Esempio n. 1
0
 /**
  * Multibyte version of ucwords().
  *
  * @param string $str
  * @param string $delimiters
  * @param null|string $encoding
  *
  * @return mixed|string
  */
 function mb_ucwords($str, $delimiters = " \t\r\n\f\v", $encoding = null)
 {
     $encoding = Std::coalesce($encoding, mb_internal_encoding());
     $delimitersArray = mb_str_split($delimiters, 1, $encoding);
     $upper = true;
     $result = '';
     for ($ii = 0; $ii < mb_strlen($str, $encoding); $ii++) {
         $char = mb_substr($str, $ii, 1, $encoding);
         if ($upper) {
             $char = mb_convert_case($char, MB_CASE_UPPER, $encoding);
             $upper = false;
         } elseif (ArrayList::of($delimitersArray)->includes($char)) {
             $upper = true;
         }
         $result .= $char;
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Wrap provided value inside a List.
  *
  * @param array|ArrayObject|ListInterface $input
  *
  * @return ArrayList
  * @throws InvalidArgumentException
  */
 public static function toList($input)
 {
     Arguments::define(Boa::lst())->check($input);
     if ($input instanceof ListInterface) {
         return $input;
     }
     return ArrayList::of($input);
 }
Esempio n. 3
0
 /**
  * Build an instance of the defined Spec.
  *
  * @return Spec
  */
 public function make()
 {
     return new Spec($this->constraints->toArray(), $this->defaults->toArray(), $this->required->toArray());
 }
 protected function renderFullField($fieldName)
 {
     $fieldNodes = $this->renderField($fieldName);
     if (!is_array($fieldNodes)) {
         $nodes = ArrayList::of([$fieldNodes]);
     } else {
         $nodes = ArrayList::of($fieldNodes);
     }
     if ($this->spec->getFieldDescription($fieldName)->isJust()) {
         $nodes = $nodes->append(ArrayList::of([new Paragraph([], new Small(['class' => 'text-muted'], [Maybe::fromJust($this->spec->getFieldDescription($fieldName))]))]));
     }
     return $nodes->toArray();
 }
Esempio n. 5
0
 /**
  * Render the content of the tag.
  *
  * @throws CoreException
  * @return string
  */
 protected function renderContent()
 {
     if (is_string($this->content) || $this->content instanceof SafeHtmlWrapper || $this->content instanceof SafeHtmlProducerInterface) {
         return Html::escape($this->content);
     } elseif ($this->content instanceof RenderableInterface) {
         return Html::escape($this->content->render());
     } elseif (is_array($this->content) || $this->content instanceof ArrayableInterface) {
         return ArrayList::of($this->content)->map(function ($child) {
             if (is_string($child) || $child instanceof SafeHtmlWrapper || $child instanceof SafeHtmlProducerInterface) {
                 return Html::escape($child);
             } elseif ($child instanceof RenderableInterface) {
                 return Html::escape($child->render());
             }
             throw new NodeChildRenderingException($child);
         })->join();
     }
     throw new NodeRenderingException($this->content);
 }
Esempio n. 6
0
 /**
  * Get all the constraints for a field.
  *
  * @param string $fieldName
  *
  * @return Iterable
  */
 protected function getInternalFieldConstraints($fieldName)
 {
     return parent::getInternalFieldConstraints($fieldName)->append(ArrayList::of([$this->getFieldType($fieldName)]));
 }
Esempio n. 7
0
 /**
  * Return the string with all its characters reversed.
  *
  * @return Rope
  */
 public function reverse()
 {
     return static::of(ArrayList::of($this->split())->reverse()->join(), $this->encoding);
 }
Esempio n. 8
0
 /**
  * Get an array representation of this entity.
  *
  * @return array
  */
 public function toArray()
 {
     $result = [];
     ArrayList::of($this->getFillable())->append(ArrayList::of($this->getVisible()))->unique(SORT_STRING)->exceptValues($this->getHidden())->each(function ($key) use(&$result) {
         $getter = vsprintf('get%s', [Str::studly($key)]);
         if (method_exists($this, $getter)) {
             $result[$key] = $this->{$getter}();
             return;
         }
         $camel = Str::camel($key);
         $result[$key] = $this->{$camel};
     });
     return $result;
 }
Esempio n. 9
0
 /**
  * Left-curry the provided function with the provided array of arguments.
  *
  * @param callable $function
  * @param mixed[] $args
  *
  * @return Closure|mixed
  */
 public static function curryArgs(callable $function, $args)
 {
     Arguments::define(Boa::func(), Boa::arr())->check($function, $args);
     // Counts required parameters.
     $required = function () use($function) {
         return (new ReflectionFunction($function))->getNumberOfRequiredParameters();
     };
     $isFulfilled = function (callable $function, $args) use($required) {
         return count($args) >= $required($function);
     };
     if ($isFulfilled($function, $args)) {
         return static::apply($function, $args);
     }
     return function (...$funcArgs) use($function, $args, $required, $isFulfilled) {
         $newArgs = ArrayList::of($args)->append(ArrayList::of($funcArgs))->toArray();
         if ($isFulfilled($function, $newArgs)) {
             return static::apply($function, $newArgs);
         }
         return static::curryArgs($function, $newArgs);
     };
 }
Esempio n. 10
0
 /**
  * @return ListInterface
  */
 public static function toList()
 {
     return ArrayList::of(static::getValues());
 }
Esempio n. 11
0
 /**
  * Render the object into a string.
  *
  * @return mixed
  */
 public function render()
 {
     $classes = ArrayList::of(['fa', vsprintf('fa-%s', [$this->icon])]);
     // Spin class (fa-spin)
     if ($this->spin) {
         $classes = $classes->append(ArrayList::of(['fa-spin']));
     }
     // Size classes (fa-lg, fa-2x, fa-3x...)
     if ($this->size === 1) {
         $classes = $classes->append(ArrayList::of(['fa-lg']));
     } elseif ($this->size > 1 && $this->size < 6) {
         $classes = $classes->append(ArrayList::of([vsprintf('fa-%dx', [$this->size])]));
     }
     // Fixed-width class (fa-fw)
     if ($this->fixedWidth) {
         $classes = $classes->append(ArrayList::of(['fa-fw']));
     }
     // List icons class (fa-li)
     if ($this->list) {
         $classes = $classes->append(ArrayList::of(['fa-li']));
     }
     // Border class (fa-border)
     if ($this->bordered) {
         $classes = $classes->append(ArrayList::of(['fa-border']));
     }
     // Pull classes (fa-pull-right, fa-pull-left)
     if ($this->pull !== null && $this->pull !== '') {
         $classes = $classes->append(ArrayList::of([vsprintf('fa-pull-%s', [$this->pull])]));
     }
     // Rotation classes
     switch ($this->rotation) {
         case 90:
             $classes = $classes->append(ArrayList::of(['fa-rotate-90']));
             break;
         case 180:
             $classes = $classes->append(ArrayList::of(['fa-rotate-180']));
             break;
         case 270:
             $classes = $classes->append(ArrayList::of(['fa-rotate-270']));
             break;
     }
     // Flip classes
     switch ($this->flip) {
         case 'horizontal':
             $classes = $classes->append(ArrayList::of(['fa-flip-horizontal']));
             break;
         case 'vertical':
             $classes = $classes->append(ArrayList::of(['fa-flip-horizontal']));
             break;
     }
     return (new Italic(['class' => $classes->join(' ')]))->render();
 }
Esempio n. 12
0
 public function testOf()
 {
     $list = ArrayList::of(['hello', 'world']);
     $this->assertInstanceOf(ArrayList::class, $list);
 }
Esempio n. 13
0
 /**
  * Get all the constraints for a single field.
  *
  * @param string $fieldName
  *
  * @return Iterable
  */
 public function getFieldConstraints($fieldName)
 {
     $maybeConstraints = $this->annotations->lookupIn([$fieldName, static::ANNOTATION_CONSTRAINTS]);
     if ($maybeConstraints->isNothing()) {
         return ArrayList::zero();
     }
     $constraints = Maybe::fromJust($maybeConstraints);
     if (is_array($constraints)) {
         return ArrayList::of($constraints);
     } elseif ($constraints instanceof Iterable) {
         return $constraints;
     }
     return ArrayList::of([$constraints]);
 }
 /**
  * Construct an instance of a MismatchedArgumentTypesException.
  *
  * @param string $functionName
  * @param mixed $arguments
  */
 public function __construct($functionName, ...$arguments)
 {
     parent::__construct(vsprintf('Argument type mismatch: %s for function %s', [ArrayList::of($arguments)->map(function ($item) {
         return TypeHound::fetch($item);
     })->join(', '), $functionName]));
 }
Esempio n. 15
0
 public function testEach()
 {
     $result = '';
     $concat = function ($x) use(&$result) {
         $result .= $x;
     };
     Std::each($concat, ['h', 'e', 'l', 'l', 'o', ' ']);
     Std::each($concat, ArrayList::of(['w', 'o', 'r', 'l', 'd']));
     Std::each($concat, new ArrayObject([' ', ':', ')']));
     $this->assertEquals('hello world :)', $result);
 }