コード例 #1
0
ファイル: Request.php プロジェクト: hjr3/titon
 /**
  * Loads the $_POST, $_FILES data, configures the query params and populates the accepted headers fields.
  *
  * @access public
  * @return void
  */
 public function initialize()
 {
     if ($this->_initialized) {
         return;
     }
     parent::initialize();
     // Store data
     $this->data =& App::$data;
     $this->params = Router::current();
     // Store accept HTTP headers
     foreach (array('Accept', 'Accept-Language', 'Accept-Charset') as $acception) {
         if ($accept = $this->env($acception)) {
             $accept = explode(',', $accept);
             foreach ($accept as $type) {
                 if (strpos($type, ';') !== false) {
                     list($type, $quality) = explode(';', $type);
                 } else {
                     $quality = 1;
                 }
                 $data = array('type' => $type, 'quality' => str_replace('q=', '', $quality));
                 if ($acception == 'Accept-Language') {
                     $this->__acceptLangs[] = $data;
                 } else {
                     if ($acception == 'Accept-Charset') {
                         $this->__acceptCharsets[] = $data;
                     } else {
                         $this->__acceptTypes[] = $data;
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: Hook.php プロジェクト: hjr3/titon
 /**
  * Cycles through the hooks for the specified event, and executes the related method.
  * If a scope is defined, and the hook doesn't match the scope, it will be bypassed.
  *
  * @access public
  * @param string $event
  * @param object $Object    - Object passed by reference: Controller, View, etc
  * @return void
  * @static
  */
 public static function execute($event, $Object = null)
 {
     if (!empty(self::$__hooks[$event])) {
         $route = Router::current();
         foreach (self::$__hooks[$event] as $slug => &$hook) {
             if ($hook['executed'] === true) {
                 continue;
             }
             // Check to see if the hook is restricted to a certain scope
             if (isset(self::$__scopes[$event][$slug])) {
                 $scope = self::$__scopes[$event][$slug];
                 foreach (array('container', 'controller', 'action') as $action) {
                     if ($scope[$action] != $route[$action] || $scope[$action] != '*') {
                         continue;
                     }
                 }
             }
             if (isset(self::$__objectMap[$slug])) {
                 $obj = self::$__objectMap[$slug];
                 if ($obj instanceof Closure) {
                     $obj($Object);
                 } else {
                     if (method_exists($obj, $event)) {
                         $obj->{$event}($Object);
                     }
                 }
             }
             $hook['executed'] = true;
         }
     }
 }
コード例 #3
0
ファイル: Html.php プロジェクト: hjr3/titon
 /**
  * Create an HTML anchor link.
  *
  * @access public
  * @param string $title
  * @param string|array $url
  * @param array $attributes
  * @return string
  */
 public function anchor($title, $url, array $attributes = array())
 {
     if ($route = Router::detect($url)) {
         $url = Router::construct($route);
     }
     $attributes['href'] = $url;
     if (!isset($attributes['title'])) {
         $attributes['title'] = htmlentities($title, ENT_COMPAT, App::charset());
     }
     return $this->tag('anchor', $this->attributes($attributes), $title);
 }
コード例 #4
0
ファイル: Dispatch.php プロジェクト: hjr3/titon
 /**
  * Initialize dispatch and detects if a custom dispatcher should be used within the current scope.
  * If no scope is defined, the default dispatcher will be instantiated.
  *
  * @access public
  * @return void
  * @static
  */
 public static function initialize()
 {
     $params = Router::current();
     $dispatch = null;
     if (!empty(self::$__mapping)) {
         // Specific controller and container
         if (isset(self::$__mapping[$params['container'] . '.' . $params['controller']])) {
             $dispatch = self::$__mapping[$params['container'] . '.' . $params['controller']];
             // All controllers within a specific container
         } else {
             if (isset(self::$__mapping[$params['container'] . '.*'])) {
                 $dispatch = self::$__mapping[$params['container'] . '.*'];
                 // Specific controller within any container
             } else {
                 if (isset(self::$__mapping['*.' . $params['controller']])) {
                     $dispatch = self::$__mapping['*.' . $params['controller']];
                     // Apply to all controllers and containers
                 } else {
                     if (isset(self::$__mapping['*.*'])) {
                         $dispatch = self::$__mapping['*.*'];
                     }
                 }
             }
         }
     }
     if ($dispatch) {
         $Dispatcher = $dispatch($params);
     } else {
         switch (Environment::detect()) {
             case 'development':
                 $Dispatcher = new \titon\modules\dispatchers\front\FrontDev($params);
                 break;
             default:
                 $Dispatcher = new \titon\modules\dispatchers\front\Front($params);
                 break;
         }
     }
     if ($Dispatcher instanceof \titon\modules\dispatchers\DispatcherInterface) {
         $Dispatcher->run();
         exit;
     }
     throw new Exception(sprintf('%s Dispatcher must implement the \\titon\\modules\\dispatchers\\DispatcherInterface.', $dispatch));
 }
コード例 #5
0
ファイル: Application.php プロジェクト: hjr3/titon
 /**
  * Initialize all classes required for runtime. Master initialize method.
  *
  * @access public
  * @return void
  * @static
  */
 public static function initialize()
 {
     // Try and autoload from include_paths first
     spl_autoload_register();
     spl_autoload_register('\\titon\\core\\App::autoload');
     // Initialize core components
     Environment::initialize();
     Debugger::initialize();
     Router::initialize();
     // Get super globals
     $get = $_GET;
     $post = $_POST;
     $files = array();
     if (!empty($_FILES)) {
         foreach ($_FILES as $model => $data) {
             foreach ($data as $meta => $values) {
                 $keys = array_keys($values);
                 $files[$model][$keys[0]][$meta] = $values[$keys[0]];
             }
         }
     }
     // Clear magic quotes, just in case
     if (get_magic_quotes_gpc() > 0) {
         $stripSlashes = function ($data) {
             return is_array($data) ? array_map($stripSlashes, $data) : stripslashes($data);
         };
         $get = $stripSlashes($get);
         $post = $stripSlashes($post);
         $files = $stripSlashes($files);
     }
     static::$data = array_merge_recursive($post, $files);
     static::$globals = array('_GET' => $get, '_POST' => $post, '_FILES' => $files, '_SERVER' => $_SERVER, '_ENV' => $_ENV);
 }
コード例 #6
0
ファイル: Form.php プロジェクト: hjr3/titon
 /**
  * Open a form by outputting the form open tag.
  *
  * @access public
  * @param string $model
  * @param array $attributes
  * @return string
  */
 public function open($model, array $attributes = array())
 {
     if (!empty($model) && is_string($model)) {
         $model = Inflector::modelize($model);
         $this->_model = $model;
     }
     // Form type
     if (isset($attributes['type'])) {
         if ($attributes['type'] == 'file') {
             $attributes['enctype'] = 'multipart/form-data';
         }
         unset($attributes['type']);
     }
     // Fieldset legend
     $legend = null;
     if (isset($attributes['legend'])) {
         $legend = $attributes['legend'];
         unset($attributes['legend']);
     }
     // Attributes
     $attributes = array_merge(array('method' => 'post', 'action' => '', 'id' => $this->_model . 'Form'), $attributes);
     if (!empty($attributes['action'])) {
         $attributes['action'] = Router::construct(Router::detect($attributes['action']));
     }
     $output = $this->tag('form_open', $this->attributes($attributes));
     // If legend, add fieldset
     if (isset($legend)) {
         $attributes['legend'] = $legend;
         $output .= $this->tag('fieldset_open');
         $output .= $this->tag('legend', $legend);
     }
     // Save its state
     $this->_forms[$this->_model] = $attributes;
     return $output;
 }