コード例 #1
0
ファイル: RadioGroupElement.php プロジェクト: desmart/deform
 /**
  * Add new element to group.
  *
  * @param \DeForm\Element\ElementInterface $element
  * @return self
  * @throw \InvalidArgumentException
  */
 public function addElement(ElementInterface $element)
 {
     if (false === $element instanceof RadioElement) {
         throw new \InvalidArgumentException('Only instance of RadioElement object can be added.');
     }
     if ($this->countElements() > 0 && $element->getName() !== $this->getName()) {
         throw new \InvalidArgumentException('Attribute input[name] is invalid.');
     }
     $this->elements[] = $element;
     return $this;
 }
コード例 #2
0
 /**
  * Map everything to an array.
  *
  * @return array
  */
 public function toArray()
 {
     $array = [];
     if (!empty($this->data)) {
         $array['data'] = $this->data->toIdentifier();
     }
     if (!empty($this->meta)) {
         $array['meta'] = $this->meta;
     }
     if (!empty($this->links)) {
         $array['links'] = $this->links;
     }
     return $array;
 }
コード例 #3
0
ファイル: Node.php プロジェクト: tomaskuba/vp-tree
 public function distance(ElementInterface $a, ElementInterface $b)
 {
     $aCoordinates = $a->getCoordinates();
     $bCoordinates = $b->getCoordinates();
     if (array_keys($aCoordinates) != array_keys($bCoordinates)) {
         throw new \InvalidArgumentException('Unequal elements\' dimensions');
     }
     $sum = 0;
     foreach ($aCoordinates as $dimension => $value) {
         $diff = abs($bCoordinates[$dimension] - $aCoordinates[$dimension]);
         $sum += pow($diff, 2);
     }
     $distance = sqrt($sum);
     return $distance;
 }
コード例 #4
0
 /**
  * Convert to BBCode
  *
  * Converts an individual node into a #text node containing a string of its BBCode equivalent.
  *
  * Example: An <h3> node with text content of 'Title' becomes a text node with content of '### Title'
  *
  * @param ElementInterface $element
  *
  * @return string The converted HTML as BBCode
  */
 protected function convertToBBCode(ElementInterface $element)
 {
     $tag = $element->getTagName();
     // Strip nodes named in remove_nodes
     $tags_to_remove = explode(' ', $this->getConfig()->getOption('remove_nodes'));
     if (in_array($tag, $tags_to_remove)) {
         return false;
     }
     $converter = $this->environment->getConverterByTag($tag);
     return $converter->convert($element);
 }