Esempio n. 1
0
 /**
  * Cache file (do not regenerate on every call)
  *
  * @return $this
  */
 public function cache()
 {
     $this->prepare();
     if (!$this->target->exists() || !$this->lazy && $this->manager->isDebug()) {
         $this->write();
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * Get last logs
  *
  * @param int $count Line count numbered from end
  *
  * @return null|string
  */
 public function tail($count)
 {
     if (!$this->file->exists()) {
         return null;
     }
     $lines = $this->file->tail($count);
     $data = implode($lines, PHP_EOL);
     return $data;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function write(Config $config, $target)
 {
     $file = new File($target);
     if ($file->exists()) {
         throw new \LogicException(sprintf("Config target file already exists '%s'", $target));
     }
     $data = sprintf("<?php\n\n// \nreturn %s;\n", var_export($config->getData(), true));
     $file->write($data);
     return $this;
 }
Esempio n. 4
0
 /**
  * @param string $source
  *
  * @throws \LogicException
  * @throws \ErrorException
  *
  * @return Config
  */
 public function read($source)
 {
     $file = new File($source);
     if (!$file->exists()) {
         throw new \LogicException(sprintf("Config source file '%s' does not exist.", $source));
     }
     // Possible syntax errors, do not handle them / expensive!
     $path = $file->getPath();
     $data = (include $path);
     if (!is_array($data)) {
         throw new \ErrorException("Config source file should return array: '%s'", $source);
     }
     $config = new Config();
     $config->setData($data);
     return $config;
 }