public function testRouteFullWithParams() { $this->app->get('/user/:id', function () { })->name('user'); $url = Url::route('user', array('id' => '1'), null, true); $this->assertEquals('http://apple.com/test/user/1', $url); }
public function setUp() { $this->app = Pagon::create(); $_SERVER = array('HTTP_HOST' => 'localhost', 'HTTP_CONNECTION' => 'keep-alive', 'HTTP_CACHE_CONTROL' => 'max-age=0', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36', 'HTTP_ACCEPT_ENCODING' => 'gzip,deflate,sdch', 'HTTP_ACCEPT_LANGUAGE' => 'zh-CN,zh;q=0.8', 'PATH' => '/usr/bin:/bin:/usr/sbin:/sbin', 'SERVER_SIGNATURE' => '', 'SERVER_SOFTWARE' => 'Apache/2.2.24 (Unix) DAV/2 PHP/5.3.25 mod_ssl/2.2.24 OpenSSL/0.9.8y', 'SERVER_NAME' => 'localhost', 'SERVER_ADDR' => '::1', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '::1', 'DOCUMENT_ROOT' => '/Users/hfcorriez/Code', 'SERVER_ADMIN' => '*****@*****.**', 'SCRIPT_FILENAME' => '/Users/hfcorriez/Code/index.php', 'REMOTE_PORT' => '52872', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => '', 'REQUEST_URI' => '/index.php', 'SCRIPT_NAME' => '/index.php', 'PHP_SELF' => '/index.php', 'REQUEST_TIME' => 1375528769); $this->app->input = new Input(array('app' => $this->app)); ob_start(); $this->app->run(); ob_end_clean(); }
/** * Dispense logger with config * * @param string $key Default key is "log" * @return Logger */ public static function with($key = 'log') { if (empty(self::$instances[$key])) { self::$instances[$key] = new self(App::self()->get($key)); } return self::$instances[$key]; }
public static function register(App $app) { $app->on('comment', function (Comment $comment) { CommentNotify::perform($comment); }); }
/** * Compile the template * * @param string $template * @param array $data * @param array $options * @return View */ public function compile($template, array $data = null, array $options = array()) { return $this->app->compile($template, $data, $options); }
/** * Compile template * * @param string $path * @param array $data * @param array $options * @return \Pagon\View */ function compile($path, array $data = null, array $options = array()) { return App::self()->output->compile($path, $data, $options); }
/** * Stop * * @throws Stop */ public function stop() { $this->app->stop(); }
/** * Get current encoding * * @return mixed */ protected static function charset() { return static::$charset ?: (static::$charset = App::self()->get('charset')); }
<?php /** * * Bootstrap file for universal load. * * This file will be load by cli and web entry, you can define or config the application as global use. * */ use Pagon\App; define('APP_DIR', __DIR__); require __DIR__ . '/vendor/autoload.php'; $app = new App(__DIR__ . '/config/default.php'); // Load env from file if (is_file(__DIR__ . '/config/env')) { $app->mode(trim(file_get_contents(__DIR__ . '/config/env'))); } $mode = $app->mode(); if (is_file($conf_file = __DIR__ . '/config/' . $mode . '.php')) { $app->append(include $conf_file); } // Boost application $app->add('Booster'); // Functions $app->assisting(); // Add pretty exception if ($app->debug) { $app->add('PrettyException'); } else { error_reporting(E_ALL & ~E_NOTICE); }
/** * Init * * @param array $injectors */ public function __construct(array $injectors = array()) { // Auto global if (!isset($injectors['global'])) { $injectors['global'] = PHP_SAPI === 'CLI' ? false : true; } parent::__construct($injectors + $this->injectors); // Use default store is not set if (self::$defaultStore && $this->injectors['store'] === null) { $this->injectors['store'] = self::$defaultStore; } // If store is config, create store if ($this->injectors['store'] && !$this->injectors['store'] instanceof Store) { $this->injectors['store'] = Store::create($this->injectors['store']); // Set default store if not exists if (!self::$defaultStore) { self::$defaultStore = $this->injectors['store']; } } // If not app inject, use default if (!$this->injectors['app']) { $this->injectors['app'] = App::self(); } }
<?php use Pagon\App; define('APP_DIR', __DIR__); define('BASE_DIR', dirname(__DIR__)); require dirname(__DIR__) . '/vendor/autoload.php'; $app = new App(array('views' => APP_DIR . '/views', 'autoload' => APP_DIR . '/src') + (include BASE_DIR . '/config/default.php')); /** * Config */ // Load env from file if (is_file(BASE_DIR . '/config/env')) { $app->mode(trim(file_get_contents(BASE_DIR . '/config/env'))); } // Load config by enviroment if (!is_file($conf_file = BASE_DIR . '/config/' . $app->mode() . '.php')) { echo "No config found! Plz add config/" . $app->mode() . ".php file"; exit; } else { $app->append(include $conf_file); } $app->add('Booster'); $app->assisting(); // Add pretty exception if ($app->debug) { $app->add('PrettyException'); } else { error_reporting(E_ALL & ~E_NOTICE); } $app->protect('loadOrm', function () { global $app;
public function isSuperAdmin() { return ($admins = App::self()->get('admins')) ? in_array($this->name, $admins) : false; }