本文整理匯總了PHP中Phalcon\Mvc\Application類的典型用法代碼示例。如果您正苦於以下問題:PHP Application類的具體用法?PHP Application怎麽用?PHP Application使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Application類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setUp
public function setUp()
{
$di = new DI();
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb';
$_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb');
$request = new Request();
$request->setDI($di);
$this->request = $request;
$response = new Response();
$response->setDI($di);
$this->response = $response;
$eventsManager = new Manager();
$cors = new Cors(array(array('domain' => 'bar.com')));
$di->set('request', $request, true);
$di->set('response', $response, true);
$di->set('eventsManager', $eventsManager);
$di->set('cors', $cors);
$this->di = $di;
$application = new Application();
$application->setDI($di);
$application->setEventsManager($eventsManager);
$this->application = $application;
}
示例2: modulesClosure
public function modulesClosure(IntegrationTester $I)
{
$I->wantTo('handle request and get content by using single modules strategy (closure)');
Di::reset();
$_GET['_url'] = '/login';
$di = new FactoryDefault();
$di->set('router', function () {
$router = new Router(false);
$router->add('/index', ['controller' => 'index', 'module' => 'frontend', 'namespace' => 'Phalcon\\Test\\Modules\\Frontend\\Controllers']);
$router->add('/login', ['controller' => 'login', 'module' => 'backend', 'namespace' => 'Phalcon\\Test\\Modules\\Backend\\Controllers']);
return $router;
});
$application = new Application();
$view = new View();
$application->registerModules(['frontend' => function ($di) use($view) {
/** @var \Phalcon\DiInterface $di */
$di->set('view', function () use($view) {
$view->setViewsDir(PATH_DATA . 'modules/frontend/views/');
return $view;
});
}, 'backend' => function ($di) use($view) {
/** @var \Phalcon\DiInterface $di */
$di->set('view', function () use($view) {
$view->setViewsDir(PATH_DATA . 'modules/backend/views/');
return $view;
});
}]);
$application->setDI($di);
$I->assertEquals('<html>here</html>' . PHP_EOL, $application->handle()->getContent());
}
示例3: load
protected function load($uri, $method = "GET", $params = [])
{
$_SERVER['REQUEST_METHOD'] = $method;
$_SERVER['REQUEST_URI'] = $uri;
switch ($method) {
case "GET":
$_GET = $params;
$_REQUEST = array_merge($_REQUEST, $_GET);
break;
case "POST":
$_POST = $params;
$_REQUEST = array_merge($_REQUEST, $_POST);
break;
case "PUT":
$_PUT = $params;
$_REQUEST = array_merge($_REQUEST, $_PUT);
break;
default:
$_REQUEST = $params;
break;
}
foreach ($params as $paramkey => $paramValue) {
$this->getDi()->get('dispatcher')->setParam($paramkey, $paramValue);
}
$application = new Application($this->getDI());
$_GET['_url'] = $uri;
$response = $application->handle();
return json_decode($response->getContent(), true);
}
示例4: setUp
/**
*
*/
public function setUp()
{
$di = new DI();
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb';
$_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb');
$request = new Request();
$request->setDI($di);
$this->request = $request;
$response = new Response();
$response->setDI($di);
$dispatcher = new Dispatcher();
$dispatcher->setDI($di);
$this->dispatcher = $dispatcher;
$cache = new BackendCache(new FrontendCache());
$di->set('viewCache', $cache);
$config = new Config(array('cache' => array('enable' => true)));
$di->set('config', $config);
$eventsManager = new Manager();
$di->set('request', $request, true);
$di->set('response', $response, true);
$di->set('dispatcher', $dispatcher, true);
$di->set('eventsManager', $eventsManager);
$this->di = $di;
$application = new Application();
$application->setDI($di);
$application->setEventsManager($eventsManager);
$this->application = $application;
}
示例5: testTestCase
public function testTestCase()
{
/**
* ------ NOTE
* Because i have no more time, only write one test for register motorbike
* and do not test authentication and other parts
*/
$this->autheticate();
$_SERVER["REQUEST_METHOD"] = 'POST';
$_POST["brand"] = "Honda";
$_POST["model"] = "CB1100";
$_POST["cc"] = 250;
$_POST["color"] = "black";
$_POST["weight"] = 750;
$_POST["price"] = 78000000.0;
$_POST["csrf"] = $this->handleCsrf();
$fh = fopen($this->di->get('config')->application->testsDir . "tempdata/honda-motorcycle", 'r');
$tmpfname = tempnam(sys_get_temp_dir(), "img");
$handle = fopen($tmpfname, "w");
fwrite($handle, fread($fh, 636958));
fclose($handle);
fclose($fh);
$_FILES["image"] = array("name" => "honda-motorcycles-cb1100.jpg", "type" => "image/jpeg", "tmp_name" => $tmpfname, "error" => "0", "size" => "636958");
$_SERVER["REQUEST_URI"] = "/motorbikes/create";
$_GET["_url"] = "/motorbikes/create";
$request = new Request();
$this->di->set('request', $request);
$application = new Application($this->di);
$files = $request->getUploadedFiles();
$result = $application->handle()->getContent();
$this->assertNotFalse(strpos($result, 'motorbike was created successfully'), 'Error in creating motorbike');
}
示例6: testApplicationWithNotFoundRoute
/**
* @expectedException \Phalcon\Mvc\Dispatcher\Exception
*/
public function testApplicationWithNotFoundRoute()
{
$appKernel = new TestKernel('dev');
$appKernel->boot();
$application = new Application($appKernel->getDI());
ob_end_clean();
// application don't close output buffer after exception
$application->handle('/asdasd111');
}
示例7: createMvcFrom
/**
* @param array $config
* @return MvcApplication
*/
public static function createMvcFrom(array $config) : MvcApplication
{
$di = Di::createMvcFrom($config);
$application = new MvcApplication($di);
if ($di->has('applicationEventManager')) {
$application->setEventsManager($di->getShared('applicationEventManager'));
}
$application->useImplicitView(isset($config['view']));
return $application;
}
示例8: run
/**
* Runs the application performing all initializations
*
* @param $options
*
* @return mixed
*/
public function run($options)
{
$loaders = array('session', 'config', 'loader', 'url', 'router', 'view', 'cache', 'markdown');
foreach ($loaders as $service) {
$function = 'init' . ucfirst($service);
$this->{$function}();
}
$application = new PhApplication();
$application->setDI($this->di);
return $application->handle($_SERVER['REQUEST_URI'])->getContent();
}
示例9: boot
/**
* @param Application $app
*/
public function boot(Application $app)
{
$options = $this->options;
$app->getDI()->setShared('aws', function () use($options) {
$aws = Aws::factory($options);
$aws->getEventDispatcher()->addListener('service_builder.create_client', function (Event $event) {
$clientConfig = $event['client']->getConfig();
$commandParams = $clientConfig->get(Client::COMMAND_PARAMS) ?: array();
$clientConfig->set(Client::COMMAND_PARAMS, array_merge_recursive($commandParams, array(UserAgentListener::OPTION => 'Phalcon/' . Application::VERSION)));
});
return $aws;
});
}
示例10: run
public function run($args = array())
{
parent::run($args);
// initialize our benchmarks
$this->di['util']->startBenchmark();
// create the mvc application
$application = new Application($this->di);
// run auth init
$this->di['auth']->init();
// output the content. our benchmark is finished in the base
// controller before output is sent.
echo $application->handle()->getContent();
}
示例11: run
/**
* Runs the application performing all initializations
*
* @param $options
*
* @return mixed
*/
public function run($options)
{
$loaders = array('session', 'config', 'loader', 'url', 'router', 'view', 'cache');
foreach ($loaders as $service) {
$function = 'init' . ucfirst($service);
$this->{$function}();
}
$application = new PhApplication();
$application->setDI($this->di);
if (PHP_OS == 'Linux') {
$uri = $_SERVER['REQUEST_URI'];
} else {
$uri = null;
}
return $application->handle($uri)->getContent();
}
示例12: initPhalconApplication
/**
* Initialize phalcon application
* @return PhalconApplication
*/
protected function initPhalconApplication()
{
$diFactory = $this->diManager->getDI();
$moduleHandler = $diFactory->get('moduleHandler');
// Register autoloader
(new Autoloader($diFactory))->register();
// Register services and routers
$this->diManager->initInvokableServices()->initFactoriedServices()->initRouterDi();
// Init listeners
(new Listener($diFactory))->listenApplicationEvents(new Listener\Application())->listenDispatchEvents(new Listener\Dispatch());
// Register modules
$application = new PhalconApplication($diFactory);
$application->setEventsManager($diFactory['eventsManager']);
$application->registerModules($moduleHandler->getRegisteredModules());
return $application;
}
示例13: run
/**
* Runs the application performing all initializations
*
* @param $options
*
* @return mixed
*/
public function run($options)
{
$loaders = array('config', 'session', 'loader', 'url', 'router', 'database', 'view', 'cache', 'log', 'utils', 'debug');
try {
// Handing missing controller errors
$this->di->set('dispatcher', function () {
//Create an EventsManager
$eventsManager = new EventsManager();
// Attach a listener
$eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
// Handle 404 exceptions
if ($exception instanceof DispatchException) {
$dispatcher->forward(array('controller' => 'index', 'action' => 'internalServerError'));
return false;
}
// Alternative way, controller or action doesn't exist
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array('controller' => 'index', 'action' => 'internalServerError'));
return false;
}
}
});
// Instantiate the Security plugin
$security = new Security($di);
// Listen for events produced in the dispatcher using the Security plugin
$eventsManager->attach('dispatch', $security);
$dispatcher = new \Phalcon\Mvc\Dispatcher();
// Bind the EventsManager to the dispatcher
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
}, true);
foreach ($loaders as $service) {
$function = 'init' . ucfirst($service);
$this->{$function}();
}
$application = new PhApplication();
$application->setDI($this->di);
return $application->handle()->getContent();
} catch (PhException $e) {
echo $e->getMessage();
} catch (\PDOException $e) {
echo $e->getMessage();
}
}
示例14: run
/**
* Runs the application performing all initializations
*
* @param $options
*
* @return mixed
*/
public function run($options)
{
$loaders = array('config', 'loader', 'environment', 'timezone', 'debug', 'flash', 'url', 'dispatcher', 'view', 'logger', 'database', 'session', 'cache', 'behaviors');
try {
foreach ($loaders as $service) {
$function = 'init' . ucfirst($service);
$this->{$function}($options);
}
$application = new PhApplication();
$application->setDI($this->_di);
return $application->handle()->getContent();
} catch (PhException $e) {
echo $e->getMessage();
} catch (\PDOException $e) {
echo $e->getMessage();
}
}
示例15: __construct
/**
* Application constructor.
* @param \Phalcon\DiInterface|null $dependencyInjector
* @param Config $config
*/
public function __construct(\Phalcon\DiInterface $dependencyInjector = null, Config $config)
{
parent::__construct($dependencyInjector);
$this->config = $config;
$this->_eventsManager = new Manager();
$dependencyInjector->set('config', $config);
$this->attachBootstrapEvents();
}