e7fbdaaa66
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.
39 lines
900 B
PHP
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);
|
|
}
|
|
} |