/**
  * @param string $text
  *
  * @return ListItem
  */
 protected function renderNextButton($text = null)
 {
     $content = Std::coalesce($text, Html::safe('»'));
     if (!$this->paginator->hasMorePages()) {
         return $this->getDisabledPageWrapper($content);
     }
     return $this->getPageWrapper($content, $this->paginator->url($this->paginator->currentPage() + 1));
 }
예제 #2
0
 public function testCoalesce()
 {
     $this->assertEquals('doge', Std::coalesce('doge'));
     $this->assertEquals('doge', Std::coalesce(null, 'doge'));
     $this->assertEquals('doge', Std::coalesce(null, null, 'doge'));
     $this->assertEquals('doge', Std::coalesce(null, null, 'doge', 'dolan'));
     $this->assertEquals('gopher', Std::coalesce('gopher', null, 'doge'));
     $this->assertNull(Std::coalesce());
 }
예제 #3
0
 /**
  * Determine if some value fits inside a database column.
  *
  * Right now this check is limited to string values. Future versions might
  * support binary data and numbers as well.
  *
  * @param mixed $content
  * @param string $type
  * @param null $length
  *
  * @throws \Chromabits\Nucleus\Exceptions\LackOfCoffeeException
  * @return bool
  */
 public static function fits($content, $type, $length = null)
 {
     switch ($type) {
         case static::TYPE_CHAR:
         case static::TYPE_VARCHAR:
             return Std::within(0, Std::coalesce($length, 255), strlen($content));
         case static::TYPE_TINYTEXT:
             return Std::within(0, Std::coalesce($length, 2 ** 8), strlen($content));
         case static::TYPE_TEXT:
             return Std::within(0, Std::coalesce($length, 2 ** 16), strlen($content));
         case static::TYPE_MEDIUMTEXT:
             return Std::within(0, Std::coalesce($length, 2 ** 24), strlen($content));
         case static::TYPE_LONGTEXT:
             return Std::within(0, Std::coalesce($length, 2 ** 32), strlen($content));
     }
     throw new LackOfCoffeeException('Not implemented.');
 }
예제 #4
0
파일: intl.php 프로젝트: chromabits/nucleus
 /**
  * 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;
 }
예제 #5
0
 /**
  * Construct an instance of a ClosureConstraint.
  *
  * @param Closure $closure
  * @param string|null $description
  */
 public function __construct(Closure $closure, $description = null)
 {
     parent::__construct();
     $this->closure = $closure;
     $this->description = Std::coalesce($description, 'The value is expected to meet the constraint.');
 }
예제 #6
0
 /**
  * Generate an authorization code for the Research API server.
  *
  * @param null|integer $timestamp
  *
  * @return string
  */
 public function generateCode($timestamp = null)
 {
     Arguments::contain(Boa::either(Boa::null(), Boa::integer()))->check($timestamp);
     $timestamp = Std::coalesce($timestamp, time() + 3600 * 3);
     $signature = md5(implode('', [$timestamp, $this->clientId, $this->secret]));
     return vsprintf('%s|%s|%s', [$timestamp, $this->clientId, $signature]);
 }
예제 #7
0
 /**
  * Render the sidebar for this module.
  *
  * If null is returned, we won't display one.
  *
  * @param ConferenceContext $context
  *
  * @return SafeHtmlWrapper
  */
 public function renderSidebar(ConferenceContext $context)
 {
     return Html::safe((new UnorderedList(['class' => 'nav nav-pills nav-stacked'], Std::map(function (Method $method, $methodName) use($context) {
         return new ListItem(['class' => 'nav-item'], [new Anchor(['href' => $context->method($this->getName(), $methodName), 'class' => 'nav-link'], Std::coalesce($method->getLabel(), $methodName))]);
     }, Std::filter(function (Method $method) {
         return !$method->isHidden();
     }, $this->getMethods()))))->render());
 }
 /**
  * @param ConferenceContext $context
  * @param ResourceFactory $factory
  * @param bool $reflect
  * @param int $id
  *
  * @return Div
  */
 protected function renderResource(ConferenceContext $context, ResourceFactory $factory, $reflect = false, $id = 0)
 {
     return new Div([], [new Card([], [new CardHeader([], [Std::coalesce($factory->getPrefix(), '/'), ' ', new Italic(['class' => ['fa', 'fa-arrow-circle-right ']]), ' ', new Anchor(['href' => $context->method('illuminated.conference.application', 'single', ['resource' => $id])], new Bold([], $factory->getController()))]), new CardBlock([], [new Paragraph([], [new Bold([], 'Middleware: '), implode(', ', $factory->getMiddleware())]), new Div([], Std::map(function (ResourceMethod $method) use($factory, $reflect) {
         return $this->renderRoute($factory, $method, $reflect);
     }, $factory->getMethods()))])])]);
 }
 /**
  * Execute the command.
  */
 public function fire()
 {
     $take = $this->option('take');
     $ready = $this->scheduler->findReady($take);
     if (count($ready) < 1) {
         $this->line('No jobs ready to run.');
         return;
     }
     $defaultConnection = $this->config->get('jobs.queue.connection');
     $defaultQueue = $this->config->get('jobs.queue.id');
     /** @var Job $job */
     foreach ($ready as $job) {
         $this->pusher->push(RunTaskCommand::class, ['job_id' => $job->id], Std::coalesce($job->queue_connection, $defaultConnection), Std::coalesce($job->queue_name, $defaultQueue));
         $job = $job->fresh();
         // Sometimes, a developer might be running a sync queue. This means
         // we have to check if the jobs is still in a scheduled state.
         // Only then, we will update the status to queued. Otherwise, the
         // job gets stuck in a queued state.
         if ($job->state === JobState::SCHEDULED) {
             $job->state = JobState::QUEUED;
             $job->save();
         }
         $this->line('Queued Job ID: ' . $job->id . ' ' . $job->task);
     }
     $this->line('Finished.');
 }
예제 #10
0
파일: Rope.php 프로젝트: chromabits/nucleus
 /**
  * Construct an instance of a Rope.
  *
  * @param string|Rope $contents
  * @param string|null $encoding
  */
 public function __construct($contents = '', $encoding = null)
 {
     parent::__construct();
     $this->contents = (string) $contents;
     $this->encoding = Std::coalesce($encoding, mb_internal_encoding());
 }
예제 #11
0
 /**
  * Check that the spec matches and overlay help messaged.
  *
  * The resulting SpecResult instance should have more user-friendly
  * messages. This allows one to use Specs for validation on a website or
  * even an API.
  *
  * @param array $input
  *
  * @return SpecResult
  */
 public function check(array $input)
 {
     $result = $this->spec->check($input);
     return new SpecResult($result->getMissing(), Arr::walkCopy($result->getFailed(), function ($key, $value, &$array, $path) {
         $array[$key] = Std::coalesce(Std::firstBias(Arr::dotGet($this->messages, Std::nonempty($path, $key)) !== null, [Arr::dotGet($this->messages, Std::nonempty($path, $key))], null), Std::firstBias($value instanceof AbstractConstraint, function () use($value) {
             return $value->getDescription();
         }, null), Std::firstBias(is_array($value), function () use($value) {
             return array_map(function (AbstractConstraint $item) {
                 return $item->getDescription();
             }, $value);
         }, $value));
     }, true, '', false), $result->getStatus());
 }