コード例 #1
0
ファイル: DataShaper.php プロジェクト: pkdevboxy/php-utils
 /**
  * Reshapes the data given from $this->with()
  *
  * @param int|string $shape   The desired shape
  * @param array      $options Any options to pass to the shaper
  *
  * @return mixed
  * @throws \DreamFactory\Enterprise\Common\Exceptions\NotImplementedException
  */
 public function shape($shape = null, $options = [])
 {
     $_shape = DataShapes::resolve($shape ?: $this->shape);
     switch ($_shape) {
         case DataShapes::RAW:
             return $this->data;
         case DataShapes::MEDIAWIKI_TABLE:
             return MediaWikiTableShape::transform($this->data, $options);
         case DataShapes::JSON:
             return JsonShape::transform($this->data, $options);
         case DataShapes::XML:
             return XmlShape::transform($this->data, $options);
     }
     throw new NotImplementedException('The requested shape "' . $this->shape . '" is not valid.');
 }
コード例 #2
0
 /**
  * Using the --format option (if specified) format an array of data for output in that format
  *
  * @param array       $array
  * @param bool        $pretty
  * @param string|null $rootNode Enclose transformed data inside a $rootNode
  * @param string      $type     Inner node name prefix. Defaults to 'item'. Used only for XML
  *
  * @return string
  */
 protected function formatArray(array $array, $pretty = true, $rootNode = 'root', $type = 'item')
 {
     switch ($this->format) {
         case 'json':
             return Json::encode($array, ($pretty ? JSON_PRETTY_PRINT : 0) | JSON_UNESCAPED_SLASHES);
         case 'xml':
             return XmlShape::transform($array, ['root' => $rootNode, 'item-type' => $type, 'ugly' => !$pretty]);
     }
     //  Default is to use print_r format
     return print_r($array, true);
 }