public function testtoObject()
 {
     $sUT = new Property();
     $sUT->addProperty('test', new Property());
     $sUT->addItem('test', new Item());
     $this->assertInstanceOf('stdClass', $sUT->toObject());
 }
 /**
  * @param mixed $property
  * @param string $name
  * @return \JSONSchema\Structure\Property
  */
 private function determineProperty($property, $name, Schema $schema)
 {
     $baseUrl = $schema->getConfig()->getBaseUrl();
     $additionalProperties = $schema->getConfig()->hasAdditionalProperties();
     $type = PropertyTypeMapper::map($property);
     $prop = new Property();
     $prop->setType($type)->setName($name)->setAdditionalProperties($additionalProperties);
     if ($baseUrl !== null) {
         $prop->setId($baseUrl . '/' . $name);
     }
     return $this->determineChildProperty($type, $property, $prop, $schema);
 }
 /**
  * due to the fact that determining property will be so different between 
  * parser types we should probably just define this function here
  * In a JSON string it will be very simple.
  *   enter a string
  *   see what the string looks like
  *     check the maps of types 
  *     see if it fits some semantics  
  * 
  * @param object $property
  * @return Property
  */
 protected function determineProperty($property, $name)
 {
     $baseUrl = $this->configKeyExists('baseUrl') ? $this->getConfigSetting('baseUrl') : null;
     $requiredDefault = $this->configKeyExists('requiredDefault') ? $this->getConfigSetting('requiredDefault') : false;
     $type = StringMapper::map($property);
     if ($type == StringMapper::ARRAY_TYPE) {
         return $this->determineItem($property, $name);
     }
     $prop = new Property();
     $prop->setType($type)->setName($name)->setKey($name)->setRequired($requiredDefault);
     if ($baseUrl) {
         $prop->setId($baseUrl . '/' . $name);
     }
     // since this is an object get the properties of the sub objects
     if ($type == StringMapper::ARRAY_TYPE) {
         $prop->addItem($name, $this->determineItem($property, $name));
     } elseif ($type == StringMapper::OBJECT_TYPE) {
         foreach ($property as $key => $newProperty) {
             $prop->addProperty($key, $this->determineProperty($newProperty, $key));
         }
     }
     return $prop;
 }
예제 #4
0
 /**
  * @param string $key
  * @param Property $value
  * @param boolean $overwrite
  * @return $this
  * @throws Exceptions\OverwriteKeyException
  */
 public function addProperty($key, Property $value, $overwrite = true)
 {
     if (!empty($this->properties[$key]) && !$overwrite) {
         throw new Exceptions\OverwriteKeyException();
     }
     $value->setId($this->getId() . '/' . $key);
     $this->properties[$key] = $value;
     return $this;
 }
예제 #5
0
 /**
  * Because the Item structure is of Array type we
  * need to pass in the parent ID differently
  * For now we can just hard code an :id field but later
  * it needs to have keys for various reasons
  * 
  * @see JSONSchema\Structure.Property::loadFields()
  */
 public function loadFields($parentId = null)
 {
     $arrParentId = $parentId ? $parentId . '/:id' : null;
     return parent::loadFields($arrParentId);
 }