Beispiel #1
0
 public function create($component, array $args = [], $forceNewInstance = false, $share = [])
 {
     if (!$forceNewInstance && isset($this->instances[$component])) {
         return $this->instances[$component];
     }
     if (empty($this->cache[$component])) {
         $rule = $this->getRule($component);
         $class = new \ReflectionClass($rule->instanceOf ? $rule->instanceOf : $component);
         $constructor = $class->getConstructor();
         $params = $constructor ? $this->getParams($constructor, $rule) : null;
         $this->cache[$component] = function ($args) use($component, $rule, $class, $constructor, $params, $share) {
             if ($rule->shared) {
                 if ($constructor) {
                     try {
                         $this->instances[$component] = $object = $class->newInstanceWithoutConstructor();
                         $constructor->invokeArgs($object, $params($args, $share));
                     } catch (\ReflectionException $r) {
                         $this->instances[$component] = $object = $class->newInstanceArgs($params($args, $share));
                     }
                 } else {
                     $this->instances[$component] = $object = $class->newInstanceWithoutConstructor();
                 }
             } else {
                 $object = $params ? $class->newInstanceArgs($params($args, $share)) : new $class->name();
             }
             if ($rule->call) {
                 foreach ($rule->call as $call) {
                     $class->getMethod($call[0])->invokeArgs($object, call_user_func($this->getParams($class->getMethod($call[0]), $rule), $this->expand($call[1])));
                 }
             }
             return $object;
         };
     }
     return $this->cache[$component]($args);
 }
 public function testGenerator()
 {
     if (!self::$dbh) {
         $this->markTestSkipped('The mysql database isn\'t available, check config and server.');
     }
     $generator = new \Snok\EntityGenerator(self::$dbh, "Test\\Snok\\Entity", __DIR__ . "/Entity");
     $generator->generateAll();
     require_once __DIR__ . "/Entity/Address.php";
     $reflection = new \ReflectionClass("\\Test\\Snok\\Entity\\Address");
     $instance = $reflection->newInstanceWithoutConstructor();
     $this->setupEntity($instance);
     $instance->firstname = "John";
     $instance->lastname = "Logan";
     $instance->address = "123 Ground street";
     $instance->district = "Harlem";
     $instance->city = "Detroit";
     $instance->phone = "555-1234";
     $instance->commit();
     $instance2 = $reflection->newInstanceWithoutConstructor();
     $this->setupEntity($instance2);
     $this->assertNull($instance2->address_id);
     $this->assertNull($instance2->firstname);
     $instance2->address_id = $instance->address_id;
     $instance2->refresh();
     $this->assertEquals("John", $instance2->firstname, "When adding a name to an object with auto increment name should be returned");
     unlink(__DIR__ . "/Entity/Address.php");
 }
Beispiel #3
0
 /**
  * Injects the data in the class
  * @param  object $object The object to inject the data in
  * @return object The instanciated class with its loaded properties
  */
 public function injectData($object = null)
 {
     if ($object !== null) {
         $reflection = new \ReflectionClass($object);
         if ($reflection->getParentClass()->name !== $this->reflection->name) {
             throw new \LogicException('You can only inject data in a class of the same type');
         }
         $class = $object;
     } else {
         $reflection = $this->reflection;
         $class = $this->reflection->newInstanceWithoutConstructor();
     }
     foreach ($this->data as $key => $value) {
         $prop = $reflection->getProperty($key);
         $prop->setAccessible(true);
         // When the value given only is a reference, load it.
         if ($value instanceof Reference) {
             $value = $value->loadRef();
         } elseif (is_array($value)) {
             $value = self::injectDataInArray($value);
         }
         $prop->setValue($class, $value);
     }
     return $class;
 }
 /**
  * Get the interactor name
  *
  * @return mixed
  *
  * @throws Exception\NonInteractorException
  */
 public function getInteractorName()
 {
     if (!$this->isInteractor()) {
         throw new NonInteractorException($this->file->getFilename());
     }
     $method = $this->reflection->getMethod(self::NAME_GETTER_METHOD);
     return $method->invoke($this->reflection->newInstanceWithoutConstructor(), self::NAME_GETTER_METHOD);
 }
