Esempio n. 1
0
File: Hook.php Progetto: hjr3/titon
 /**
  * Register a Hook (predefined class) to be called at certain events.
  * Can drill down the hook to only execute during a certain scope (controller, action).
  *
  * @access public
  * @param HookInterface $Hook
  * @param array $scope
  * @return void
  * @static
  */
 public static function register(HookInterface $Hook, array $scope = array())
 {
     if ($Hook) {
         $class = App::toDotNotation(get_class($Hook));
         self::$__objectMap[$class] = $Hook;
         foreach (self::$__events as $event) {
             self::$__hooks[$event][$class] = array('executed' => false);
             if (!empty($scope)) {
                 self::$__scopes[$event][$class] = $scope + array('container' => '*', 'controller' => '*', 'action' => '*');
             }
         }
     }
 }
Esempio n. 2
0
/**
 * Fallback method if the app autoloader isn't called.
 *
 * @param string $class
 * @return void
 */
function __autoload($class)
{
    \titon\core\App::autoload($class);
}
Esempio n. 3
0
 */
require_once FRAMEWORK . 'Paths.php';
require_once FRAMEWORK . 'Bootstrap.php';
/**
 * Require core internals that operate the application.
 */
require_once FRAMEWORK . 'utility' . DS . 'Inflector.php';
require_once FRAMEWORK . 'utility' . DS . 'Set.php';
require_once FRAMEWORK . 'core' . DS . 'Application.php';
require_once FRAMEWORK . 'core' . DS . 'Configuration.php';
require_once FRAMEWORK . 'core' . DS . 'Environment.php';
require_once FRAMEWORK . 'core' . DS . 'Prototype.php';
require_once FRAMEWORK . 'core' . DS . 'Registry.php';
require_once FRAMEWORK . 'router' . DS . 'Router.php';
require_once FRAMEWORK . 'log' . DS . 'Debugger.php';
require_once FRAMEWORK . 'log' . DS . 'Exception.php';
require_once FRAMEWORK . 'system' . DS . 'Dispatch.php';
require_once FRAMEWORK . 'system' . DS . 'Controller.php';
require_once FRAMEWORK . 'system' . DS . 'Hook.php';
/**
 * Require custom config and settings from the application.
 */
require_once CONFIG . 'Environments.php';
require_once CONFIG . 'Setup.php';
require_once CONFIG . 'Routes.php';
require_once CONFIG . 'Bootstrap.php';
/**
 * Initialize the application objects.
 */
