예제 #1
0
 /**
  * Magic method called when creating a new instance of the object from the
  * autoloader.
  *
  * @return   void             No value is returned
  */
 public static function __initialize()
 {
     if (!\function_exists('mcrypt_encrypt')) {
         throw new \Exception('The mcrypt php extension is required to use the Mcrypt driver');
     }
     static::$cipher = Config::get('crypt.mcrypt.cipher');
     static::$mode = Config::get('crypt.mcrypt.mode');
 }
예제 #2
0
파일: file.php 프로젝트: nerdsrescueme/Core
 /**
  * Write data to a datastore key
  *
  * @param    string           The datastore key
  * @param    mixed            The data to be written to the key
  * @param    integer          The time, in minutes, to store the data. Defaults to the time value in your datastore configuration file
  * @return   boolean          Returns true if the datastore was successfully written, otherwise false
  */
 public function write($key, $value, $minutes = false)
 {
     !is_numeric($minutes) and $minutes = Config::get('datastore.time');
     $value = time() + $minutes * 60 . serialize($value);
     if (!F::exists(self::$path . $key)) {
         return F::create(self::$path . $key, $value);
     } else {
         return (bool) F::put(self::$path . $key, $value);
     }
 }
예제 #3
0
파일: site.php 프로젝트: nerdsrescueme/Core
 public function __construct($resource)
 {
     if (($url = Config::get('application.url')) === null) {
         throw new \InvalidArgumentException('You must set the application.url configuration variable in application.php');
     }
     parent::url($url);
     $this->prefix = trim($this->path, '/');
     $this->path = null;
     $this->uri($resource);
 }
예제 #4
0
 public function __construct($resource = null)
 {
     if (($url = Config::get('application.url')) === null) {
         throw new \InvalidArgumentException('You must set the application.url configuration variable in application.php');
     }
     $this->url($url);
     $this->prefix = trim($this->path, '/');
     $this->path = null;
     $this->uri(str_replace($this->prefix, '', $_SERVER['REQUEST_URI']));
 }
예제 #5
0
 /**
  * Create a new response rendered with the error code, and stops page
  * execution.
  *
  * ## Usage
  *
  *     throw new \Http\Exception(500);
  *
  * @param    integer          The HTTP error code, defaults to 404
  * @param    Response         The current response object, if one is not defined, one will be generated
  * @return   void             No value is returned
  */
 public function __construct($code = 404, Response $response = null)
 {
     if ($code < 400) {
         throw new \Exception('An invalid call to Nerd\\Http\\Exception was made. This exception is meant to handle errors for Http, and was called with a ' . $code);
     }
     if ($response === null) {
         $response = new Response();
     }
     $response->setStatus($code)->setBody(call_user_func(Config::get('error.http_error_handler', null, false), $code))->send();
     exit;
 }
예제 #6
0
 /**
  * Determine what attributes a given class is allowed to render on itself as
  * attributes.
  *
  * @return    array          Allowed attribute array
  */
 public static function allowedAttributes()
 {
     if (!is_array(self::$attributes)) {
         $attributes = array_merge(Config::get('attributes.event.standard', []), Config::get('attributes.standard', []));
         if (isset(self::$localAttributes)) {
             foreach (self::$localAttributes as $attr) {
                 $attributes = array_merge($attributes, Config::get("attributes.{$attr}", []));
             }
         }
         self::$attributes = $attributes;
     }
     return self::$attributes;
 }
예제 #7
0
<?php

namespace Geek;

// Aliasing rules
use Nerd\Config, Nerd\Environment;
define('APPLICATION_NS', 'geek');
error_reporting(Config::get('error.reporting'));
ini_set('display_errors', Config::get('error.display', true) ? 'On' : 'Off');
date_default_timezone_set(Config::get('application.timezone', 'UTC'));
\Nerd\Str::$mbString and mb_internal_encoding(Config::get('application.encoding', 'UTF-8'));
Application::instance()->execute();
예제 #8
0
 /**
  * Session garbage collection
  *
  * @param    integer          Session lifetime
  * @return   void
  */
 public function gc($life)
 {
     $table = Config::get('session.mysql.table', 'nerd_sessions');
     static::$connection->query("DELETE FROM {$table} WHERE updated_at < DATE_SUB(NOW(), INTERVAL {$life} SECOND)");
 }