Beispiel #5
0
 /**
  * @param array $array
  * @return static
  */
 public static function createFromArray(array $array)
 {
     $reflection = new \ReflectionClass(static::class);
     $object = $reflection->newInstanceWithoutConstructor();
     $object->fromArray($array);
     return $object;
 }
 /**
  * @param object $entity
  *
  * @return MetaInformation
  *
  * @throws \RuntimeException if no declaration for document found in $entity
  */
 public function loadInformation($entity)
 {
     $className = $this->getClass($entity);
     if (!is_object($entity)) {
         $reflectionClass = new \ReflectionClass($className);
         if (!$reflectionClass->isInstantiable()) {
             throw new \RuntimeException(sprintf('cannot instantiate entity %s', $className));
         }
         $entity = $reflectionClass->newInstanceWithoutConstructor();
     }
     if (!$this->annotationReader->hasDocumentDeclaration($entity)) {
         throw new \RuntimeException(sprintf('no declaration for document found in entity %s', $className));
     }
     $metaInformation = new MetaInformation();
     $metaInformation->setEntity($entity);
     $metaInformation->setClassName($className);
     $metaInformation->setDocumentName($this->getDocumentName($className));
     $metaInformation->setFieldMapping($this->annotationReader->getFieldMapping($entity));
     $metaInformation->setFields($this->annotationReader->getFields($entity));
     $metaInformation->setRepository($this->annotationReader->getRepository($entity));
     $metaInformation->setIdentifier($this->annotationReader->getIdentifier($entity));
     $metaInformation->setBoost($this->annotationReader->getEntityBoost($entity));
     $metaInformation->setSynchronizationCallback($this->annotationReader->getSynchronizationCallback($entity));
     $metaInformation->setIndex($this->annotationReader->getDocumentIndex($entity));
     $metaInformation->setIsDoctrineEntity($this->annotationReader->isDoctrineEntity($entity));
     return $metaInformation;
 }
Beispiel #7
0
 /**
  * @param $array
  * @param $key
  * @param $expected
  *
  * @dataProvider keyExistsProvider
  */
 public function testKeyExists($array, $key, $expected)
 {
     $method = self::$inst->getMethod('keyExists');
     $method->setAccessible(true);
     $actual = $method->invoke(self::$inst->newInstanceWithoutConstructor(), $key, $array);
     $this->assertEquals($expected, $actual);
 }
 /**
  * This is INSANE - don't put your actions in a constructor.
  */
 function test_actions_added_in_constructor()
 {
     $class = new \ReflectionClass('\\tenup\\demo\\Real_World_Class');
     $object = $class->newInstanceWithoutConstructor();
     \WP_Mock::expectActionAdded('init', [$object, 'action_init']);
     $object->__construct();
 }
Beispiel #9
0
 /**
  * Returns the current row of a result set under HHVM
  * The problem was fetch_object creates new instance of a given class,
  * and attaches resulted key/value pairs after the class was constructed.
  *
  * @return  mixed
  */
 private function currentHHVM()
 {
     if ($this->_as_object === TRUE or is_string($this->_as_object)) {
         if ($this->_reflect_class === NULL) {
             // Create reflection class of given classname or stdClass
             $this->_reflect_class = new ReflectionClass(is_string($this->_as_object) ? $this->_as_object : 'stdClass');
         }
         // Support ORM with loaded, when the class has __set and __construct if its ORM
         if ($this->_reflect_class->hasMethod('__set') === TRUE && $this->_reflect_class->hasMethod('__construct') === TRUE) {
             // Get row as associated array
             $row = $this->_result->fetch_assoc();
             // Get new instance without constructing it
             $object = $this->_reflect_class->newInstanceWithoutConstructor();
             foreach ($row as $column => $value) {
                 // Trigger the class setter
                 $object->__set($column, $value);
             }
             // Construct the class with no parameters
             $object->__construct(NULL);
             return $object;
         } elseif (is_string($this->_as_object)) {
             // Return an object of given class name
             return $this->_result->fetch_object($this->_as_object, (array) $this->_object_params);
         } else {
             // Return an stdClass
             return $this->_result->fetch_object();
         }
     }
     // Get row as associated array
     return $this->_result->fetch_assoc();
 }
