/** * @param Application $application */ private function exampleOfRedirection(Application $application) { $application->get('redirect-from', function () { /** * @var AppController $this */ $this->flash()->set('funny', 'redirection done with fun! :)'); return $this->redirect('redirect-to'); }); $application->get('redirect-to', function () { /** * @var AppController $this */ return $funny = $this->flash()->get('funny', ['no redirection'])[0]; }); }
/** * @param $requestUri * @param string $method * @param array $post * @return Application */ public function run($requestUri, $method = 'GET', array $post = []) { $_SERVER['REQUEST_URI'] = $requestUri; $_SERVER['REQUEST_METHOD'] = $method; $_POST = $post; if ($this->getCwd()) { $cwd = getcwd(); chdir($this->getCwd()); } $puppy = new Application(new Config($this->getEnv()), Request::createFromGlobals()); $puppy->initModules((new ModuleFactory())->createFromApplication($puppy)); $puppy->run(); unset($_SERVER['REQUEST_URI']); unset($_SERVER['REQUEST_METHOD']); $_POST = []; if (isset($cwd)) { chdir($cwd); } return $puppy; }
<?php use Puppy\Application; use Puppy\Config\Config; use Puppy\Module\ModuleFactory; use Symfony\Component\HttpFoundation\Request; require_once '../vendor/autoload.php'; /** * Puppy runs for you with happiness! * * @author Raphaël Lefebvre <*****@*****.**> * @doc https://github.com/Raphhh/puppy */ chdir(dirname(__DIR__)); $puppy = new Application(new Config(getenv('APP_ENV')), Request::createFromGlobals()); $puppy->initModules((new ModuleFactory())->createFromApplication($puppy)); $puppy->run(); //good dog! :)
public function testAfter() { $masterRequest = new Request(); $masterRequest->server->set('REQUEST_URI', 'uri1'); $application = new Application(new \ArrayObject(), $masterRequest); $application->get(':all', function (Request $request) { return $request->getRequestUri(); }); $application->after(function (Response $response) { $response->setContent('uri2'); }); $this->expectOutputString('uri2'); $application->run(); }
/** * init the module. * * @param Application $application */ public function init(Application $application) { $application->addService('template', new TemplateService([new TemplateExtension($application->getServices())])); }
/** * @param Application $application * @return IModulesLoader */ public function createFromApplication(Application $application) { return $this->create($this->retrieveDirectories($application->getService('config')), $this->retrieveOptions($application->getService('config'))); }
/** * init the module. * * @param Application $application */ public function init(Application $application) { $application->addService('staticController', new StaticControllerService()); $application->any(':all', $application->getService('staticController')); }
/** * init the module. * * @param Application $application */ public function init(Application $application) { $application->addService('session', new SessionService()); }