/** * Gets a template file content * * @param string $template_path * * @return mixed|string * * @throws \MarkdownExtended\Exception\FileSystemException if the template can not be found or is not readable */ public function getTemplate($template_path) { if (true === $template_path) { $template_path = Kernel::getConfig('output_format_options.' . Kernel::getConfig('output_format') . '.default_template'); if (empty($template_path)) { return Kernel::getConfig('template_options.inline_template'); } } if (!file_exists($template_path)) { $local_path = Kernel::getResourcePath($template_path, Kernel::RESOURCE_TEMPLATE); if (empty($local_path) || !file_exists($local_path)) { throw new FileSystemException(sprintf('Template "%s" not found', $template_path)); } $template_path = $local_path; } if (!$this->cache->isCached($template_path)) { if (!is_readable($template_path)) { throw new FileSystemException(sprintf('Template "%s" is not readable', $template_path)); } $tpl_content = Helper::readFile($template_path); $this->cache->setCache($template_path, $tpl_content); } else { $tpl_content = $this->cache->getCache($template_path); } return $tpl_content; }
private function __addBin($phar, $binary = 'bin/markdown-extended') { $content = Helper::readFile($this->root_dir . '/bin/markdown-extended'); $content = preg_replace('{^#!/usr/bin/env php\\s*}', '', $content); $this->_logs[] = sprintf('Adding binary file "%s" from source (length %d)', $binary, strlen($content)); $phar->addFromString($binary, $content); return $this; }
/** * Loads a configuration file * * @param string $path * * @return array|mixed * * @throws \MarkdownExtended\Exception\FileSystemException if the file can not be found or is not readable * @throws \MarkdownExtended\Exception\InvalidArgumentException if the file is of an unknown type */ protected function loadConfigFile($path) { if (!file_exists($path)) { throw new FileSystemException(sprintf('Configuration file "%s" not found', $path)); } if (!is_readable($path)) { throw new FileSystemException(sprintf('Configuration file "%s" is not readable', $path)); } $ext = pathinfo($path, PATHINFO_EXTENSION); switch (strtolower($ext)) { case 'ini': $options = parse_ini_file($path, true); break; case 'json': $options = json_decode(Helper::readFile($path), true); break; case 'php': $options = (include $path); break; default: throw new InvalidArgumentException(sprintf('Unknown configuration file type "%s"', $ext)); } return $options; }
/** * Dumps the composer.json file */ protected function runTaskManifest() { if (file_exists($manifest = MDE_BASE_PATH . self::MANIFEST_FILE)) { $content = json_decode(Helper::readFile($manifest), true); foreach (array('extra', 'autoload', 'autoload-dev', 'config', 'scripts', 'archive') as $entry) { if (isset($content[$entry])) { unset($content[$entry]); } } if (isset($content['keywords']) && is_array($content['keywords'])) { $content['keywords'] = implode(',', $content['keywords']); } if (isset($content['authors'])) { foreach ($content['authors'] as $i => $author) { if (is_array($author)) { $content['authors'][$i] = implode(', ', $author); } } } $this->_writeTask($content, 'Manifest'); } else { $this->stream->writeln('Manifest file not found', Stream::IO_STDERR); } }