Beispiel #10
0
 protected function _checkProtection($protectionType)
 {
     // Check type
     if (!is_string($protectionType) || $protectionType != self::PROTECTION_CSRF && $protectionType != self::PROTECTION_CAPTCHA && $protectionType != self::PROTECTION_BRUTEFORCE && $protectionType != self::PROTECTION_XSS) {
         throw new \Exception('Invalid protection type : "' . $protectionType . '"');
     }
     // Check class
     if (class_exists('framework\\security\\form\\' . ucfirst($protectionType))) {
         $className = 'framework\\security\\form\\' . ucfirst($protectionType);
     } else {
         $className = $protectionType;
     }
     $class = new \ReflectionClass($className);
     if (!in_array('framework\\security\\IForm', $class->getInterfaceNames())) {
         throw new \Exception('Form protection drivers must be implement framework\\security\\IForm');
     }
     if ($class->isAbstract()) {
         throw new \Exception('Form protection drivers must be not abstract class');
     }
     if ($class->isInterface()) {
         throw new \Exception('Form protection drivers must be not interface');
     }
     $classInstance = $class->newInstanceWithoutConstructor();
     $constuctor = new \ReflectionMethod($classInstance, '__construct');
     if ($constuctor->isPrivate() || $constuctor->isProtected()) {
         throw new \Exception('Protection constructor must be public');
     }
     return $className;
 }
 /**
  * @param array $transformed
  * @param string $type
  * @return object
  * @throws \Exception
  */
 protected function revertObject($transformed, $type)
 {
     $class = new \ReflectionClass($type);
     $instance = $class->newInstanceWithoutConstructor();
     if (!is_array($transformed)) {
         throw new \Exception("Error while reverting [{$type}]. Input is not an array: " . ValuePrinter::serialize($transformed));
     }
     $reader = new PropertyReader($this->types, $class->getName());
     $properties = [];
     foreach ($reader->readState() as $property) {
         $properties[] = $property->name();
         if (array_key_exists($property->name(), $transformed)) {
             $value = new TypedValue($transformed[$property->name()], $property->type());
             $transformer = $this->transformers->toRevert($value);
             $property->set($instance, $transformer->revert($value));
         }
     }
     foreach ($transformed as $key => $value) {
         if (!in_array($key, $properties)) {
             $transformer = $this->transformers->toRevert($value);
             $instance->{$key} = $transformer->revert($value);
         }
     }
     return $instance;
 }
 protected static function _registerSingleton($singleton, $singletonNumber, $parameters)
 {
     if (self::_isLocked($singleton)) {
         throw new \Exception('Loop singleton');
     }
     self::_lockSingleton($singleton);
     $num = $singletonNumber == null ? 0 : $singletonNumber;
     // No parameters, or empty, instance directly
     if (empty($parameters)) {
         self::$_singletons[$singleton][$num] = new $singleton();
     } else {
         // create reflectionClass instance, check if is abstract class
         $ref = new \ReflectionClass($singleton);
         if ($ref->isAbstract()) {
             throw new \Exception('Your singletoned class :"' . $singleton . '" must be non-abstract class');
         }
         // Instance, and check constructor, setAccessible if is not, for invoke
         $inst = $ref->newInstanceWithoutConstructor();
         $constuctor = new \ReflectionMethod($inst, '__construct');
         if ($constuctor->isPrivate() || $constuctor->isProtected()) {
             $constuctor->setAccessible(true);
         }
         //Finally invoke (with args) and asign object into singletons list
         if (!is_array($parameters)) {
             // Single parameter
             $constuctor->invoke($inst, $parameters);
         } else {
             $constuctor->invokeArgs($inst, $parameters);
         }
         self::$_singletons[$singleton][$num] = $inst;
     }
     self::_unLockSingleton($singleton);
 }
