Example #1
0
 public function testWrite()
 {
     $this->assertFalse(is_file('foobar.php'));
     File::write("foobar.php", "foobar");
     $this->assertTrue(is_file('foobar.php'));
     unlink('foobar.php');
 }
Example #2
0
 public function save()
 {
     if ($this->isDry) {
         $this->times = array_filter($this->times);
         $code = Build\Templates::get('Main')->render(array('self' => $this, 'return' => $this->times), true);
         File::write($this->tmp, $code);
         $this->isDry = true;
     }
 }
Example #3
0
File: One.php Project: crodas/cli
 /**
  *  @CliPlugin One
  *  @CliPlugin Crontab
  */
 public function main(zCallable $function, $input, $output)
 {
     $args = $function->getOne('one,crontab')->getArgs();
     $lock = File::generateFilePath('lock', $function->getName());
     if (!empty($args)) {
         $lock = $args[0];
     }
     if (filesize($lock) > 0) {
         $pid = trim(file_get_contents($lock));
         if (posix_getsid($pid) !== false) {
             throw new RuntimeException("Process {$function->getName()}() is still running");
         }
     }
     File::write($lock, getmypid());
 }
Example #4
0
 public function __construct(array $config, Build $builder)
 {
     $collections = new Generate\Collections($config['files'], $this);
     self::$cdir = $config['loader'];
     $namespace = "ActiveMongo2\\Namspace" . uniqid(true);
     $rnd = uniqid();
     $valns = $collections->getValidatorNS();
     $validator = $collections->getValidator();
     class_exists("crodas\\FileUtil\\File");
     // preload class
     $args = compact('docs', 'namespace', 'mapper', 'indexes', 'self', 'collections', 'valns', 'rnd', 'validator');
     $code = Template\Templates::get('documents')->render($args, true);
     if (strlen($code) >= 1024 * 1024 || !class_exists('crodas\\SimpleView\\FixCode')) {
         File::write($config['loader'], $code);
     } else {
         File::write($config['loader'], FixCode::fix($code));
     }
     $this->writeFileWatch($builder, $collections);
 }
Example #5
0
 public function generate()
 {
     $output = $this->getOutput();
     $cache = new Watch($output . '.cache');
     $dirs = array_unique($this->dirs);
     $files = array_unique($this->files);
     $files[] = $output;
     $dirs[] = __DIR__ . '/Filters';
     $cache->watchFiles($files);
     $cache->watchDirs($dirs);
     if (!$cache->hasChanged()) {
         return;
     }
     $annotations = new \Notoj\Filesystem(array_unique(array_merge($dirs, $files)));
     $compiler = new Compiler($this, $annotations);
     File::write($output, $compiler->getOutput());
     $cache->watchFiles($files)->watchDirs($dirs);
     $cache->watch();
     return $compiler->getOutput();
 }
Example #6
0
 protected function renderSingle($output)
 {
     $code = Templates::get('autoloader')->render($this->GetTemplateArgs($output), true);
     File::write($output, $code);
 }
Example #7
0
 public function writeTo($file)
 {
     return File::write($file, $this->GetCode());
 }
Example #8
0
 public function addFile($name, $path = NULL)
 {
     if ($path == NULL) {
         $path = $name;
     }
     $name = trim($name, "\\/");
     $realPath = $this->tmp . '/' . $name;
     $this->files[$name] = true;
     if (file_exists($path)) {
         File::write($realPath, file_get_contents($path));
     } else {
         File::write($realPath, $path);
     }
 }