public function testParse() { $document = new \DOMDocument(); $document->load(__DIR__ . '/_files/argument_parser.xml'); $parser = new ArgumentParser(); $actual = $parser->parse($document->getElementsByTagName('argument')->item(0)); $expected = array('item' => array('one' => array('name' => 'one', 'value' => 'value1'), 'nested' => array('name' => 'nested', 'item' => array('two' => array('name' => 'two', 'value' => 'value2'), 'three' => array('name' => 'three', 'value' => 'value3'))))); $this->assertSame($expected, $actual); }
/** * Parses out all the command line to find the requested controller plus * any arguments which are available to both Synergy framework * classes and to the Controller class * * @param string $arguments line of args to be parsed (if null then taken from command line) * * @return ArgumentParser */ public static function parseArguments($arguments = null) { $obj = new ArgumentParser(); if (is_null($arguments) && isset($_SERVER['argv'])) { $aArgs = $_SERVER['argv']; } elseif (is_array($arguments)) { $aArgs = $arguments; } else { return $obj; } $request = null; $requestArgs = array(); $phase = 1; $script_filename = strtolower($_SERVER['SCRIPT_FILENAME']); foreach ($aArgs as $val) { switch ($phase) { case 1: // look for our app/console script first if (strtolower($val) == $script_filename) { $phase = 2; continue; } break; case 2: // look for any args for Synergy if (substr($val, 0, 1) == '-') { $requestArgs[] = $val; } else { $phase = 3; $obj->setRequest($val); } break; case 3: // look for any args for the request $requestArgs[] = $val; } } if (is_array($requestArgs)) { $obj->setElements($requestArgs); } return $obj; }
/** * Construct this command line library * @param null|array $arguments */ public function __construct(array $arguments = null) { $this->isCli = php_sapi_name() == self::SAPI_CLI; if (!$this->isCli) { $this->arguments = array(); return; } if ($arguments === null) { $arguments = $_SERVER['argv']; } $this->arguments = ArgumentParser::parseArguments($arguments); }
/** * Construct this command line library * @param null|array $arguments */ public function __construct(array $arguments = null) { $this->isCli = php_sapi_name() == self::SAPI_CLI; if (!$this->isCli) { $this->arguments = array(); return; } if ($arguments === null) { $arguments = $_SERVER['argv']; array_shift($arguments); // remove first element, always the script name } $this->arguments = ArgumentParser::parseArguments($arguments); }
/** * Parse given argument input into a proper format. * * @param mixed $input * * @return array */ public function parseArguments($input) { $this->argumentParser->run($input); return $this->argumentParser->all(); }
/** * _preDispatch() - Tasks handed after initialization but before dispatching * */ protected function _preDispatch() { $response = $this->_registry->getResponse(); $response->addContentDecorator(new ResponseDecorator\AlignCenter()); $response->addContentDecorator(new ResponseDecorator\Indention()); $response->addContentDecorator(new ResponseDecorator\Blockize()); if (function_exists('posix_isatty')) { $response->addContentDecorator(new ResponseDecorator\Colorizer()); } $response->addContentDecorator(new \Zend\Tool\Framework\Client\Response\ContentDecorator\Separator())->setDefaultDecoratorOptions(array('separator' => true)); $optParser = new ArgumentParser(); $optParser->setArguments($_SERVER['argv'])->setRegistry($this->_registry)->parse(); return; }
/** * Created by PhpStorm. * User: anjan * Date: 10/19/15 * Time: 2:19 PM */ $startTime = time(); require_once 'config.php'; ini_set('display_errors', TRUE); error_reporting(E_ALL); Console::emptyLines(1); # ======================================================== # Parse and prepare CLI arguments # ======================================================== $objArgumentsList = ArgumentsList::getInstance(ArgumentParser::prepareCliArguments()); # ======================================================== # Prepare managa info instance ... # ======================================================== $mangaInfo = MangaInfo::getInstance(array('source' => $objArgumentsList->getSource(), 'name' => $objArgumentsList->getMangaName(), 'slug' => $objArgumentsList->getMangaSlug(), 'url' => MangaSourceList::getInstance()->generateMangaChaptersUrl($objArgumentsList->getSource(), array('slug' => $objArgumentsList->getMangaSlug())), 'output_dir' => $objArgumentsList->getOutputDir())); Console::seperatorLine(); consoleLineInfo('Strating at: ' . date('M d, Y h:i a', $startTime)); Console::seperatorLine(); consoleLineInfo('Fetching chapters for: ' . $mangaInfo->getName()); consoleLineInfo('Manga Url: ' . $mangaInfo->getUrl()); Console::seperatorLine(); # ======================================================== # Do we have chapter titles list already? # ======================================================== $objChapterTitles = ChapterTitles::getInstance(array('mangaInfo' => $mangaInfo)); # ========================================================
public function testHasAction() { $parser = new ArgumentParser(array('-d', 'fail-lover=param')); $this->assertTrue($parser->hasAction('param')); $this->assertFalse($parser->hasAction('param-not-found')); }