Beispiel #13
0
 /**
  * 实例化验证规则
  * @param string $type
  * @param array $arguments
  * @throws UploadException
  * @return RuleInterface
  */
 public static function create($type, $arguments = null)
 {
     $ruleClass = '';
     switch ($type) {
         case static::RULE_SIZE:
             $ruleClass = 'SizeRule';
             break;
         case static::RULE_MIME_TYPE:
             $ruleClass = 'MimeTypeRule';
             break;
         case static::RULE_EXTENSION:
             $ruleClass = 'ExtensionRule';
             break;
         case static::RULE_SYSTEM:
             $ruleClass = 'SystemRule';
             break;
     }
     $ruleClass = "Slince\\Upload\\Rule\\{$ruleClass}";
     try {
         $ruleReflection = new \ReflectionClass($ruleClass);
         if ($ruleReflection->getConstructor() != null) {
             $instance = $ruleReflection->newInstanceArgs($arguments);
         } else {
             $instance = $ruleReflection->newInstanceWithoutConstructor();
         }
         return $instance;
     } catch (\ReflectionException $e) {
         throw new UploadException(sprintf('Rule "%s" does not support', $type));
     }
 }
Beispiel #14
0
 /**
  * Create a ghost object.
  * 
  * @param array $values
  * @return static
  */
 public static function lazyload($values)
 {
     $class = get_called_class();
     if (is_scalar($values)) {
         if (!is_a($class, Identifiable::class, true)) {
             throw new \Exception("Unable to lazy load a scalar value for {$class}: Identity property not defined");
         }
         $prop = static::getIdProperty();
         if (is_array($prop)) {
             throw new \Exception("Unable to lazy load a scalar value for {$class}: Class has a complex identity");
         }
         $values = [$prop => $values];
     }
     $reflection = new \ReflectionClass($class);
     $entity = $reflection->newInstanceWithoutConstructor();
     foreach ((array) $entity as $prop => $value) {
         if ($prop[0] === "") {
             continue;
         }
         // Ignore private and protected properties
         unset($entity->{$prop});
     }
     foreach ($values as $key => $value) {
         $entity->{$key} = $value;
     }
     $entity->ghost__ = true;
     return $entity;
 }
 /**
  * Gets the Multiton instance referenced by key.
  *
  * Automatically creates an instance if non exists. If one instance already exists, the argument list is ignored.
  *
  * @param string $key      The key of the Multiton instance to get.
  * @param mixed  $args,... The arguments for creating the Multiton instance.
  *
  * @return Multiton The Multiton instance.
  */
 public static function instance($key = 'default')
 {
     if (!is_string($key) and !empty($key)) {
         throw new \InvalidArgumentException("The \$key must be a non-empty string.");
     }
     $class = static::$T;
     if (!class_exists($class)) {
         throw new Exceptions\ClassNotFoundException("The class {$class} was not found.");
     }
     if (!array_key_exists($class, static::$instances) or !array_key_exists($key, static::$instances[$class])) {
         if (!array_key_exists($class, static::$cache)) {
             static::$cache[$class]['forgeable'] = Utils::class_implements($class, 'axelitus\\Patterns\\Interfaces\\Forgeable');
         }
         $args = array_slice(func_get_args(), 1);
         if (static::$cache[$class]['forgeable']) {
             static::$instances[$class][$key] = call_user_func_array([$class, 'forge'], $args);
         } else {
             $ref = new \ReflectionClass($class);
             $ctor = $ref->getConstructor();
             $ctor->setAccessible(true);
             static::$instances[$class][$key] = $ref->newInstanceWithoutConstructor();
             $ctor->invokeArgs(static::$instances[$class][$key], $args);
         }
     }
     return static::$instances[$class][$key];
 }
 /**
  * @param ChangeSet $changeset
  * @return bool|object
  */
 public function applyChangeSet(ChangeSet $changeset)
 {
     $now = new \DateTime();
     if ($changeset->getChangeAt() == null || $changeset->getChangeAt()->diff($now)->invert) {
         return false;
     }
     if ($changeset->getAction() == LoggableListener::ACTION_CREATE && $changeset->getObjectId() != null) {
         throw new \Exception("changeSet invalid {$changeset->getId()}  create with object id");
     }
     if ($changeset->getAction() != LoggableListener::ACTION_CREATE && $changeset->getObjectId() == null) {
         throw new \Exception("changeSet invalid {$changeset->getId()}  no objectId found but no create Action");
     }
     $data = $changeset->getData();
     if ($changeset->getObjectId() == null) {
         //create a new one
         $r = new \ReflectionClass($changeset->getObjectClass());
         $entity = $r->newInstanceWithoutConstructor();
     } else {
         //edit
         $entity = $this->_em->find($changeset->getObjectClass(), $changeset->getObjectId());
     }
     if ($changeset->getAction() == LoggableListener::ACTION_REMOVE) {
         //very rudimental remove... dont care about sitdeffects
         $this->_em->remove($entity);
         $this->_em->remove($changeset);
         $this->_em->flush();
         return true;
     }
     $wrapped = new EntityWrapper($entity, $this->_em);
     $objectMeta = $wrapped->getMetadata();
     foreach ($data as $field => $value) {
         if ($objectMeta->isSingleValuedAssociation($field)) {
             $mapping = $objectMeta->getAssociationMapping($field);
             $value = $value ? $this->_em->getReference($mapping['targetEntity'], $value) : null;
         }
         if (property_exists($changeset->getObjectClass(), $field)) {
             $wrapped->setPropertyValue($field, $value);
         }
     }
     if ($changeset->getObjectId() == null) {
         //MANY_TO_ONE create new one
         foreach ($objectMeta->getAssociationMappings() as $associationMapping) {
             if ($associationMapping['type'] != \Doctrine\ORM\Mapping\ClassMetadata::MANY_TO_ONE) {
                 continue;
             }
             $one = $objectMeta->getReflectionProperty($associationMapping['fieldName'])->getValue($entity);
             if (array_key_exists('inversedBy', $associationMapping)) {
                 $field = $associationMapping['inversedBy'];
                 $associationMeta = $this->_em->getClassMetadata($associationMapping['targetEntity']);
                 $associationMeta->getReflectionProperty($field)->getValue($one)->add($entity);
             }
         }
     }
     $object = $wrapped->getObject();
     $object->removeScheduledChangeDate();
     $this->_em->persist($object);
     $this->_em->remove($changeset);
     $this->_em->flush();
     return $object;
 }
 /**
  * Get document fields
  *
  * @param Document $document Document
  * @return array
  */
 private function getFormFields(Document $document)
 {
     $reflection = new \ReflectionClass($document->getClass());
     if ($reflection->implementsInterface('Graviton\\I18nBundle\\Document\\TranslatableDocumentInterface')) {
         $instance = $reflection->newInstanceWithoutConstructor();
         $translatableFields = $instance->getTranslatableFields();
     } else {
         $translatableFields = [];
     }
     $result = [];
     foreach ($document->getFields() as $field) {
         if ($field instanceof Field) {
             list($type, $options) = $this->resolveFieldParams($translatableFields, $field->getFieldName(), $field->getType());
             $result[] = [$field->getFormName(), $type, array_replace(['property_path' => $field->getFieldName()], $options)];
         } elseif ($field instanceof ArrayField) {
             list($type, $options) = $this->resolveFieldParams($translatableFields, $field->getFieldName(), $field->getItemType());
             $result[] = [$field->getFormName(), 'collection', ['property_path' => $field->getFieldName(), 'type' => $type, 'options' => $options]];
         } elseif ($field instanceof EmbedOne) {
             $result[] = [$field->getFormName(), 'form', ['property_path' => $field->getFieldName(), 'data_class' => $field->getDocument()->getClass(), 'required' => $field->isRequired()]];
         } elseif ($field instanceof EmbedMany) {
             $result[] = [$field->getFormName(), 'collection', ['property_path' => $field->getFieldName(), 'type' => 'form', 'options' => ['data_class' => $field->getDocument()->getClass()]]];
         }
     }
     return $result;
 }
