示例#1
0
文件: events.php 项目: neoisldl/Onion
 /**
  * 订阅类的事件
  *
  * @param string $class
  * @param string $event
  * @param callback $callback
  * @access public
  * @return void
  */
 public function subscribe($class, $event, $callback)
 {
     if (!is_callable($callback)) {
         throw Error::not_callable('Events::subscribe() parameter 3');
     }
     $class = strtolower(ltrim($class, '\\'));
     $this->subscribe[$class][$event][] = $callback;
 }
示例#2
0
文件: view.php 项目: neoisldl/Onion
 /**
  * 获得真正的视图文件名
  *
  * @param string $file
  * @access protected
  * @return string
  */
 protected function findFile($file)
 {
     $ext = $this->file_ext ?: 'php';
     if (!is_file($file)) {
         // 不是绝对路径
         $file = $this->view_dir . '/' . $file;
     }
     $pathinfo = pathinfo($file);
     if (!isset($pathinfo['extension']) || $pathinfo['extension'] != $ext) {
         $file .= '.' . $ext;
     }
     if (!($fullname = realpath($file))) {
         throw Error::file_not_found($file);
     }
     return $fullname;
 }
示例#3
0
 /**
  * 自定义类的autoloader
  * 会覆盖默认的autoloader
  *
  * @param callable $loader
  * @param boolean $throw
  * @param boolean $prepend
  * @access public
  * @return Onion\MVC\Application
  */
 public function setAutoloader($loader, $throw = true, $prepend = false)
 {
     if (!is_callable($loader)) {
         throw Error::not_callable('Application loader');
     }
     spl_autoload_unregister(array($this, 'loadClass'));
     spl_autoload_register($loader, $throw, $prepend);
     return $this;
 }
示例#4
0
 public function setProp($prop, $val = null, $static = true)
 {
     if (static::$readonly) {
         throw OrmError::readonly($this);
     }
     if (is_array($prop)) {
         $props = $prop;
         $strict = $val === null ? true : (bool) $val;
     } else {
         $props = array($prop => $val);
     }
     $meta = static::getMeta();
     foreach ($props as $prop => $val) {
         if (!($prop_meta = $meta->getPropMeta($prop))) {
             if (!$strict) {
                 continue;
             }
             throw Error::undefined_property(get_class($this), $prop);
         }
         if (!$this->is_fresh && ($prop_meta['refuse_update'] || $prop_meta['primary_key'])) {
             throw OrmError::refuse_update($this, $prop);
         }
         $val = $this->formatProp($prop, $val, $prop_meta);
         if (!$prop_meta['allow_null'] && $val === null) {
             throw OrmError::not_allow_null($this, $prop);
         }
         $this->changeProp($prop, $val);
     }
     return $this;
 }