예제 #9
0
 /**
  * The dispatcher extracts the active URI and routes to a namespaced
  * Controller for further handling.
  *
  * [!!] This method could use some serious optimization, and modularity.
  *
  * ## Usage
  *
  *     $request = FrontController::dispatch();
  *
  * Once you've dispatched your request, you can handle everything after
  * as you would a \Http\Response.
  *
  * @param    string       URI to parse
  * @return   Response     Returns the response instance for further execution
  */
 public function dispatch($uri, \Nerd\Http\Response &$response)
 {
     $default = Config::get('routes._default_');
     $default = \explode('/', $default);
     if (($controller = (isset($default[0]) and !empty($default[0])) ? \ucfirst($default[0]) : false) === false) {
         throw new \Exception('Your application does not appear to have a value default route configured. Please specify one in your routes configuration file.');
     }
     $action = (isset($default[1]) and !empty($default[1])) ? 'action' . ucfirst($default[1]) : 'actionIndex';
     unset($default);
     $directory = \LIBRARY_PATH . \DS;
     $namespace = \APPLICATION_NS;
     $segments = array_merge(array_filter(explode('/', ltrim($uri, '/'))), []);
     // Determine if we're attempting to load a package or the application
     if (isset($segments[0]) and \strtolower($segments[0]) !== \strtolower($namespace) and \is_dir($directory . $segments[0])) {
         $namespace = $segments[0];
         $directory .= $segments[0] . \DS;
         $segments = array_slice($segments, 1);
     } else {
         $directory .= $namespace . \DS;
     }
     $directory .= 'classes' . \DS . 'controller' . \DS;
     //$response   = \Nerd\Http\Response::instance();
     if (count($segments)) {
         $possibility = [];
         while (count($segments) > 0 and is_dir($directory . $segments[0])) {
             $directory .= $segments[0] . \DS;
             $possibility[] = $segments[0];
             $segments = array_slice($segments, 1);
         }
         if (count($segments) > 0) {
             if (!file_exists($directory . $segments[0] . '.php')) {
                 throw new \Nerd\Http\Exception(404, $response);
             }
             $possibility[] = $segments[0];
             $segments = array_slice($segments, 1);
         }
         $controller = '';
         foreach ($possibility as $value) {
             $controller .= ucfirst($value) . '\\';
         }
         $controller = rtrim($controller, '\\');
         if (count($segments) > 0) {
             $action = 'action' . ucfirst(array_shift($segments));
         }
     }
     $controller = '\\' . ucfirst($namespace) . '\\Controller\\' . $controller;
     if (\class_exists($controller)) {
         $controller = new $controller($response);
     }
     if (!\is_object($controller) or !\method_exists($controller, $action)) {
         throw new \Nerd\Http\Exception(404, $response);
     }
     if (!$controller instanceof \Nerd\Design\Architectural\MVC\Controller) {
         throw new \Exception('Corrupt application controller. Controller does not implement the MVC specification.');
     }
     $controller->before();
     if (($body = call_user_func_array(array($controller, $action), $segments)) != null) {
         $response->setBody($body);
     }
     $controller->after();
 }
예제 #10
0
파일: date.php 프로젝트: nerdsrescueme/Core
 /**
  * Return the date in the default Config format
  *
  * @return    string     Default format or ISO8601
  */
 public function render()
 {
     return $this->format(Config::get('date.formats.default', 'Y-m-d H:i'));
 }
예제 #11
0
파일: date.php 프로젝트: nerdsrescueme/Core
 /**
  * Return the current date in the specified format, you may use
  * values from the formats array in Nerd/config/date.php or a
  * date string.
  *
  * @see      http://php.net/manual/en/function.date.php
  *
  * @param    string     Config key or date string
  * @return   string     Formatted date
  */
 public function format($format = 'default')
 {
     return parent::format(\Nerd\Config::get("date.formats.{$format}", $format));
 }