Beispiel #18
0
 public static function instanceCell($cellUri)
 {
     if (is_array($cellUri)) {
         return self::_cell($cellUri);
     }
     if (isset(self::$_aliases[$cellUri])) {
         $cellUri = self::$_aliases[$cellUri];
     }
     $className = str_replace("/", "\\", $cellUri);
     if (class_exists($className)) {
         $reflection = new \ReflectionClass($className);
         $constructor = $reflection->getConstructor();
         if ($constructor) {
             $cell = $reflection->newInstanceArgs();
         } else {
             $cell = $reflection->newInstanceWithoutConstructor();
         }
         $fileConfig = str_replace('.php', '.yml', $reflection->getFileName());
         if (file_exists($fileConfig)) {
             $data = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($fileConfig));
             $cell->setData($data);
         }
     } else {
         $fileConfig = stream_resolve_include_path(str_replace("\\", "/", trim($cellUri, "/")) . '.yml');
         if ($fileConfig !== FALSE) {
             $data = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($fileConfig));
             $cell = self::_cell($data);
         } else {
             $cell = new \Nucleus\Cell();
         }
     }
     $cell->setCellUri($cellUri);
     return $cell;
 }
 /**
  * (@inheritdoc)
  */
 public function deserialize($type, array $data)
 {
     $reflectionClass = new \ReflectionClass($type);
     $object = $reflectionClass->newInstanceWithoutConstructor();
     $object = $this->setReflectionPropertiesFromData($data, $reflectionClass, $object);
     return $object;
 }
 /**
  * @test
  */
 public function I_can_easily_find_out_if_is_melee()
 {
     $reflection = new \ReflectionClass(self::getSutClass());
     /** @var RangedWeaponCode $sut */
     $sut = $reflection->newInstanceWithoutConstructor();
     self::assertFalse($sut->isMelee());
 }
 /**
  * Creates a new instance of the cacheable object or returns an already
  * cached one
  *
  * The parameters of this method are derived from the constructor of the
  * cacheable class. Additionally, the following parameters are dynamically
  * added:
  *
  * @param bool $fetch If <var>true</var> the object’s <var>fetch()</var>
  *        method will be called
  * @param bool $bypassCache If <var>true</var> the cache will not be hit
  * @return mixed A new object or a matching cached one
  */
 public static function create()
 {
     $args = func_get_args();
     $className = empty(self::$className) ? get_class() : self::$className;
     $class = new \ReflectionClass($className);
     $constructor = $class->getConstructor();
     $arity = $constructor->getNumberOfParameters();
     if (sizeof($args) < $arity) {
         array_fill(0, $arity, null);
     }
     $bypassCache = sizeof($args) > $arity + 1 ? array_pop($args) : false;
     $fetch = sizeof($args) > $arity ? array_pop($args) : true;
     $object = $class->newInstanceWithoutConstructor();
     $constructor->setAccessible(true);
     $constructor->invokeArgs($object, $args);
     $cachedObject = $object->cachedInstance();
     if ($cachedObject != null && !$bypassCache) {
         $object = $cachedObject;
     }
     if ($fetch && ($bypassCache || !$object->isFetched())) {
         $object->fetch();
         $object->cache();
     }
     return $object;
 }
