コード例 #1
0
 public function testGetSetPropertyMatcher()
 {
     $context = new Array2ObjectContext();
     $matcher = new CamelizeMatcher();
     $context->setMatcher($matcher);
     static::assertEquals($matcher, $context->getMatcher());
 }
コード例 #2
0
 /**
  * @param object $object object instance to populate
  * @param array  $data   array of data to apply
  *
  * @throws \InvalidArgumentException
  */
 public function populate($object, array $data)
 {
     if (!is_object($object)) {
         throw new \InvalidArgumentException('The first param should be a object.');
     }
     if ($object instanceof Array2ObjectInterface) {
         $object->__populate($data);
     } else {
         $reflClass = new \ReflectionClass($object);
         foreach (Utils::getClassProperties($reflClass) as $property) {
             foreach ($data as $key => $value) {
                 if ($this->context->getMatcher()->match($property, $key) && $this->context->getWriter()->isWritable($object, $property->getName())) {
                     $types = Utils::getPropertyTypes($property);
                     $value = $this->parseValue($value, $types, $property, $object);
                     $this->context->getWriter()->setValue($object, $property->getName(), $value);
                 }
             }
         }
     }
 }