blue-twilight/app/Helpers/ValidationHelper.php
Andy Heathershaw e7fbdaaa66 BLUE-1: A default local storage location is created on install that cannot be deleted. Storage locations can be made inactive and no new albums can be created against them.
BLUE-3: Validation is now performed on the file path selected.

Tweaks to the storage locations form to display validation errors against the correct fields.
2016-10-27 11:36:37 +01:00

39 lines
900 B
PHP

<?php
namespace App\Helpers;
class ValidationHelper
{
public function directoryExists($attribute, $value, $parameters, $validator)
{
return file_exists($value) && is_dir($value);
}
public function isDirectoryEmpty($attribute, $value, $parameters, $validator)
{
if (!$this->directoryExists($attribute, $value, $parameters, $validator))
{
return false;
}
$iterator = new \DirectoryIterator($value);
$count = 0;
foreach ($iterator as $item)
{
if ($item->isDot())
{
continue;
}
$count++;
}
return ($count == 0);
}
public function isPathWriteable($attribute, $value, $parameters, $validator)
{
return $this->directoryExists($attribute, $value, $parameters, $validator) && is_writeable($value);
}
}