Beispiel #22
0
 /**
  * @param string $base_class A parent class or interface.
  * @param bool $callback Optionally, don't call the register callback to construct the results array.
  * @param bool $use_constructor Optionally, get a class-instance via constructor - potentially UNSAFE!
  * @return array Array of result classes, optionally keyed.
  */
 public function match($base_class, $callback = true, $use_constructor = false)
 {
     $results = array();
     //foreach ($this as $class) {
     foreach ($this->classes as $class) {
         if (is_subclass_of($class, $base_class)) {
             if ($callback) {
                 try {
                     $obj = null;
                     if ($use_constructor) {
                         $obj = new $class();
                     } else {
                         $reflect = new \ReflectionClass($class);
                         // Ignore abstract classes.
                         if ($reflect->isInstantiable()) {
                             $obj = $reflect->newInstanceWithoutConstructor();
                         }
                     }
                     if ($obj) {
                         $obj->{self::REGISTER_FN}($results);
                     }
                 } catch (\ReflectionException $e) {
                     $this->debug('Warning! (RF) ' . $e->getMessage());
                 } catch (\Exception $e) {
                     $this->debug('Warning! ' . $e->getMessage());
                 }
                 //Was: $results[ $class::{ $callback }() ] = $class;
             } else {
                 $results[] = $class;
             }
         }
     }
     return $results;
 }
