Example #1
0
 /**
  * New App instance
  *
  * @param array $values Array of config settings and objects to pass into Pimple container
  */
 public function __construct(array $values = array())
 {
     $this->registerParamType('int', function ($value) {
         return filter_var($value, FILTER_VALIDATE_INT);
     });
     $this->registerParamType('float', function ($value) {
         return filter_var($value, FILTER_VALIDATE_FLOAT);
     });
     // True = "1", "true", "on", "yes"
     // False = "0", "false", "off", "no"
     $this->registerParamType('boolean', function ($value) {
         $filtered = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
         return !empty($filtered) && $filtered !== null;
     });
     $this->registerParamType('slug', function ($value) {
         return preg_match("/[a-zA-Z0-9-_]/", $value) > 0;
     });
     $this->registerParamType('email', function ($value) {
         return filter_var($value, FILTER_VALIDATE_EMAIL);
     });
     $this->registerResponseHandler(function ($response) {
         return is_array($response->content());
     }, function ($response) {
         $response->contentType('application/json');
         $response->content(json_encode($response->content()));
     }, 'array_json');
     // Pimple constructor
     parent::__construct($values);
     // Template configuration settings if given
     if (isset($this['template.cfg'])) {
         $this['template'] = $this['template.cfg'];
     }
     if (isset($this['template'])) {
         View\Template::config($this['template']);
     }
     // Get callback stacks ready
     self::$_pathLevel = 0;
     $this->resetCallbacks();
 }
Example #2
0
 public function testEventBeforeResponseHandler()
 {
     Template::config(array('path_layouts' => $this->templateDir . 'layouts/'));
     $app = new Bullet\App();
     $app->path('variableSet', function ($request) use($app) {
         return $app->template('variableSet', array('variable' => 'one'))->layout('div');
     });
     $app->on('beforeResponseHandler', function (\Bullet\Request $request, \Bullet\Response $response, $rawResponse) use($app) {
         $rawResponse->set('variable', 'two')->layout(false);
     });
     $res = $app->run('GET', '/variableSet/');
     $this->assertEquals('two', $res->content());
 }
Example #3
0
 public function tearDown()
 {
     // Restore config to original state
     Template::config($this->oldConfig);
 }