Closed qfox closed 9 years ago
We should create a special classes for mods, bemjson nodes, etc.
Mods:
class Mods implements Iterator { protected $content = []; // etc. }
JsonNode (or Json, or Node):
class JsonNode { protected $block = 'page'; protected $elem = 'content'; protected $mods = null; // Mods protected $blockMods = null; // Mods protected $elemMods = null; // Mods protected $attrs = 'page'; protected $content = []; // etc. function __construct (array $bemjson) { $this->block = $bemjson['block']; $this->elem = $bemjson['elem']; $this->content = $bemjson['content']; } function iterate (callable $cb) { // call cb for each node } public static buildTree ($bemjson) { if (is_array($bemjson)) { $res = []; foreach ($bemjson as $node) { $res[] = static::buildTree($node); } return $res; } elseif ($bemjson instanceof self) { return $bemjson; } else { // etc. return new self($bemjson); } } }
Done in 54cf16218
We should create a special classes for mods, bemjson nodes, etc.
Mods:
JsonNode (or Json, or Node):