\titon\core\App::initialize();
Esempio n. 4
0
File: Html.php Progetto: hjr3/titon
 /**
  * Create a meta element. Has predefined values for common meta tags.
  *
  * @access public
  * @param string $type
  * @param string $content
  * @param array $attributes
  * @return string
  */
 public function meta($type, $content = null, array $attributes = array())
 {
     if (empty($content)) {
         switch (strtolower($type)) {
             case 'content-script-type':
                 $content = 'text/javascript';
                 break;
             case 'content-style-type':
                 $content = 'text/css';
                 break;
             case 'content-type':
                 $content = $this->isDoctype('xhtml') ? 'application/xhtml\\+xml' : 'text/html';
                 $content .= '; charset=' . App::charset();
                 break;
         }
     }
     $metaTypes = array('content-type' => array('http-equiv' => 'Content-Type', 'content' => $content), 'content-script-type' => array('http-equiv' => 'Content-Script-Type', 'content' => $content), 'content-style-type' => array('http-equiv' => 'Content-Style-Type', 'content' => $content), 'content-language' => array('http-equiv' => 'Content-Language', 'content' => $content), 'keywords' => array('name' => 'keywords', 'content' => $content), 'description' => array('name' => 'description', 'content' => $content), 'author' => array('name' => 'author', 'content' => $content), 'robots' => array('name' => 'robots', 'content' => $content), 'rss' => array('type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => $type, 'link' => $content), 'atom' => array('type' => 'application/atom+xml', 'title' => $type, 'link' => $content), 'icon' => array('type' => 'image/x-icon', 'rel' => 'icon', 'link' => $content));
     if (isset($metaTypes[strtolower($type)])) {
         $attributes = $attributes + $metaTypes[strtolower($type)];
     } else {
         $attributes['name'] = $type;
         $attributes['content'] = $content;
     }
     return $this->tag('meta', $this->attributes($attributes));
 }
Esempio n. 5
0
 /**
  * Manually store an object into registry, and store the object name to the $__mapping array.
  * The property $__registered contains the object where as $__mapping is just the class name.
  *
  * @access public
  * @param object $object
  * @param string $slug
  * @return object
  * @static
  */
 public static function store($object, $slug = null)
 {
     if (!is_object($object)) {
         throw new Exception('The object passed must be instantiated.');
     }
     $namespace = get_class($object);
     $className = App::baseClass($namespace);
     if (!$slug) {
         $slug = App::toDotNotation($namespace);
     }
     static::$__registered[$slug] = $object;
     static::$__mapping = Set::insert(static::$__mapping, $slug, $className);
     return $object;
 }
Esempio n. 6
0
File: Form.php Progetto: hjr3/titon
 /**
  * Check to see if a value exists in the POST/GET data, if so escape and return.
  *
  * @access public
  * @param string $model
  * @param string $field
  * @return string
  */
 public function value($model, $field)
 {
     $data =& App::$data;
     $value = Set::extract($data, $model . '.' . $field);
     if (!empty($value)) {
         return is_array($value) ? $value : htmlentities($value, ENT_COMPAT, App::charset());
     } else {
         $data = Set::insert($data, $model . '.' . $field, null);
         return null;
     }
 }
Esempio n. 7
0
 /**
  * Attempts to determine a View path and load the View. If found, returns the instance, else returns the AppView.
  *
  * @access public
  * @return object|null
  */
 public final function loadView()
 {
     $path = $this->routedPath(VIEWS);
     // Use created class if it exists
     if (file_exists($path)) {
         include_once $path;
         $class = App::toNamespace($path);
         if (class_exists($class)) {
             $View = new $class();
         }
         // Else use the AppView
     } else {
         $View = new \app\AppView();
     }
     if ($View instanceof \titon\system\View) {
         return $View;
     }
     throw new Exception(sprintf('The View %s must extend \\app\\AppView.', $this->_config['controller']));
 }
Esempio n. 8
0
 /**
  * Parses an array of attributes to the HTML equivalent.
  *
  * @access public
  * @param array $attributes
  * @param array $remove
  * @return string
  */
 public function attributes(array $attributes, array $remove = array())
 {
     $parsed = null;
     $escape = true;
     if (isset($attributes['escape']) && is_bool($attributes['escape'])) {
         $escape = $attributes['escape'];
     }
     unset($attributes['escape']);
     if (!empty($attributes)) {
         foreach ($attributes as $key => $value) {
             if (in_array($key, $remove)) {
                 unset($attributes[$key]);
                 continue;
             }
             if ($escape === true) {
                 $value = htmlentities($value, ENT_COMPAT, App::charset());
             }
             $parsed .= ' ' . strtolower($key) . '="' . $value . '"';
         }
     }
     return $parsed;
 }
Esempio n. 9
0
 /**
  * Merges the custom configuration with the defaults. Parses the $_classes and imports the class into the scope,
  * but does not instantiate the object until called. Finally executes construct().
  *
  * @access public
  * @param array $config
  * @return void
  */
 public function __construct(array $config = array())
 {
     if (!empty($config)) {
         $this->_config = $config + $this->_config;
     }
     if (!empty($this->_classes)) {
         foreach ($this->_classes as $class => $options) {
             if (isset($options['namespace'])) {
                 App::import($namespace);
             }
         }
     }
     $this->construct();
 }