public function testSetPrototype() { $prototype = $this->getDefinitionMock(); $definition = new Definition(); $definition->setPrototype($prototype); $this->assertSame($prototype, $definition->getPrototype()); }
/** * @param \XMLWriter $writer * @param resource $stream * @param mixed $origin * @param Definition $definition * @return mixed */ protected function writeArray(\XMLWriter $writer, $stream, $origin, Definition $definition) { $prototype = $definition->getPrototype(); $collection = $definition->extract($origin); foreach ($collection as $index => $entry) { $writer->startElement($prototype->getNodeName()); if ($definition->getKeyName()) { $writer->writeAttribute($definition->getKeyName(), $index); } $this->writeNode($writer, $stream, $entry, $prototype); $writer->endElement(); } return $origin; }
/** * @param string $name * @param array $attributes * @return ContextInterface * @throws \Exception */ public function start($name, array $attributes = array()) { $this->initialize(); if ($this->definition->isArray()) { $prototype = $this->definition->getPrototype(); $keyName = $this->definition->getKeyName(); if ($keyName && isset($attributes[$keyName])) { $this->key = $attributes[$keyName]; } else { $this->key = $this->index; $this->index++; } if (!isset($this->collection[$this->key])) { $this->collection[$this->key] = $prototype->create($this->origin); } $this->definition->settleKey($this->collection[$this->key], $this->key); return new DefinitionContext($this->collection[$this->key], $prototype); } if ($this->definition->isObject() && $this->definition->hasProperty($name)) { return new DefinitionContext($this->object, $this->definition->getProperty($name)); } return new NullContext(); }