protected function _postStartup() { foreach ($this->getDaoProperties() as $property) { $docblock = DocBlockParser::fromProperty($this, $property); if ($docblock->hasTag('counter')) { static::$_counters[$this->_calledClass][] = $property; } } }
public function testTagging() { $bloc = \Packaged\DocBlock\DocBlockParser::fromProperty(new DocBlockFiller(), 'property'); $this->assertEquals('Hello', $bloc->getTag('name')); $this->assertEquals('Default', $bloc->getTag('missing', 'Default')); $this->assertEquals('Hello', $bloc->getTagFailover(['nothing', 'name'])); $this->assertEquals('Default', $bloc->getTagFailover(['nothing', 'missing'], 'Default')); $this->assertEquals(3, $bloc->getTagCount('value')); $this->assertArrayHasKey('index', $bloc->getTags()); $this->assertArrayHasKey('name', $bloc->getTags()); $this->assertArrayHasKey('value', $bloc->getTags()); }
public function validate(array $properties = null, $throw = true) { $allValid = true; if ($properties === null) { $properties = Objects::properties($this->_payload); } $this->_properties = $properties; foreach ($properties as $property) { $block = DocBlockParser::fromProperty($this->_payload, $property); $nullable = $block->hasTag('nullable'); $optional = $block->hasTag('optional'); $val = $this->_payload->{$property}; if ($val === null && ($nullable || $optional) || $val === '' && $optional) { continue; } foreach ($block->getTags() as $tag => $tags) { foreach ($tags as $opt) { if ($this->_repair) { $this->repairValue($tag, $property, $val, $opt); } try { $this->runValidator($tag, $property, $val, $opt); } catch (\Exception $e) { if ($throw) { throw $e; } else { $allValid = false; if (!isset($this->_errors[$property])) { $this->_errors[$property] = []; } $this->_errors[$property][] = $e->getMessage(); } } } } } return $allValid; }
/** * Prepare the form */ protected function _boot() { $formDoc = DocBlockParser::fromObject($this->getDataObject()); $labelPosition = FormElement::LABEL_BEFORE; $defaultTags = []; foreach ($formDoc->getTags() as $tag => $values) { foreach ($values as $value) { if (Strings::startsWith($tag, 'element', false)) { $defaultTags[substr($tag, 7)] = $value; } } } foreach ($this->_processPublicProperties() as $property) { if (isset($this->_elements[$property])) { continue; } static::$_propDocBlocks[$this->_calledClass][$property] = $docblock = DocBlockParser::fromProperty($this->getDataObject(), $property); //Setup the type $type = $docblock->getTagFailover(["inputType", "type", "input"]); if ($type === null) { $type = FormElement::calculateType($property); } //Setup the label $label = $docblock->getTag("label"); if ($label === null) { $label = Strings::humanize($property); } $element = new FormElement($this, $property, $type, $label, $labelPosition); foreach ($defaultTags as $tag => $value) { $element->processDocBlockTag($tag, $value); } $element->setDataObject($this->getDataObject(), $property); $this->_aliases[$element->getName()] = $property; foreach ($docblock->getTags() as $tag => $values) { foreach ($values as $value) { $element->processDocBlockTag($tag, $value); } } $this->_elements[$property] = $element; } if ($this->_enableCsrf) { $this->_buildCsrf(); } else { $this->getElement($this->_csrfField)->setRenderer(new FormElementRenderer('')); } }