Esempio n. 1
0
 /**
  * Enregistrement des actions
  *
  * @param string $name Nom de l'événement
  * @param callable $callback Action à executer
  * @param int $priority Priorité de l'action
  * @return void
  */
 public static function register($name, $callback, $priority = 10)
 {
     if (!is_callable($callback)) {
         Exception::error(I18n::__('The second parameter must be a function'));
     }
     self::$registered[$name][$priority][] = $callback;
 }
Esempio n. 2
0
 public function __unset($name)
 {
     if (!$this->__isset($name)) {
         Exception::error(I18n::__('Property %s->%s does not exist.', get_called_class(), $name));
     }
     unset($this->{$name});
 }
Esempio n. 3
0
 /**
  * @return bool
  */
 public static function start()
 {
     if (!self::$initialised) {
         session_cache_limiter('');
         ini_set('session.use_cookies', 1);
         if (version_compare(phpversion(), '5.4.0', '>=')) {
             session_register_shutdown();
         } else {
             register_shutdown_function('session_write_close');
         }
         self::$initialised = true;
     }
     if (session_status() === PHP_SESSION_DISABLED) {
         Exception::error(Lib\I18n::__('PHP sessions are disabled.'));
     }
     if (session_status() === PHP_SESSION_ACTIVE) {
         return true;
     }
     if (ini_get('session.use_cookies') && headers_sent($file, $line)) {
         Exception::error(Lib\I18n::__('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line));
     }
     if (!session_start()) {
         Exception::error(Lib\I18n::__('Failed to start the session.'));
     }
     self::$reference =& $_SESSION;
     return true;
 }
Esempio n. 4
0
 public static function check($classes)
 {
     foreach ($classes as $class) {
         if (!in_array($class, self::$requiredClasses)) {
             Exception::error(Lib\I18n::__('Class %s is required.', $class));
         }
     }
 }
Esempio n. 5
0
 function __call($method, $args)
 {
     if (isset($this->methods[$method])) {
         return call_user_func_array($this->methods[$method], $args);
     } else {
         Exception::error(I18n::__('Unknow method %s', $method));
     }
 }
Esempio n. 6
0
 private static function isRegistered($name = null, $exception = true)
 {
     if (isset(self::$registry[$name])) {
         return true;
     } elseif ($exception) {
         Exception::error(I18n::__('%s element %s is nor registered.', __CLASS__, $name));
     }
     return false;
 }
Esempio n. 7
0
 public static function __callStatic($method, array $args = null)
 {
     if (preg_match("#^(link)([A-Z][a-z]+)\$#", $method, $match)) {
         switch ($match[1]) {
             case 'link':
                 return call_user_func_array('self::link', array_merge(array($match[2]), $args));
                 break;
         }
     }
     Exception::error(Lib\I18n::__('Unknow method %s', __CLASS__ . '::' . $method));
     return false;
 }
Esempio n. 8
0
 /**
  * Chargement d'un répertoire de langue
  *
  * @param $domain
  * @param $directory
  * @return void
  */
 public function load($domain, $directory)
 {
     if (is_dir($directory)) {
         if (!in_array($directory, self::$directories)) {
             self::$directories[] = $directory;
             bindtextdomain($domain, $directory);
             bind_textdomain_codeset($domain, SJO_CHARSET);
         }
     } else {
         Exception::error('I18n directory ' . $directory . ' do not exists.');
     }
 }
Esempio n. 9
0
 public static function getClass($module, $className)
 {
     $class = '\\Module\\' . $module . '\\' . ltrim($className, '\\');
     $defaultClass = '\\sJo' . $class;
     if (class_exists($class)) {
         if (!get_parent_class($class) == $defaultClass) {
             Exception::error(Lib\I18n::__('Classe %s is not extended to %s.', $class, $defaultClass));
         }
     } else {
         $class = $defaultClass;
     }
     return $class;
 }
Esempio n. 10
0
 /**
  * Créé et retourne l'objet courrant
  *
  * @access public
  * @static
  * @param int $id
  * @return static
  */
 public static function getInstance($id = 0)
 {
     if (isset(self::$auth[$id])) {
         return static::SingletonGetInstance(self::$auth[$id], $id);
     } else {
         Exception::error(Lib\I18n::__('Drivers Unknow Auth ID %s.', $id));
     }
     return false;
 }
Esempio n. 11
0
 protected final function inc(array $args)
 {
     $closure = new Closure();
     foreach ($args as $name => $value) {
         if (!in_array($name, array('attributes'))) {
             $closure->{$name} = $value;
         }
     }
     $closure->attributes = function (array $attributes = array()) use($args) {
         if (!isset($args['attributes'])) {
             return null;
         }
         $output = '';
         foreach ($attributes as $name => $value) {
             if (isset($args['attributes'][$name])) {
                 $args['attributes'][$name] .= ' ' . $value;
             } else {
                 $args['attributes'][$name] = $value;
             }
         }
         foreach ($args['attributes'] as $name => $value) {
             if (!Validate::isEmpty($value)) {
                 switch ($name) {
                     case 'data':
                         foreach ($value as $subname => $subvalue) {
                             $output .= ' ' . $name . '-' . $subname . '="' . trim($subvalue) . '"';
                         }
                         break;
                     default:
                         $output .= ' ' . $name . '="' . trim($value) . '"';
                         break;
                 }
             }
         }
         return $output;
     };
     $closure->attribute = function ($name) use($args) {
         if (!isset($args['attributes'])) {
             return null;
         }
         return isset($args['attributes'][$name]) ? $args['attributes'][$name] : null;
     };
     $filename = $this->getTplFile();
     if (file_exists($filename)) {
         ob_start();
         $closure->inc($filename);
         return ob_get_clean();
     } else {
         Exception::error(I18n::__('helper %s do not exists.', $filename . '.php'));
     }
     return false;
 }