/** * @param NavigatorInterface $navigator * @param VisitorInterface $visitor * @param mixed $value * @return void */ public function accept(NavigatorInterface $navigator, VisitorInterface $visitor, $value) { switch (gettype($value)) { case 'object': $visitor->visitArrayStart(); $names = $this->objectAccessor->getNames($value); foreach ($names as $name) { $property = $this->objectAccessor->getValue($value, $name); $visitor->visitElementStart($name); $navigator->accept($navigator, $visitor, $property); $visitor->visitElementEnd($name); } $visitor->visitArrayEnd(); break; case 'array': $visitor->visitArrayStart(); foreach ($value as $key => $element) { $visitor->visitElementStart($key); $navigator->accept($navigator, $visitor, $element); $visitor->visitElementEnd($key); } $visitor->visitArrayEnd(); break; default: $visitor->visitValue($value); break; } }
/** * Turn an object graph into another object graph * * @param mixed $value * @param string $type * @return mixed */ public function map($value, $type) { $this->visitor->visitType(Type::fromString($type)); $this->navigator->accept($this->navigator, $this->visitor, $value); return $this->visitor->getResult(); }
/** * @param NavigatorInterface $navigator * @param VisitorInterface $visitor * @param mixed $value * @return void */ public function accept(NavigatorInterface $navigator, VisitorInterface $visitor, $value) { $this->navigator->accept($navigator, $visitor, $this->converter->convert($value)); }