/** * @return WindHttpRequest */ public function getRequest() { if ($this->_request === null) { $this->_request = WindFactory::createInstance('WindCommandRequest'); } return $this->_request; }
public function beforeStart($front = null) { parent::beforeStart($front); if (!Wind::getComponent('router')->getRoute('pw')) { Wind::getComponent('router')->addRoute('pw', WindFactory::createInstance(Wind::import('LIB:route.PwRoute'), array('bbs'))); } }
public function preHandle() { if (!($compilers = $this->getCompiler())) { return; } /* @var $chain WindHandlerInterceptorChain */ $chain = WindFactory::createInstance('WindHandlerInterceptorChain'); foreach ($compilers as $key => $value) { $_compiler = Wind::import($value); $chain->addInterceptors(array($key => new $_compiler())); } $chain->getHandler()->handle(); }
/** * 解析action过滤链的配置信息 * * @param WindSimpleController $handler * @return void */ protected function resolveActionFilters(&$handler) { if (!($filters = $this->getConfig('filters'))) { return; } /* @var $cache AbstractWindCache */ $_filters = array(); if ($cache = Wind::getComponent('windCache')) { $_filters = $cache->get('filters'); } $_token = $this->handlerAdapter->getModule() . '/' . $this->handlerAdapter->getController() . '/' . $this->handlerAdapter->getAction(); if (!isset($_filters[$_token])) { foreach ($filters as $_filter) { if (empty($_filter['class'])) { continue; } $_pattern = empty($_filter['pattern']) ? '' : $_filter['pattern']; unset($_filter['pattern']); if ($_pattern) { $_pattern = str_replace(array('*', '/'), array('\\w*', '\\/'), $_pattern); if (in_array($_pattern[0], array('~', '!'))) { $_pattern = substr($_pattern, 1); if (preg_match('/^' . $_pattern . '$/i', $_token)) { continue; } } else { if (!preg_match('/^' . $_pattern . '$/i', $_token)) { continue; } } } $_filters[$_token][] = $_filter; } $cache && $cache->set('filters', $_filters); } if (empty($_filters[$_token])) { return; } /* @var $proxy WindClassProxy */ $proxy = WindFactory::createInstance(Wind::import('WIND:filter.proxy.WindClassProxy')); $proxy->registerTargetObject($handler); foreach ($_filters[$_token] as $value) { $proxy->registerEventListener($this->factory->createInstance(Wind::import($value['class']), array($handler->getForward(), $handler->getErrorMessage(), $this->handlerAdapter, $value)), 'doAction'); } $handler = $proxy; }
public function setConfig($config) { parent::setConfig($config); if ($this->_config) { $this->_module = $this->getConfig('module', 'default-value', $this->_module); $this->_controller = $this->getConfig('controller', 'default-value', $this->_controller); $this->_action = $this->getConfig('action', 'default-value', $this->_action); $this->moduleKey = $this->getConfig('module', 'url-param', $this->moduleKey); $this->controllerKey = $this->getConfig('controller', 'url-param', $this->controllerKey); $this->actionKey = $this->getConfig('action', 'url-param', $this->actionKey); foreach ($this->getConfig('routes', '', array()) as $routeName => $route) { if (!isset($route['class'])) { continue; } $instance = WindFactory::createInstance(Wind::import($route['class'])); $instance->setConfig($route); $this->addRoute($routeName, $instance, isset($route['default']) && $route['default'] === true); } } }
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 string $username 用户名 * @param string $email 用户邮件 * @param string $statu 激活标志 * @param int $uid 用户ID * @return boolean */ public function sendEmailActive($username, $email, $statu = '', $uid = 0) { if (!$this->config['active.mail']) { return true; } if ($uid == 0 || !$statu) { $info = $this->_getUserDs()->getUserByName($username, PwUser::FETCH_MAIN); if ($info['email'] != $email) { return new PwError('USER:illegal.request'); } $uid = $info['uid']; $statu = self::createRegistIdentify($uid, $info['password']); } if (!Wind::getComponent('router')->getRoute('pw')) { Wind::getComponent('router')->addRoute('pw', WindFactory::createInstance(Wind::import('LIB:route.PwRoute'), array('bbs'))); } $code = substr(md5(Pw::getTime()), mt_rand(1, 8), 8); $url = WindUrlHelper::createUrl('u/register/activeEmail', array('code' => $code, '_statu' => $statu), '', 'pw'); list($title, $content) = $this->_buildTitleAndContent('active.mail.title', 'active.mail.content', $username, $url); /* @var $activeCodeDs PwUserActiveCode */ $activeCodeDs = Wekit::load('user.PwUserActiveCode'); $activeCodeDs->addActiveCode($uid, $email, $code, Pw::getTime()); $mail = new PwMail(); $mail->sendMail($email, $title, $content); return true; }
/** * 返回验证器 * * @return WindValidator * @throws WindException 验证器创建失败抛出异常 */ protected function getValidator() { if ($this->_validator === null) { $_className = Wind::import($this->_validatorClass); $this->_validator = WindFactory::createInstance($_className); if ($this->_validator === null) { throw new WindException('[base.WindEnableValidateModule.getValidator] validator', WindException::ERROR_RETURN_TYPE_ERROR); } } return $this->_validator; }
/** * 创建并返回过滤链,如果过滤链已经被创建不重复创建 * * @return WindHandlerInterceptorChain * @throws WindException */ private function _getInterceptorChain() { if (null === $this->_interceptorChain) { $chain = Wind::import($this->_class_interceptorChain); $this->_interceptorChain = WindFactory::createInstance($chain); $this->_interceptorChain->addInterceptors($this->_listener); } return $this->_interceptorChain; }
/** * 设置类代理对象,并返回代理类对象 * 代理类同当前类拥有同样的职责和功能,可以通过访问代理类对象访问当前类. * 类的代理信息对应的组件配置为<code><component * proxy=''>...</component></code>当'proxy'设置为false时返回该类的代理类型, * 类默认的代理类型为WindClassProxy,不可以通过配置进行修改. * * @param string $proxy * @param WindModule $instance * @return WindClassProxy */ protected function setProxyForClass($proxy, $listeners, $instance) { if (!$proxy) { return $instance; } if (true === $proxy) { $proxy = $this->proxyType; } /* @var $proxy WindClassProxy */ $proxy = self::createInstance(Wind::import($proxy)); $proxy->registerTargetObject($instance); foreach ($listeners as $key => $value) { $listener = WindFactory::createInstance(Wind::import($value)); $proxy->registerEventListener($listener, $key); } // $instance->_proxy = $proxy; return $proxy; }
/** * 创建并返回过滤链,如果过滤链已经被创建不重复创建 * * @param string $event 事件名称 默认值为空 * @return WindHandlerInterceptorChain * @throws WindException */ private function _getInterceptorChain($event = '') { if (null === $this->_interceptorChain) { $chain = Wind::import($this->_class_interceptorChain); $this->_interceptorChain = WindFactory::createInstance($chain); } $this->_interceptorChain->reset(); return $this->_interceptorChain; }
/** * 重载了魔术方法__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::getComponent($_property['ref'], $args); } elseif (isset($_property['path'])) { $_className = Wind::import($_property['path']); $_value = WindFactory::createInstance($_className, $args); } $this->{$_propertyName} = $_value; } return $this->{$_propertyName}; } elseif ($_prefix == '_set') { $this->{$_propertyName} = $args[0]; } }
/** * 发送邮件 * * @param string $type 发送类型 * @param array $config 邮件发送器需要的配置数据 * @return boolean * @throws Exception */ public function send($type = self::SEND_SMTP, $config = array()) { $class = Wind::import('Wind:mail.sender.Wind' . ucfirst($type) . 'Mail'); /* @var $sender IWindSendMail */ $sender = WindFactory::createInstance($class); return $sender->send($this, $config); }
/** * 发送邮件 * * @param string $type 发送类型 * @param array $config 邮件发送器需要的配置数据 * @return boolean */ public function send($type = self::SEND_SMTP, $config = array()) { try { $class = Wind::import('Wind:mail.sender.Wind' . ucfirst($type) . 'Mail'); /* @var $sender IWindSendMail */ $sender = WindFactory::createInstance($class); return $sender->send($this, $config); } catch (Exception $e) { if (WIND_DEBUG & 2) { Wind::getApp()->getComponent('windLogger')->info('[mail.WindMail.send] send mail fail. ' . $e->getMessage(), 'windmail'); } if (WIND_DEBUG & 1) { throw new WindMailException('[mail.WindMail.send] send mail fail.' . $e->getMessage()); } return false; } }
/** * action过滤链策略部署 * * @example <pre> * $filters = array(array('expression'=>'', 'class'=>'', * args=array())); * </pre> * @param array $filters * @return void */ protected function resolveActionFilter($filters) { if (!$filters) { return; } $chain = WindFactory::createInstance('WindHandlerInterceptorChain'); $args = array($this->getForward(), $this->getErrorMessage(), null); foreach ((array) $filters as $value) { $chain->addInterceptors(WindFactory::createInstance(Wind::import($value['class']), empty($value['args']) ? $args : array_merge($args, array($value['args'])))); } $chain->getHandler()->handle(); }
/** * 创建并返回过滤链,如果过滤链已经被创建不重复创建 * * @param string $event 事件名称 默认值为空 * @return WindHandlerInterceptorChain * @throws WindException */ private function _getInterceptorChain($event = '') { if (null === $this->_interceptorChainObj) { $chain = Wind::import($this->_interceptorChain); $interceptorChain = WindFactory::createInstance($chain); if ($interceptorChain && $interceptorChain instanceof WindHandlerInterceptorChain) { $this->_interceptorChainObj = $interceptorChain; } else { throw new WindException('[base.WindClassProxy._getInterceptorChain] Unable to create interceptorChain.'); } } $this->_interceptorChainObj->reset(); return $this->_interceptorChainObj; }
public function init($front = null) { parent::init($front); Wind::getComponent('router')->getRoute('pw') || Wind::getComponent('router')->addRoute('pw', WindFactory::createInstance(Wind::import('LIB:route.PwRoute'))); Wind::getComponent('router')->addRoute('admin', WindFactory::createInstance(Wind::import('LIB:route.AdminRoute')), true); }
public function beforeStart($front = null) { parent::beforeStart($front); if (!Wind::getComponent('router')->getRoute('pw')) { Wind::getComponent('router')->addRoute('pw', WindFactory::createInstance(Wind::import('LIB:route.PwRoute'), array('bbs'))); } Wind::getComponent('router')->addRoute('admin', WindFactory::createInstance(Wind::import('LIB:route.PwAdminRoute'), array('default')), true); Wekit::setapp('windid', Wekit::app()); }