/** * 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; }
/** * 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; }
/** * {@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; }
/** * @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; }