/** * Helper to get instance of AutoloadBuilder with cli options applied * * @throws \RuntimeException * @return \TheSeer\Autoload\AutoloadBuilder|\TheSeer\Autoload\StaticBuilder */ public function getBuilder(ClassFinder $finder) { $isStatic = $this->config->isStaticMode(); $isPhar = $this->config->isPharMode(); $isCompat = $this->config->isCompatMode(); $noLower = !$this->config->isLowercaseMode(); $isOnce = $this->config->isOnceMode(); $tplType = $noLower ? 'cs' : 'ci'; if ($isStatic === TRUE) { $builder = new StaticBuilder($finder->getMerged()); $builder->setDependencies($finder->getDependencies()); $builder->setPharMode($isPhar); $builder->setRequireOnce($isOnce); } else { $builder = new AutoloadBuilder($finder->getMerged()); } $builder->setCompat($isCompat); $basedir = $this->config->getBaseDirectory(); if (!$basedir || !is_dir($basedir)) { throw new \RuntimeException("Given basedir '{$basedir}' does not exist or is not a directory"); } $builder->setBaseDir($basedir); $template = $this->config->getTemplate(); if ($template !== NULL) { if (!file_exists($template)) { $alternative = __DIR__ . '/templates/' . $tplType . '/' . $template; if (file_exists($alternative)) { $template = $alternative; } } $builder->setTemplateFile($template); } else { // determine auto template to use $tplFile = 'default.php.tpl'; if ($isCompat) { $tplFile = 'php52.php.tpl'; } if ($isPhar) { if ($isStatic) { $tplFile = 'staticphar.php.tpl'; } else { $tplFile = 'phar.php.tpl'; } } elseif ($isStatic) { $tplFile = 'static.php.tpl'; $tplType = '.'; } $builder->setTemplateFile(__DIR__ . '/templates/' . $tplType . '/' . $tplFile); } $format = $this->config->getDateFormat(); if ($format) { $builder->setDateTimeFormat($format); } $builder->setIndent($this->config->getIndent()); $builder->setLineBreak($this->config->getLinebreak()); foreach ($this->config->getVariables() as $name => $value) { $builder->setVariable($name, $value); } return $builder; }
/** * Helper to get instance of AutoloadBuilder with cli options applied * * @param Array $found Iterator or Array with files to process * @param \ezcConsoleInput $input CLI Options pased to app */ protected function getBuilder(array $found, \ezcConsoleInput $input) { $ab = new AutoloadBuilder($found); $basedir = $input->getOption('basedir'); if ($basedir->value) { $ab->setBaseDir($basedir->value); } else { $args = $input->getArguments(); $ab->setBaseDir(realpath($args[0])); } $phar = $input->getOption('phar'); if ($phar->value) { $ab->setTemplateFile(__DIR__ . '/templates/phar.php.tpl'); } $template = $input->getOption('template'); if ($template->value) { if (!file_exists($template->value)) { $alternative = __DIR__ . '/templates/' . $template->value; if (file_exists($alternative)) { $template->value = $alternative; } } $ab->setTemplateFile($template->value); } $format = $input->getOption('format'); if ($format->value) { $ab->setDateTimeFormat($format->value); } $indent = $input->getOption('indent'); if ($indent->value) { $ab->setIndent($indent->value); } $linebreak = $input->getOption('linebreak'); if ($linebreak->value !== false) { $lbr = array('LF' => "\n", 'CR' => "\r", 'CRLF' => "\r\n"); if (in_array($linebreak->value, $lbr)) { $ab->setLineBreak($lbr[$linebreak->value]); } else { $ab->setLineBreak($linebreak->value); } } else { $ab->setLineBreak(PHP_EOL); } return $ab; }