Beispiel #1
0
 public function schema()
 {
     Filter::register('can_access', function ($value, $entry, $args) {
         if (empty($value)) {
             return $value;
         }
         if ($args[0] === 'dir') {
             if (!is_dir($value) && !@mkdir($value, 0755, true)) {
                 throw new \Exception('Directory is not exists');
             }
             if (!is_readable($value)) {
                 throw new \Exception('Directory is not readable');
             }
             if (!is_writable($value)) {
                 throw new \Exception('Directory is not writable');
             }
         } else {
             @mkdir(dirname($value), 0755, true);
             if (!@touch($value)) {
                 throw new \Exception('File is not exists');
             }
             if (!is_readable($value)) {
                 throw new \Exception('File is not readable');
             }
             if (!is_writable($value)) {
                 throw new \Exception('File is not writable');
             }
         }
         return $value;
     });
     return array('name' => String::create('name')->filter('required'), 'expression' => String::create('expression')->filter('required'), 'command' => String::create('command')->filter('required'), 'working_dir' => String::create('working_dir')->filter('can_access:dir'), 'stdout' => String::create('stdout')->filter('can_access:file'), 'stderr' => String::create('stderr')->filter('can_access:file'), 'next_run' => DateTime::create('next_run'));
 }
 public function initialized($collection)
 {
     $collection->schema('$created_time', DateTime::create('$created_time'));
     $collection->schema('$updated_time', DateTime::create('$updated_time'));
 }