<?php error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT); ini_set('display_errors', 1); require dirname(__FILE__) . '/../app/bootstrap.php'; define('VERSION', '1.0.0'); $loader = new \Phalcon\Loader(); $loader->registerDirs(array(FA_INCLUDE_MODULES . '/cli/tasks')); $loader->register(); // Create a console application $console = new \Phalcon\CLI\Console(); $console->setDI($di); // Process the console arguments $arguments = array(); foreach ($argv as $k => $arg) { if ($k == 1) { $task_parts = explode(':', $arg); $arguments['task'] = $task_parts[0]; $arguments['action'] = isset($task_parts[1]) ? $task_parts[1] : 'index'; } elseif ($k > 1) { $arguments['params'][] = $arg; } } // define global constants for the current task and action define('CURRENT_TASK', $arguments['task']); define('CURRENT_ACTION', $arguments['action']); try { // handle incoming arguments $console->handle($arguments); } catch (\Phalcon\Exception $e) { echo $e->getMessage();
public function testArgumentOptions() { $di = new Phalcon\DI\FactoryDefault\CLI(); $di->setShared('router', function () { $router = new \Phalcon\Cli\Router(true); return $router; }); $console = new \Phalcon\CLI\Console(); $console->setDI($di); $dispatcher = $console->getDI()->getShared('dispatcher'); $console->setArgument(array('php', '-opt1', '--option2', '--option3=hoge', 'main', 'hello', 'World', '######'))->handle(); $this->assertEquals($dispatcher->getTaskName(), 'main'); $this->assertEquals($dispatcher->getActionName(), 'hello'); $this->assertEquals($dispatcher->getParams(), array('World', '######')); $this->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); $this->assertEquals($dispatcher->getOptions(), array('opt1' => true, 'option2' => true, 'option3' => 'hoge')); $console->setArgument(array('php', 'main', '-opt1', 'hello', '--option2', 'World', '--option3=hoge', '######'))->handle(); $this->assertEquals($dispatcher->getTaskName(), 'main'); $this->assertEquals($dispatcher->getActionName(), 'hello'); $this->assertEquals($dispatcher->getParams(), array('World', '######')); $this->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); $this->assertEquals($dispatcher->getOptions(), array('opt1' => true, 'option2' => true, 'option3' => 'hoge')); }
public function testIssue787() { $di = new \Phalcon\DI\FactoryDefault\CLI(); $di->setShared('dispatcher', function () use($di) { $dispatcher = new Phalcon\CLI\Dispatcher(); $dispatcher->setDI($di); return $dispatcher; }); $console = new \Phalcon\CLI\Console(); $console->setDI($di); $console->handle(array('task' => 'issue787', 'action' => 'main')); $this->assertTrue(class_exists('Issue787Task')); $actual = Issue787Task::$output; $expected = "beforeExecuteRoute\ninitialize\n"; $this->assertEquals($actual, $expected); }
$view = new \Phalcon\Mvc\View(); $view->setViewsDir(__DIR__ . '/../app/views/'); $view->registerEngines(array(".volt" => function ($view, $di) { $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di); $volt->setOptions(['compileAlways' => isset($_SERVER["APP_ENV"]) && $_SERVER["APP_ENV"] == 'dev', 'compiledPath' => function ($templatePath) { $templatePath = str_replace(__DIR__ . '/../app/views', __DIR__ . '/../app/views/cache', $templatePath); $dirName = dirname($templatePath); if (!is_dir($dirName)) { mkdir($dirName, 0755, true); } return $templatePath; }]); return $volt; })); return $view; }); if (PHP_SAPI != 'cli') { // URL Creation $url = str_replace('?' . $_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']); //Handle the request $application = new \Phalcon\Mvc\Application(); $application->setDI($di); echo $application->handle($url)->getContent(); } else { $cli = new Phalcon\CLI\Console(); $cli->setDI($di); $cli->handle(array('task' => isset($argv[1]) ? $argv[1] : null, 'action' => isset($argv[2]) ? $argv[2] : 'index', 'params' => count($argv) > 3 ? array_slice($argv, 3) : [])); } } catch (\Phalcon\Exception $e) { echo "PhalconException: ", $e->getMessage(); }