Inheritance: extends Thenbsp\Wechat\Util\Option
Example #1
0
 /**
  * response message entity
  */
 public function setResponse(Entity $entity)
 {
     $body = $entity->getBody();
     $body['ToUserName'] = $this['FromUserName'];
     $body['FromUserName'] = $this['ToUserName'];
     $body['MsgType'] = $entity->getType();
     $body['CreateTime'] = time();
     $response = new XmlResponse($body);
     $response->send();
 }
Example #2
0
 /**
  * 构造方法
  */
 public function __construct(array $options = array())
 {
     $required = array('ToUserName', 'FromUserName', 'CreateTime', 'Music');
     $validator = new OptionValidator();
     $validator->setDefined($required)->setRequired($required)->setAllowedTypes('Music', array('array'));
     $validtated = $validator->validate($options);
     parent::__construct($validtated);
 }
Example #3
0
 /**
  * 构造方法
  */
 public function __construct(array $options = array())
 {
     $required = array('ToUserName', 'FromUserName', 'CreateTime', 'Video');
     $validator = new OptionValidator();
     $validator->setDefined($required)->setRequired($required)->setAllowedTypes('Video', array('array'))->setAllowedValues('Video', function ($value) {
         if (!array_key_exists('MediaId', $value)) {
             throw new \InvalidArgumentException('Undefined index: MediaId');
         }
         return true;
     });
     $validtated = $validator->validate($options);
     parent::__construct($validtated);
 }
Example #4
0
 /**
  * 构造方法
  */
 public function __construct(array $options = array())
 {
     $required = array('ToUserName', 'FromUserName', 'CreateTime', 'ArticleCount', 'Articles');
     $validator = new OptionValidator();
     $validator->setDefined($required)->setRequired($required)->setAllowedTypes('Articles', array('array'))->setAllowedValues('Articles', function ($value) {
         if (!array_key_exists('item', $value)) {
             throw new \InvalidArgumentException('Undefined index: item');
         }
         if (!is_array($value['item'])) {
             throw new \InvalidArgumentException('Articles item must be array');
         }
         if (count($value['item']) > 10) {
             throw new \InvalidArgumentException('Articles item must be Less than 10');
         }
         return true;
     })->setDefault('ArticleCount', function (Options $options) {
         return count($options['Articles']['item']);
     });
     $validtated = $validator->validate($options);
     parent::__construct($validtated);
 }