Пример #1
0
 /**
  * Fetch COOKIE data
  *
  * This method returns a key-value array of Cookie data sent in the HTTP request, or
  * the value of a array key if requested; if the array key does not exist, NULL is returned.
  *
  * @param  string            $key
  * @return array|string|null
  */
 public function cookies($key = null)
 {
     if ($key) {
         return $this->cookies->get($key);
     }
     return $this->cookies;
 }
Пример #2
0
 /**
  * Set cookie
  *
  * The second argument may be a single scalar value, in which case
  * it will be merged with the default settings and considered the `value`
  * of the merged result.
  *
  * The second argument may also be an array containing any or all of
  * the keys shown in the default settings above. This array will be
  * merged with the defaults shown above.
  *
  * @param string $key   Cookie name
  * @param mixed  $value Cookie settings
  */
 public function set($key, $value)
 {
     if (is_array($value)) {
         $cookieSettings = array_replace($this->defaults, $value);
     } else {
         $cookieSettings = array_replace($this->defaults, array('value' => $value));
     }
     parent::set($key, $cookieSettings);
 }
Пример #3
0
 /**
  * Render a template file
  *
  * NOTE: This method should be overridden by custom view subclasses
  *
  * @param  string $template     The template pathname, relative to the template base directory
  * @param  array  $data         Any additonal data to be passed to the template.
  * @return string               The rendered template
  * @throws \RuntimeException    If resolved template pathname is not a valid file
  */
 protected function render($template, $data = null)
 {
     $templatePathname = $this->getTemplatePathname($template);
     if (!is_file($templatePathname)) {
         throw new \RuntimeException("View cannot render `{$template}` because the template does not exist");
     }
     $data = array_merge($this->data->all(), (array) $data);
     extract($data);
     ob_start();
     require $templatePathname;
     return ob_get_clean();
 }
Пример #4
0
 /**
  * Constructor
  * @param  array $userSettings Associative array of application settings
  */
 public function __construct(array $userSettings = array())
 {
     // Setup IoC container
     $this->container = new \Yee\Helper\Set();
     $this->container['settings'] = array_merge(static::getDefaultSettings(), $userSettings);
     // Default environment
     $this->container->singleton('environment', function ($c) {
         return \Yee\Environment::getInstance();
     });
     // Default request
     $this->container->singleton('request', function ($c) {
         return new \Yee\Http\Request($c['environment']);
     });
     // Default response
     $this->container->singleton('response', function ($c) {
         return new \Yee\Http\Response();
     });
     // Default router
     $this->container->singleton('router', function ($c) {
         return new \Yee\Router();
     });
     // Default view
     $this->container->singleton('view', function ($c) {
         $viewClass = $c['settings']['view'];
         $templatesPath = $c['settings']['templates.path'];
         $view = $viewClass instanceof \Yee\View ? $viewClass : new $viewClass();
         $view->setTemplatesDirectory($templatesPath);
         return $view;
     });
     // Default log writer
     $this->container->singleton('logWriter', function ($c) {
         $logWriter = $c['settings']['log.writer'];
         return is_object($logWriter) ? $logWriter : new \Yee\LogWriter($c['environment']['yee.errors']);
     });
     // Default log
     $this->container->singleton('log', function ($c) {
         $log = new \Yee\Log($c['logWriter']);
         $log->setEnabled($c['settings']['log.enabled']);
         $log->setLevel($c['settings']['log.level']);
         $env = $c['environment'];
         $env['yee.log'] = $log;
         return $log;
     });
     // Default mode
     $this->container['mode'] = function ($c) {
         $mode = $c['settings']['mode'];
         if (isset($_ENV['YEE_MODE'])) {
             $mode = $_ENV['YEE_MODE'];
         } else {
             $envMode = getenv('YEE_MODE');
             if ($envMode !== false) {
                 $mode = $envMode;
             }
         }
         return $mode;
     };
     // Define default middleware stack
     $this->middleware = array($this);
     $this->add(new \Yee\Middleware\Flash());
     $this->add(new \Yee\Middleware\MethodOverride());
     // Make default if first instance
     if (is_null(static::getInstance())) {
         $this->setName('default');
     }
 }