コード例 #1
0
ファイル: Writer.php プロジェクト: tiagobutzke/json2dto
 /**
  * Write classes
  */
 public function write()
 {
     foreach ($this->objects as $className => $classContent) {
         $className = Format::className($className);
         Message::write(sprintf(Message::$classTemplate, $className));
         $fileName = "{$this->directory}/{$className}.php";
         if (file_exists($fileName)) {
             unlink($fileName);
         }
         $file = new \SplFileObject($fileName, 'w');
         $file->fwrite(html_entity_decode($classContent));
     }
 }
コード例 #2
0
ファイル: Loader.php プロジェクト: tiagobutzke/json2dto
 /**
  * Trigger a json node
  *
  * @param \stdClass $node
  * @param string $object
  */
 protected function loadNode(\stdClass $node, $object = null)
 {
     $properties = get_object_vars($node);
     foreach ($properties as $property => $value) {
         if (is_object($value)) {
             $this->objects[$object]['arguments'] .= sprintf(Argument::getTemplate(), Format::className($property), Format::paramName($property));
             $this->objects[$object]['methods'] .= sprintf(GetMethod::getTemplate(), Format::methodName($property), Format::className($property), Format::className($property));
             $this->objects[$object]['methods'] .= sprintf(SetTypedMethod::getTemplate(), Format::methodName($property), Format::className($property));
             $this->objects[$object]['use'] .= sprintf(UseNamespace::getTemplate(), $this->options['--namespace'] . '\\' . Format::className($property));
             $this->queue[$property] = $value;
         }
         if (is_array($value)) {
             $this->objects[$object]['arguments'] .= sprintf(ArgumentCollection::getTemplate(), Format::className($property), Format::paramName($property));
             $this->objects[$object]['methods'] .= sprintf(GetMethod::getTemplate(), Format::methodName($property), Format::className($property), Format::className($property));
             $this->objects[$object]['methods'] .= sprintf(AddMethod::getTemplate(), Format::methodName($property), Format::className($property));
             $this->objects[$object]['use'] .= sprintf(UseNamespace::getTemplate(), $this->options['--namespace'] . '\\' . Format::className($property));
             $this->queue[$property] = $value[0];
         }
         if ($this->isInternalType($value)) {
             $this->objects[$object]['arguments'] .= sprintf(Argument::getTemplate(), strtolower(gettype($property)), Format::paramName($property));
             $this->objects[$object]['methods'] .= sprintf(GetMethod::getTemplate(), Format::methodName($property), strtolower(gettype($value)), Format::className($property));
             $this->objects[$object]['methods'] .= sprintf(SetMethod::getTemplate(), Format::methodName($property), Format::className($property), strtolower(gettype($value)));
         }
     }
     unset($this->queue[$object]);
 }