示例#1
0
 /**
  * Imports an array representation into an actual PHP object
  * 
  * @param array $something
  *   The object representation to import
  *   
  * @return object
  *   The PHP object
  */
 private function importObject($something)
 {
     if (isset($something['__id__'])) {
         if (isset($this->state[$something['__id__']])) {
             return $this->state[$something['__id__']];
         }
     }
     $entry = $this->manifest->getEntryByAlias($something['__class__']);
     $className = $entry->class;
     if (method_exists($className, '__set_state')) {
         $object = call_user_func(array($className, '__set_state'), $something);
     } else {
         $object = new $className();
     }
     if (isset($something['__id__'])) {
         $this->state[$something['__id__']] = $object;
     }
     $ref = new \ReflectionClass(get_class($object));
     foreach ($entry->properties as $name => $propertyDefinition) {
         if (!isset($something[$name])) {
             continue;
         }
         if ($propertyDefinition->isReadOnly) {
             continue;
         }
         $property = $ref->getProperty($name);
         $property->setAccessible(true);
         if ($propertyDefinition->isStatic) {
             $property->setValue(new \stdClass(), $something[$name]);
         } else {
             $property->setValue($object, $something[$name]);
         }
     }
     return $object;
 }
示例#2
0
 /**
  * Calls a method on an object based on the contents of the payload
  * 
  * @param array $payload
  *   The data received from the HTTP request
  *   
  * @throws \RuntimeException
  *   If the specified object is not found
  *   
  * @return mixed
  *   The result of the method call in question
  */
 public function callMethod($alias, $method, $arguments, $context = null)
 {
     $entry = $this->manifest->getEntryByAlias($alias);
     $method = $entry->getMethodByName($method);
     $arguments = $this->state->import($arguments);
     if ($method->isStatic) {
         $callable = array($entry->class, $method->name);
     } else {
         if (!is_object($context)) {
             throw new \RuntimeException('Object not found');
         }
         $callable = array($context, $method->name);
     }
     return call_user_func_array($callable, $arguments);
 }