Пример #1
0
 /**
  * 重载了魔术方法__call
  * 
  * 当类的方法访问不到时调用该方法,在这里的实现是配置类属性对象的延迟加载策略
  * <code>
  * //延迟访问某个属性,当使用这种方式调用时该方法被调用,并访问该类中的$_delayAttributes属性,并创建该属性对象并返回
  * $this->_getMethodName(); 
  * </code>
  * @param string $methodName
  * @param array $args
  * @return mixed
  */
 public function __call($methodName, $args)
 {
     $_prefix = substr($methodName, 0, 4);
     $_propertyName = substr($methodName, 4);
     $_propertyName = WindUtility::lcfirst($_propertyName);
     if ($_prefix == '_get') {
         if (!$this->{$_propertyName} && isset($this->_delayAttributes[$_propertyName])) {
             $_property = $this->_delayAttributes[$_propertyName];
             $_value = null;
             if (isset($_property['value'])) {
                 $_value = $_property['value'];
             } elseif (isset($_property['ref'])) {
                 $_value = Wind::getApp()->getWindFactory()->getInstance($_property['ref'], $args);
             } elseif (isset($_property['path'])) {
                 $_className = Wind::import($_property['path']);
                 $_value = WindFactory::createInstance($_className, $args);
             }
             $this->{$_propertyName} = $_value;
             /*unset($this->delayAttributes[$_propertyName]);*/
         }
         return $this->{$_propertyName};
     } elseif ($_prefix == '_set') {
         $this->{$_propertyName} = $args[0];
     }
 }
Пример #2
0
 public function preHandle()
 {
     if (!$this->form) {
         return null;
     }
     $className = Wind::import($this->form);
     $form = WindFactory::createInstance($className);
     $methods = get_class_methods($form);
     foreach ($methods as $method) {
         if (0 !== strpos($method, 'set') || '' == ($_tmp = substr($method, 3))) {
             continue;
         }
         if (null === ($input = $this->getRequest()->getRequest(WindUtility::lcfirst($_tmp), null))) {
             continue;
         }
         call_user_func_array(array($form, $method), array($input));
     }
     $form->validate();
     $this->getRequest()->setAttribute($form, WindUtility::lcfirst($className));
     $this->sendError($form->getErrorAction(), $form->getErrors());
 }
 /**
  * 生成简单钩子
  *
  * @param unknown_type $hookname        	
  */
 public function generateSimpleHook($hookname)
 {
     $hookInfo = Wekit::load('hook.PwHooks')->fetchByName($hookname);
     list($description, $doc) = explode("\r\n", $hookInfo['document']);
     if (!$doc) {
         return new PwError('APPCENTER:generate.unsupport.hook');
     }
     preg_match_all('/\\$[a-zA-Z_][a-zA-Z0-9_]*/', $doc, $matches);
     $param = implode(', ', $matches[0]);
     $doc = str_replace("\n", "\n\t * ", $doc);
     $this->baseDir = Wind::getRealDir('EXT:' . $this->alias);
     $manifest = Wind::getComponent('configParser')->parse($this->baseDir . '/Manifest.xml');
     $thing = substr($hookname, 2);
     $classname = $this->_ucwords($this->alias . '_' . $thing) . 'Do';
     $method = WindUtility::lcfirst($this->_ucwords($this->alias)) . 'Do';
     $hook = array('app_' . $this->alias => array('class' => 'EXT:' . $this->alias . '.service.srv.' . $classname, 'loadway' => 'load', 'method' => $method, 'description' => 'this is another ' . $hookname));
     $manifest['inject-services'][$hookname] = $hook;
     Wind::import('WIND:parser.WindXmlParser');
     $parser = new WindXmlParser();
     $manifest = str_replace('><', ">\n\t<", $parser->parseToXml(array('manifest' => $manifest), Wind::getApp()->getResponse()->getCharset()));
     if (!WindFile::write($this->baseDir . '/Manifest.xml', $manifest)) {
         return new PwError('APPCENTER:generate.copy.fail');
     }
     $class = WindFile::read(dirname($this->defaultDir) . '/simplehook');
     $class = strtr($class, array('{{method}}' => $method, '{{classname}}' => $classname, '{{document}}' => $doc, '{{param}}' => $param, '{{classname}}' => $classname, '{{author}}' => $this->author, '{{email}}' => $this->email, '{{website}}' => $this->website, '{{description}}' => $description));
     WindFolder::mkRecur($this->baseDir . '/service/srv/');
     if (!WindFile::write($this->baseDir . '/service/srv/' . $classname . '.php', $class)) {
         return new PwError('APPCENTER:generate.copy.fail');
     }
 }