Ejemplo n.º 1
0
 protected function _postStartup()
 {
     foreach ($this->getDaoProperties() as $property) {
         $docblock = DocBlockParser::fromProperty($this, $property);
         if ($docblock->hasTag('counter')) {
             static::$_counters[$this->_calledClass][] = $property;
         }
     }
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 /**
  * @return ISafeHtmlProducer
  */
 public function render()
 {
     $output = new Div();
     $groups = $this->getMethods();
     foreach ($groups as $group => $methods) {
         $output->appendContent(Div::create(new HeadingOne(Strings::titleize($group)))->addClass('content-container'));
         foreach ($methods as $method) {
             $reflect = new \ReflectionMethod($this, $method);
             $parsed = DocBlockParser::fromMethod($this, $method);
             $code = $this->_getCode($reflect);
             $id = Strings::randomString(4);
             $toggledCode = new Div();
             $toggledCode->appendContent(new HeadingFour((new Link('#', Strings::titleize($method)))->setAttribute('onclick', '$(\'#code-' . $id . '\')' . '.toggleClass(\'' . Ui::HIDE . '\');' . 'return false;')));
             $code = new SafeHtml(str_replace('<span style="color: #0000BB">&lt;?php&nbsp;</span>', '', highlight_string('<?php ' . $code, true)));
             $toggledCode->appendContent(Div::create()->appendContent(HtmlTag::createTag('pre', [], $code))->addClass(Ui::HIDE)->setId('code-' . $id));
             $methRow = Div::create()->addClass('content-container');
             $methRow->appendContent($toggledCode);
             $methRow->appendContent(new Paragraph($parsed->getSummary()));
             $methRow->appendContent($this->{$method}());
             $output->appendContent($methRow);
         }
     }
     return $output;
 }
Ejemplo n.º 4
0
 /**
  * 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(''));
     }
 }
Ejemplo n.º 5
0
 /**
  * Retrieve the description for this endpoint
  *
  * @return string
  */
 public function getDescription()
 {
     return DocBlockParser::fromObject($this)->getSummary();
 }
Ejemplo n.º 6
0
 public function testGetRaw()
 {
     $bloc = \Packaged\DocBlock\DocBlockParser::fromObject(new DocBlockFiller());
     $this->assertInstanceOf('\\Eloquent\\Blox\\Element\\DocumentationBlock', $bloc->rawDocBlock());
 }
Ejemplo n.º 7
0
 /**
  * @return DocBlockParser[]
  */
 protected static function _getDocBlockProperties()
 {
     if (!isset(self::$_docBlockProperties[get_called_class()])) {
         self::$_docBlockProperties[get_called_class()] = DocBlockParser::fromProperties(get_called_class(), \ReflectionProperty::IS_PUBLIC);
     }
     return self::$_docBlockProperties[get_called_class()];
 }