Ejemplo n.º 1
0
 /**
  * Builds a model based on it's mapping.
  * Does so recursively if needed
  *
  * @param string            $classPath
  * @param \SimpleXMLElement $element
  *
  * @throws \InvalidArgumentException
  *
  * @return mixed
  */
 protected function visitModel($classPath, $element)
 {
     // Check if we have a valid $classPath and Model (must extend Model)
     if (class_exists($classPath)) {
         $model = new $classPath();
         if ($model instanceof ModelInterface) {
             // get the mapping
             $mapping = $model->getMapping();
             // loop over the mapping
             // for every mapped field, get a value
             foreach ($mapping['attributes'] as $variable => $opts) {
                 // Call the Model setter and set the value
                 call_user_func([$model, MethodHelper::getSetter($variable)], $this->visitElement($element->{$variable}, $opts));
             }
             return $model;
         } else {
             throw new \InvalidArgumentException(sprintf('"%s" does not implement Recurly\\Model\\ModelInterface', $classPath));
         }
     } else {
         throw new \InvalidArgumentException(sprintf('"%s" is not a class', $classPath));
     }
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider setters
  */
 public function testGetSetter($expected, $variable)
 {
     $this->assertEquals($expected, MethodHelper::getSetter($variable));
 }