示例#1
0
文件: WebService.php 项目: jymsy/sky2
 /**
  * 生成由provider定义的WSDL
  * @return string 生成的WSDL字符串
  */
 public function generateWsdl()
 {
     $providerClass = is_object($this->provider) ? get_class($this->provider) : \Sky\Sky::import($this->provider, true);
     $generator = \Sky\Sky::createComponent($this->generatorConfig);
     $wsdl = $generator->generateWsdl($providerClass, $this->namespace, $this->encoding);
     return $wsdl;
 }
示例#2
0
文件: LogRouter.php 项目: jymsy/sky2
 /**
  * 初始化应用组件
  */
 public function init()
 {
     // 		parent::init();
     foreach ($this->_routes as $name => $route) {
         $route = \Sky\Sky::createComponent($route);
         $route->init();
         $this->_routes[$name] = $route;
     }
     // 		VarDump::dump($this->_routes);
     \Sky\Sky::getLogger()->attachEventHandler('onFlush', array($this, 'collectLogs'));
     \Sky\Sky::$app->attachEventHandler('onEndRequest', array($this, 'processLogs'));
 }
示例#3
0
文件: Validator.php 项目: jymsy/sky2
 /**
  * 创建一个验证器对象
  * @param string $type 验证器的类型。可以使内置验证器的名字或自定义验证器的类名。
  * @param \Sky\base\Model $object 要被验证的数据对象。
  * @param array|string $attributes 要被验证的属性列表。
  * 既可以是包含属性名的数组,也可以是用逗号分隔的属性名。
  * @param array $params 要被赋给验证器类的初始属性值。
  * @return Validator 验证器类对象
  */
 public static function createValidator($type, $object, $attributes, $params = array())
 {
     if (is_string($attributes)) {
         $attributes = preg_split('/[\\s,]+/', $attributes, -1, PREG_SPLIT_NO_EMPTY);
     }
     $params['attributes'] = $attributes;
     if (method_exists($object, $type)) {
         // 基于方法的验证器。
         $params['class'] = __NAMESPACE__ . '\\InlineValidator';
         $params['method'] = $type;
     } else {
         if (isset(static::$builtInValidators[$type])) {
             $type = static::$builtInValidators[$type];
         }
         $params['class'] = $type;
     }
     $obj = Sky::createComponent($params);
     $obj->init();
     return $obj;
 }
示例#4
0
 /**
  * @param \Sky\base\Controller $controller
  * @param \Sky\base\Action $action
  * @param array $filters
  */
 public static function create($controller, $action, $filters)
 {
     $chain = new self($controller, $action);
     $actionID = $action->getId();
     foreach ($filters as $filter) {
         if (is_string($filter)) {
             if (($pos = strpos($filter, '+')) !== false || ($pos = strpos($filter, '-')) !== false) {
                 $matched = preg_match("/\\b{$actionID}\\b/i", substr($filter, $pos + 1)) > 0;
                 if (($filter[$pos] === '+') === $matched) {
                     $filter = InlineFilter::create($controller, trim(substr($filter, 0, $pos)));
                 }
             } else {
                 $filter = InlineFilter::create($controller, $filter);
             }
         } elseif (is_array($filter)) {
             if (!isset($filter[0])) {
                 throw new \Exception('The first element in a filter configuration must be the filter class.');
             }
             $filterClass = $filter[0];
             unset($filter[0]);
             if (($pos = strpos($filterClass, '+')) !== false || ($pos = strpos($filterClass, '-')) !== false) {
                 $matched = preg_match("/\\b{$actionID}\\b/i", substr($filterClass, $pos + 1)) > 0;
                 if (($filterClass[$pos] === '+') === $matched) {
                     $filterClass = trim(substr($filterClass, 0, $pos));
                 } else {
                     continue;
                 }
             }
             $filter['class'] = $filterClass;
             $filter = Sky::createComponent($filter);
         }
         if ($filter instanceof Filter) {
             $filter->init();
             $chain->_chainList[] = $filter;
             // 				$chain->add($filter);
         } else {
             throw new \Exception('FilterChain can only take instance of Filter.');
         }
     }
     return $chain;
 }