Beispiel #23
0
 /**
  * 重载callback()
  * 将微信服务器请求的数据进行解析
  * 并回调控制器的接口方法
  */
 public function callback()
 {
     $req = parent::callback();
     //$this->log($req);
     empty($_GET) && die;
     // 必须有附带参数
     extract($_GET);
     if ($this->sha1_sign($req->Encrypt, $timestamp, $nonce, $msg_signature)) {
         $reply = '';
         $ES = \es\core\Controller\ControllerAbstract::getInstance();
         switch (strtolower($req->MsgType)) {
             case 'text':
                 $reply = $ES->_keywords($req->Content);
                 break;
             case 'event':
                 $reply = $ES->_events($req);
                 break;
         }
         empty($reply) && die;
         list($method, $args) = $reply;
         $args = ['to' => $req->FromUserName, 'from' => $req->ToUserName] + $args;
         $reflector = new \ReflectionClass('\\es\\libraries\\Wechat\\ReplyStatic');
         $rMethod = $reflector->getMethod($method);
         $xml = $rMethod->invokeArgs($reflector->newInstanceWithoutConstructor(), $args);
         //$this->log($xml); // 未加密的消息体
         die($xml);
         $xml = $this->crypt_generate($xml);
         $signature = $this->set_sha1_sign($xml, $timestamp, $nonce);
         $xml = ReplyStatic::crypt_xml($xml, $signature, $timestamp, $nonce);
         //$this->log($xml); // 加密后的消息体
         echo $xml;
         exit;
     }
     exit;
 }
 /**
  * {@inheritdoc}
  */
 public function getCommandFrom($className)
 {
     if (class_exists($className)) {
         $accessor = PropertyAccess::createPropertyAccessor();
         $reflector = new \ReflectionClass($className);
         $instance = $reflector->newInstanceWithoutConstructor();
         foreach ($reflector->getProperties() as $property) {
             if ($instance instanceof ConsoleCommandInterface && $property->getName() == 'io') {
                 continue;
             }
             if (!$this->format->hasArgument($property->getName()) && !$this->format->hasOption($property->getName())) {
                 throw new \InvalidArgumentException(sprintf("There is not '%s' argument defined in the %s command", $property->getName(), $className));
             }
             $value = null;
             if ($this->format->hasArgument($property->getName())) {
                 $value = $this->args->getArgument($property->getName());
             } elseif ($this->format->hasOption($property->getName())) {
                 $value = $this->args->getOption($property->getName());
             }
             $accessor->setValue($instance, $property->getName(), $value);
         }
         return $instance;
     }
     return;
 }
