예제 #1
0
파일: DemoModule.php 프로젝트: raphhh/puppy
 /**
  * @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];
     });
 }
예제 #2
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;
 }
예제 #3
0
파일: index.php 프로젝트: raphhh/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! :)
예제 #4
0
 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();
 }
예제 #5
0
 /**
  * init the module.
  *
  * @param Application $application
  */
 public function init(Application $application)
 {
     $application->addService('template', new TemplateService([new TemplateExtension($application->getServices())]));
 }
예제 #6
0
 /**
  * @param Application $application
  * @return IModulesLoader
  */
 public function createFromApplication(Application $application)
 {
     return $this->create($this->retrieveDirectories($application->getService('config')), $this->retrieveOptions($application->getService('config')));
 }
예제 #7
0
 /**
  * init the module.
  *
  * @param Application $application
  */
 public function init(Application $application)
 {
     $application->addService('staticController', new StaticControllerService());
     $application->any(':all', $application->getService('staticController'));
 }
예제 #8
0
 /**
  * init the module.
  *
  * @param Application $application
  */
 public function init(Application $application)
 {
     $application->addService('session', new SessionService());
 }