示例#5
0
 /**
  * @param string $name 命令名 (大小写敏感)
  * @return ConsoleCommand 命令对象. 如果名字非法的话返回null.
  */
 public function createCommand($name)
 {
     $name = strtolower($name);
     $command = null;
     if (isset($this->commands[$name])) {
         $command = $this->commands[$name];
     } else {
         $commands = array_change_key_case($this->commands);
         if (isset($commands[$name])) {
             $command = $commands[$name];
         }
     }
     // 		echo $command;
     if ($command !== null) {
         if (is_string($command)) {
             if (strpos($command, '/') !== false) {
                 $classPathName = substr($command, strpos($command, Sky::$app->name), -4);
                 // 					$classPathName=substr($classPathName, strpos($classPathName, '/')+1);
                 $className = str_replace('/', '\\', $classPathName);
                 // 					echo $className;
                 if (!class_exists($className, false)) {
                     require_once $command;
                 }
             } else {
                 throw new \Exception('command ' . $command . ' must be a filepath');
             }
             return new $className($name, $this);
         } else {
             // an array configuration
             return Sky::createComponent($command, $name, $this);
         }
     } elseif ($name === 'help') {
         return new HelpCommand('help', $this);
     } else {
         return null;
     }
 }
示例#6
0
文件: Response.php 项目: jymsy/sky2
 /**
  * 准备要发送的响应。
  * @throws \Exception 如果格式不支持的话
  */
 protected function prepare()
 {
     if ($this->data === null) {
         return;
     }
     if (isset($this->formatters[$this->format])) {
     } else {
         switch ($this->format) {
             case self::FORMAT_HTML:
                 $this->setHeader('Content-Type', 'text/html; charset=' . $this->charset);
                 $this->content = $this->data;
                 break;
             case self::FORMAT_RAW:
                 $this->content = $this->data;
                 break;
             case self::FORMAT_JSON:
                 $this->setHeader('Content-Type', 'application/json');
                 $this->content = JSON::encode($this->data);
                 break;
             case self::FORMAT_JSONP:
                 $this->setHeader('Content-Type', 'text/javascript; charset=' . $this->charset);
                 // 					if (is_array($this->data) && isset($this->data['data'], $this->data['callback'])) {
                 // 						$this->content = sprintf('%s(%s);', $this->data['callback'], JSON::encode($this->data['data']));
                 // 					} else {
                 if (isset($this->jsonpcallback)) {
                     $this->content = sprintf('%s(%s);', $this->jsonpcallback, JSON::encode($this->data));
                 } else {
                     $this->content = '';
                 }
                 break;
             case self::FORMAT_XML:
                 Sky::createComponent(array('class' => 'Sky\\web\\XmlResponse'))->format($this);
                 break;
             default:
                 throw new \Exception("Unsupported response format: {$this->format}");
         }
     }
 }
示例#7
0
文件: Module.php 项目: jymsy/sky2
 /**
  * 取回已经配置的模块。
  * 模块必须要在 {@link modules}中声明。
  * 当通过id第一次调用该方法的时候,一个新的实例将会创建。
  * @param string $id 模块 ID (大小写敏感)
  * @return Module 模块实例, 如果模块被禁用或不存在的话返回null。
  */
 public function getModule($id)
 {
     // 		Sky::log('get module '.$id);
     if (isset($this->_modules[$id]) || array_key_exists($id, $this->_modules)) {
         // 			Sky::log($this->_modules[$id]);
         return $this->_modules[$id];
     } elseif (isset($this->_moduleConfig[$id])) {
         $config = $this->_moduleConfig[$id];
         if (!isset($config['enabled']) || $config['enabled']) {
             Sky::trace('Loading ' . $id . ' module', 'system.base.Module');
             $class = $config['class'];
             unset($config['class']);
             // 			\Sky\Sky::log('this is class '.$class);
             if ($this === Sky::$app) {
                 // 				Sky::log('createcompontn '.$id);
                 $module = Sky::createComponent($class, $id, null, $config);
                 // 				Sky::log('createcompontn over '.$id);
             } else {
                 // 				Sky::log($this->getId().'/'.$id);
                 $module = Sky::createComponent($class, $id, $this, $config);
                 // 				Sky::log('set child module finish');
             }
             $this->_modules[$id] = $module;
             // 			Sky::log('set modules array');
             return $module;
         }
     }
 }