当前位置: 首页>>代码示例>>PHP>>正文


PHP xPDO::toJSON方法代码示例

本文整理汇总了PHP中xPDO::toJSON方法的典型用法代码示例。如果您正苦于以下问题:PHP xPDO::toJSON方法的具体用法?PHP xPDO::toJSON怎么用?PHP xPDO::toJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xPDO的用法示例。


在下文中一共展示了xPDO::toJSON方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getProperties

 /**
  * Get the properties on this source
  * @param boolean $parsed
  * @return array
  */
 public function getProperties($parsed = false)
 {
     $properties = $this->get('properties');
     $defaultProperties = $this->getDefaultProperties();
     if (!empty($properties) && is_array($properties)) {
         foreach ($properties as &$property) {
             $property['overridden'] = 0;
             if (array_key_exists($property['name'], $defaultProperties)) {
                 if ($defaultProperties[$property['name']]['value'] != $property['value']) {
                     $property['overridden'] = 1;
                 }
             } else {
                 $property['overridden'] = 2;
             }
         }
         $properties = array_merge($defaultProperties, $properties);
     } else {
         $properties = $defaultProperties;
     }
     /** @var array $results Allow manipulation of media source properties via event */
     $results = $this->xpdo->invokeEvent('OnMediaSourceGetProperties', array('properties' => $this->xpdo->toJSON($properties)));
     if (!empty($results)) {
         foreach ($results as $result) {
             $result = is_array($result) ? $result : $this->xpdo->fromJSON($result);
             $properties = array_merge($properties, $result);
         }
     }
     if ($parsed) {
         $properties = $this->parseProperties($properties);
     }
     return $this->prepareProperties($properties);
 }
开发者ID:WhisperingTree,项目名称:blog,代码行数:37,代码来源:modmediasource.class.php

示例2: _setRaw

 /**
  * Set a raw value on a field converted to the appropriate type.
  *
  * @access protected
  * @param string $key The key identifying the field to set.
  * @param mixed $val The value to set.
  * @return boolean Returns true if the value was set, false otherwise.
  */
 protected function _setRaw($key, $val)
 {
     $set = false;
     if ($val === null) {
         $this->_fields[$key] = null;
         $set = true;
     } else {
         $phptype = $this->_getPHPType($key);
         $dbtype = $this->_getDataType($key);
         switch ($phptype) {
             case 'int':
             case 'integer':
             case 'boolean':
                 $this->_fields[$key] = (int) $val;
                 $set = true;
                 break;
             case 'float':
                 $this->_fields[$key] = (double) $val;
                 $set = true;
                 break;
             case 'array':
                 if (is_array($val)) {
                     $this->_fields[$key] = serialize($val);
                     $set = true;
                 } elseif (is_string($val)) {
                     $this->_fields[$key] = $val;
                     $set = true;
                 } elseif (is_object($val) && $val instanceof xPDOObject) {
                     $this->_fields[$key] = serialize($val->toArray());
                     $set = true;
                 }
                 break;
             case 'json':
                 if (!is_string($val)) {
                     $v = $val;
                     if (is_array($v)) {
                         $this->_fields[$key] = $this->xpdo->toJSON($v);
                         $set = true;
                     } elseif (is_object($v) && $v instanceof xPDOObject) {
                         $this->_fields[$key] = $this->xpdo->toJSON($v->toArray());
                         $set = true;
                     }
                 } else {
                     $this->_fields[$key] = $val;
                     $set = true;
                 }
                 break;
             case 'date':
             case 'datetime':
             case 'timestamp':
                 if (preg_match('/int/i', $dbtype)) {
                     $this->_fields[$key] = (int) $val;
                     $set = true;
                     break;
                 }
             default:
                 $this->_fields[$key] = $val;
                 $set = true;
         }
     }
     if ($set) {
         $this->setDirty($key);
     }
     return $set;
 }
开发者ID:e-gob,项目名称:apps.gob.cl,代码行数:73,代码来源:xpdoobject.class.php