Beispiel #25
0
 private function createInstance(Scope $scope)
 {
     if (!$this->arguments) {
         return $this->class->newInstanceWithoutConstructor();
     }
     return $this->class->newInstanceArgs($this->newArguments($scope));
 }
 /**
  * {@inheritdoc}
  */
 public function convert($value)
 {
     $ref = new \ReflectionClass($this->class);
     $data = $ref->newInstanceWithoutConstructor();
     $this->propertyAccessor->setValue($data, $this->label, $value);
     return (object) $data;
 }
Beispiel #27
0
 /**
  * 重载callback()
  * 将微信服务器请求的数据进行解析
  * 并回调控制器的接口方法
  */
 public function callback()
 {
     $postXML = parent::callback();
     empty($_GET) && die;
     // 必须有附带参数
     extract($_GET);
     if ($this->sha1_sign($postXML->Encrypt, $timest, $nonce, $msg_signature)) {
         $req = $this->crypt_extract(parent::callback());
         $reply = '';
         switch (strtolower($req->MsgType)) {
             case 'text':
                 $reply = ES_controller::get_instance()->_keywords($req->Content);
                 break;
             case 'event':
                 $reply = ES_controller::get_instance()->_events($req);
                 break;
         }
         empty($reply) && die;
         list($method, $args) = $reply;
         $args = array('to' => $req->FromUserName, 'from' => $req->ToUserName) + $args;
         $reflector = new ReflectionClass('Reply');
         $rMethod = $reflector->getMethod($method);
         $xml = $rMethod->invokeArgs($reflector->newInstanceWithoutConstructor(), $args);
         // log_msg($xml); // 未加密的消息体
         $xml = $this->crypt_generate($xml);
         $signature = $this->set_sha1_sign($xml, $timestamp, $nonce);
         $xml = Reply::crypt_xml($xml, $signature, $timestamp, $nonce);
         // log_msg($xml); // 加密后的消息体
         echo $xml;
         exit;
     }
     exit;
 }
Beispiel #28
0
 /**
  * @param $string
  * @return static
  */
 public static function createFromJson($string)
 {
     $reflection = new \ReflectionClass(static::class);
     $object = $reflection->newInstanceWithoutConstructor();
     $object->fromJson($string);
     return $object;
 }
Beispiel #29
0
 /**
  * {@inheritdoc}
  */
 public function get($name)
 {
     if ($this->has($name)) {
         return $this->definitions[$name];
     }
     if (!class_exists($name) && !interface_exists($name)) {
         return;
     }
     $autowiring = function ($name) {
         $class = new \ReflectionClass($name);
         $constructor = $class->getConstructor();
         if ($constructor && $constructor->isPublic()) {
             $parameters = $this->getParametersDefinition($constructor);
             if ($constructor->getNumberOfRequiredParameters() !== count($parameters)) {
                 return;
             }
             $object = $class->newInstanceArgs($parameters);
             $this->set($name, $object);
             return $object;
         }
         $object = $class->newInstanceWithoutConstructor();
         $this->set($name, $object);
         return $object;
     };
     return $autowiring($name);
 }
Beispiel #30
0
 /**
  * Creates a data object from an array of data.
  *
  * @param array $data The array containing object data.
  *
  * @return self A new object instance.
  */
 public static function fromData(array $data)
 {
     $reflection = new \ReflectionClass(static::class);
     $instance = $reflection->newInstanceWithoutConstructor();
     $instance->data = $data;
     $instance->jsonUnserialize($data);
     return $instance;
 }