public function testHumanizeCamelSplit() { $expectations = [["first name", "First name"], ["first_name", "First name"], ["firstName", "First name"]]; foreach ($expectations as $expect) { $this->assertEquals($expect[1], \Packaged\Helpers\Strings::humanize($expect[0], true)); } }
public function __construct(Form $form, $name, $type = self::TEXT, $label = null, $labelPosition = self::LABEL_BEFORE) { $name = Strings::stringToUnderScore($name); $this->_name = $name; $this->_id = $form->getId() . '-' . Strings::urlize($name); $this->setOption('name', $name); $this->setOption('id', $this->_id); $this->_type = $type; $this->_label = $label === null ? Strings::humanize($name) : $label; $this->_labelPosition = $labelPosition; $this->_form = $form; }
/** * 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('')); } }
/** * @param string $useName Use this as the key * @param string $useValue Use this as the value * * @return string */ public function getReadableValue($useName = null, $useValue = null) { $useName = $useName ?: ucwords(Strings::humanize($this->key)); $useValue = $useValue ?: $this->value; if (is_array($useValue)) { $useValue = implode(', ', ValueAs::arr($useValue)); } $nonIsComparators = [AdvancedFilterComparator::STARTS_WITH, AdvancedFilterComparator::NOT_STARTS_WITH, AdvancedFilterComparator::ENDS_WITH, AdvancedFilterComparator::NOT_ENDS_WITH]; if (!in_array($this->comparator, $nonIsComparators)) { $useName .= ' is'; } if (in_array($this->comparator, [AdvancedFilterComparator::BETWEEN, AdvancedFilterComparator::NOT_BETWEEN])) { list($min, $max) = explode(',', $useValue); return $useName . ' between ' . trim($min) . ' and ' . trim($max); } if (is_bool($useValue)) { return $useName . ' ' . ($useValue ? 'true' : 'false'); } return $useName . ' ' . AdvancedFilterComparator::getDisplayValue($this->comparator) . ' ' . $useValue; }
/** * Assemble the segment * * @return string */ public function assemble() { throw new \RuntimeException("Unsupported segment '" . get_class($this->_segment) . "' passed to the " . ucwords(Strings::humanize(Objects::classShortname(get_called_class())))); }