示例3: _compilePayload

 /**
  * Compile necessary resources in preparation for storing the vehicle.
  *
  * @access protected
  * @param xPDOTransport &$transport A reference to the transport the vehicle is being stored in.
  */
 protected function _compilePayload(&$transport)
 {
     $cacheManager = $transport->xpdo->getCacheManager();
     if ($cacheManager) {
         if (isset($this->payload['resolve']) && is_array($this->payload['resolve'])) {
             foreach ($this->payload['resolve'] as $rKey => $r) {
                 $type = $r['type'];
                 $body = array();
                 switch ($type) {
                     case 'file':
                         $fileSource = $r['source'];
                         $body['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '/' . $rKey . '/';
                         $fileTarget = $transport->path . $body['source'];
                         $body['target'] = $r['target'];
                         $fileName = isset($r['name']) ? $r['name'] : basename($fileSource);
                         $body['name'] = $fileName;
                         if (!is_writable($fileTarget)) {
                             $cacheManager->writeTree($fileTarget);
                         }
                         if (file_exists($fileSource) && is_writable($fileTarget)) {
                             $copied = false;
                             if (is_dir($fileSource)) {
                                 $copied = $cacheManager->copyTree($fileSource, $fileTarget . $fileName);
                             } elseif (is_file($fileSource)) {
                                 $copied = $cacheManager->copyFile($fileSource, $fileTarget . $fileName);
                             }
                             if (!$copied) {
                                 $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not copy file from {$fileSource} to {$fileTarget}{$fileName}");
                                 $body = null;
                             }
                         } else {
                             $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Source file {$fileSource} is missing or {$fileTarget} is not writable");
                             $body = null;
                         }
                         break;
                     case 'php':
                         $fileSource = $r['source'];
                         $scriptName = basename($fileSource, '.php');
                         $body['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '.' . $scriptName . '.resolver';
                         $fileTarget = $transport->path . $body['source'];
                         $body['name'] = $scriptName;
                         $body = array_merge($r, $body);
                         if (!$cacheManager->copyFile($fileSource, $fileTarget)) {
                             $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Source file {$fileSource} is missing or {$fileTarget} could not be written");
                         }
                         break;
                     default:
                         $transport->xpdo->log(xPDO::LOG_LEVEL_WARN, "xPDOVehicle does not support resolvers of type {$type}.");
                         break;
                 }
                 if ($body) {
                     $this->payload['resolve'][$rKey] = array('type' => $type, 'body' => xPDO::toJSON($body));
                 } else {
                     $this->payload['resolve'][$rKey] = null;
                 }
             }
         }
         if (isset($this->payload['validate']) && is_array($this->payload['validate'])) {
             foreach ($this->payload['validate'] as $vKey => $v) {
                 $type = $r['type'];
                 $body = array();
                 switch ($type) {
                     case 'php':
                         $fileSource = $r['source'];
                         $scriptName = basename($fileSource, '.php');
                         $body['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '.' . $scriptName . '.validator';
                         $fileTarget = $transport->path . $body['source'];
                         $body['name'] = $scriptName;
                         $body = array_merge($r, $body);
                         if (!$cacheManager->copyFile($fileSource, $fileTarget)) {
                             $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Source file {$fileSource} is missing or {$fileTarget} could not be written");
                         }
                         break;
                     default:
                         $transport->xpdo->log(xPDO::LOG_LEVEL_WARN, "xPDOVehicle does not support validators of type {$type}.");
                         break;
                 }
                 if ($body) {
                     $this->payload['validate'][$vKey] = array('type' => $type, 'body' => xPDO::toJSON($body));
                 } else {
                     $this->payload['validate'][$vKey] = null;
                 }
             }
         }
     }
 }
开发者ID:Kleist,项目名称:xPDO,代码行数:92,代码来源:xpdovehicle.class.php


注:本文中的xPDO::toJSON方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。