protected function setUp()
 {
     $factory = new Type\FactoryType();
     $factory->add(new Type\Null(), 'type_null');
     $managerInspectorMock = m::mock('Ladybug\\Inspector\\InspectorManager');
     $managerInspectorMock->shouldReceive('get')->andReturn(null);
     $metadataResolverMock = m::mock('Ladybug\\Metadata\\MetadataResolver');
     $metadataResolverMock->shouldReceive('has')->andReturn(false);
     $this->type = new Type\Object\Container(8, $factory, $managerInspectorMock, $metadataResolverMock);
 }
Example #2
0
 public function testFactoryForUnknownResourceValues()
 {
     $var = fopen(__DIR__ . '/../../../files/test.txt', 'rb');
     fclose($var);
     // Turns resource into type "Unknown"
     $type = $this->factory->factory($var);
     $this->assertInstanceOf('Ladybug\\Type\\Resource', $type);
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function load($var, $level = 1)
 {
     if (!is_array($var)) {
         throw new InvalidVariableTypeException();
     }
     $this->length = count($var);
     $this->level = $level;
     if ($this->level < $this->maxLevel) {
         foreach ($var as $k => $v) {
             $value = $this->factory->factory($v, $this->level + 1);
             $arrayItem = new Item($k, $value);
             $this->add($arrayItem);
         }
     } else {
         $this->terminal = true;
     }
 }
 protected function loadData($var, \ReflectionClass $reflectedObject)
 {
     $inspector = $this->inspectorManager->get($this->variableWrapper);
     if ($inspector instanceof InspectorInterface) {
         $inspector->setLevel($this->level + 1);
         $this->objectCustomData = $inspector->get($this->variableWrapper);
     }
     // properties
     $data = (array) $var;
     // unmangle private and protected
     $this->objectProperties = array();
     foreach ($data as $key => $item) {
         $propertyOwner = null;
         if ("" === $key[0]) {
             // private or protected
             list($owner, $name) = explode("", substr($key, 1), 2);
             if ("*" === $owner) {
                 // protected
                 $propertyName = $name;
                 $propertyVisibility = Object\VisibilityInterface::VISIBILITY_PROTECTED;
                 $this->protectedPropertiesNumber++;
             } else {
                 // private
                 $propertyName = $name;
                 $propertyVisibility = Object\VisibilityInterface::VISIBILITY_PRIVATE;
                 $propertyOwner = $owner === $this->className ? null : $owner;
                 $this->privatePropertiesNumber++;
             }
         } else {
             // public
             $propertyName = $key;
             $propertyVisibility = Object\VisibilityInterface::VISIBILITY_PUBLIC;
             $this->publicPropertiesNumber++;
         }
         $value = $this->factory->factory($item, $this->level + 1);
         $objectProperty = new Object\Property();
         $objectProperty->setName($propertyName);
         $objectProperty->setValue($value);
         $objectProperty->setVisibility($propertyVisibility);
         $objectProperty->setOwner($propertyOwner);
         $this->objectProperties[] = $objectProperty;
     }
 }
Example #5
0
 protected function loadData($var, \ReflectionClass $reflectedObject)
 {
     $inspector = $this->inspectorManager->get($this->variableWrapper);
     if ($inspector instanceof InspectorInterface) {
         $inspector->setLevel($this->level + 1);
         $this->objectCustomData = $inspector->get($this->variableWrapper);
     }
     $this->objectProperties = array();
     $properties = $reflectedObject->getProperties();
     foreach ($properties as $key => $item) {
         $item->setAccessible(true);
         $value = $this->factory->factory($item->getValue($var), $this->level + 1);
         $objectProperty = new Property();
         $objectProperty->setName($item->getName());
         $objectProperty->setValue($value);
         $objectProperty->setStatic($item->isStatic());
         if ($item->isPrivate()) {
             $objectProperty->setVisibility(VisibilityInterface::VISIBILITY_PRIVATE);
             $this->privatePropertiesNumber++;
         } elseif ($item->isProtected()) {
             $objectProperty->setVisibility(VisibilityInterface::VISIBILITY_PROTECTED);
             $this->protectedPropertiesNumber++;
         } else {
             $objectProperty->setVisibility(VisibilityInterface::VISIBILITY_PUBLIC);
             $this->publicPropertiesNumber++;
         }
         //$objectProperty->setVisibility($propertyVisibility);
         $objectProperty->setOwner($item->getDeclaringClass()->getName());
         $this->objectProperties[] = $objectProperty;
     }
     // order properties
     usort($this->objectProperties, function (Property $propertyA, Property $propertyB) {
         $orderValueA = (int) (!$propertyA->getStatic()) . $propertyA->getVisibility() . $propertyA->getName();
         $orderValueB = (int) (!$propertyB->getStatic()) . $propertyB->getVisibility() . $propertyB->getName();
         return strcasecmp($orderValueA, $orderValueB);
     });
 }