Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Config_Writer_Json Class Reference
Inheritance diagram for Zend_Config_Writer_Json:
Zend_Config_Writer_FileAbstract Zend_Config_Writer

Public Member Functions

 prettyPrint ()
 
 setPrettyPrint ($flag)
 
 render ()
 
- Public Member Functions inherited from Zend_Config_Writer_FileAbstract
 setFilename ($filename)
 
 setExclusiveLock ($exclusiveLock)
 
 write ($filename=null, Zend_Config $config=null, $exclusiveLock=null)
 
 render ()
 
- Public Member Functions inherited from Zend_Config_Writer
 __construct (array $options=null)
 
 setConfig (Zend_Config $config)
 
 setOptions (array $options)
 
 write ()
 

Protected Attributes

 $_prettyPrint = false
 
- Protected Attributes inherited from Zend_Config_Writer_FileAbstract
 $_filename = null
 
 $_exclusiveLock = false
 
- Protected Attributes inherited from Zend_Config_Writer
 $_skipOptions
 
 $_config = null
 

Detailed Description

Definition at line 38 of file Json.php.

Member Function Documentation

◆ prettyPrint()

prettyPrint ( )

Get prettyPrint flag

Returns
the prettyPrint flag

Definition at line 52 of file Json.php.

53  {
54  return $this->_prettyPrint;
55  }

◆ render()

render ( )

Render a Zend_Config into a JSON config string.

Since
1.10
Returns
string

Definition at line 75 of file Json.php.

76  {
77  $data = $this->_config->toArray();
78  $sectionName = $this->_config->getSectionName();
79  $extends = $this->_config->getExtends();
80 
81  if (is_string($sectionName)) {
82  $data = array($sectionName => $data);
83  }
84 
85  foreach ($extends as $section => $parentSection) {
86  $data[$section][Zend_Config_Json::EXTENDS_NAME] = $parentSection;
87  }
88 
89  // Ensure that each "extends" section actually exists
90  foreach ($data as $section => $sectionData) {
91  if (is_array($sectionData) && isset($sectionData[Zend_Config_Json::EXTENDS_NAME])) {
92  $sectionExtends = $sectionData[Zend_Config_Json::EXTENDS_NAME];
93  if (!isset($data[$sectionExtends])) {
94  // Remove "extends" declaration if section does not exist
95  unset($data[$section][Zend_Config_Json::EXTENDS_NAME]);
96  }
97  }
98  }
99 
100  $out = Zend_Json::encode($data);
101  if ($this->prettyPrint()) {
102  $out = Zend_Json::prettyPrint($out);
103  }
104  return $out;
105  }
static prettyPrint($json, $options=array())
Definition: Json.php:379
const EXTENDS_NAME
Definition: Json.php:45
static encode($valueToEncode, $cycleCheck=false, $options=array())
Definition: Json.php:130

◆ setPrettyPrint()

setPrettyPrint (   $flag)

Set prettyPrint flag

Parameters
bool$prettyPrintPrettyPrint flag
Returns
Zend_Config_Writer_Json

Definition at line 63 of file Json.php.

64  {
65  $this->_prettyPrint = (bool) $flag;
66  return $this;
67  }

Field Documentation

◆ $_prettyPrint

$_prettyPrint = false
protected

Definition at line 45 of file Json.php.


The documentation for this class was generated from the following file: