public function testtoObject() { $sUT = new Item(); $sUT->addProperty('test', new Property()); $sUT->addRequired('test'); $this->assertInstanceOf('stdClass', $sUT->toObject()); }
/** * Similar to determineProperty but with a variation * Notice that in items list there can be a collection of items - no keys here * the total items represent a full definition * we are taking the collection of items * we should take the cross section of the items and figure out base items * * @param array $items * @param string $name * @return Property */ protected function determineItem($items, $name) { $baseUrl = $this->configKeyExists('baseUrl') ? $this->getConfigSetting('baseUrl') : null; $requiredDefault = $this->configKeyExists('requiredDefault') ? $this->getConfigSetting('requiredDefault') : false; $type = StringMapper::map($items); $retItem = new Item(); $retItem->setType($type)->setName($name)->setKey($name)->setRequired($requiredDefault); if ($baseUrl) { $retItem->setId($baseUrl . '/' . $name); } // since we stacked the groups of items into their major elements // add ALL of them to the item listings if ($type == StringMapper::ARRAY_TYPE) { // loop through and get a list of the definitions // stack them together to find the greatest common foreach ($items as $key => $val) { // a collapse of each type $this->stackItemFields($name, $val); } // now that we have our commons lets add them to the items foreach ($this->itemFields[$name] as $key => $newItem) { $retItem->addItem($key, $this->determineItem($newItem, $key), true); } } elseif ($type == StringMapper::OBJECT_TYPE) { $retItem->addItem($key, $this->determineProperty($items, $key)); } return $retItem; }
/** * @param mixed $property * @param Item $item * @return Item */ private function determineChildItem($property, Item $item, Schema $schema) { if (PropertyTypeMapper::map($property) === PropertyTypeMapper::OBJECT_TYPE) { foreach (get_object_vars($property) as $key => $itemzz) { $item->addProperty($key, $this->determineProperty($itemzz, $key, $schema), $schema->getConfig()->isRequiredDefault()); } } return $item; }