コード例 #1
0
 /**
  * Get all migrations.
  *
  * @param StructuredStatusInterface $status
  *
  * @return Card
  */
 public function getAll(StructuredStatusInterface $status)
 {
     $report = $status->generateReport();
     $idle = $report->getIdle();
     $unknown = $report->getUnknown();
     $ran = $report->getRan();
     return new Card([], [new CardHeader([], 'All Migrations'), new SimpleTable(['-', 'Status', 'Name'], Std::map(function ($name) use($idle, $unknown, $ran) {
         if (in_array($name, $idle)) {
             return [new Italic(['class' => ['fa', 'fa-circle-o', 'text-warning']]), 'Pending', $name];
         } elseif (in_array($name, $unknown)) {
             return [new Italic(['class' => ['fa', 'fa-times-circle', 'text-danger']]), 'Exotic', $name];
         } elseif (in_array($name, $ran)) {
             return [new Italic(['class' => ['fa', 'fa-check-circle', 'text-success']]), 'Ran', $name];
         }
         return [new Italic(['class' => ['fa', 'fa-circle-o']]), '???', $name];
     }, Std::concat($report->getMigrations(), $report->getUnknown())))]);
 }
コード例 #2
0
 /**
  * Get list of services provided.
  *
  * @throws LackOfCoffeeException
  * @return array
  */
 public function provides()
 {
     return Std::concat(Arr::keys($this->getServiceMap()), Arr::keys($this->getSingletons()));
 }
コード例 #3
0
ファイル: Spec.php プロジェクト: chromabits/nucleus
 /**
  * Check that a certain input passes the spec.
  *
  * @param mixed $input
  *
  * @return SpecResult
  */
 public function check(array $input)
 {
     $missing = [];
     $invalid = [];
     $check = function ($constraint, $key, $value, $input) use(&$missing, &$invalid) {
         if ($constraint instanceof AbstractConstraint) {
             if (!$constraint->check($value, $input)) {
                 $invalid[$key][] = $constraint;
             }
         } elseif ($constraint instanceof CheckableInterface) {
             $result = $constraint->check($value);
             $missing = Std::concat($missing, array_map(function ($subKey) use($key) {
                 return vsprintf('%s.%s', [$key, $subKey]);
             }, $result->getMissing()));
             foreach ($result->getFailed() as $failedField => $constraints) {
                 $fullPath = vsprintf('%s.%s', [$key, $failedField]);
                 if (array_key_exists($fullPath, $invalid)) {
                     $invalid[$fullPath] = array_merge($invalid[$fullPath], $constraints);
                 } else {
                     $invalid[$fullPath] = $constraints;
                 }
             }
         } else {
             throw new CoreException(vsprintf('Unexpected constraint type: %s.', [TypeHound::fetch($constraint)]));
         }
     };
     $inputMap = ArrayMap::of($input);
     $this->annotations->each(function ($value, $key) use($check, $input, $inputMap, &$missing) {
         // If a field is required but not present, we should report it.
         if (Maybe::fromMaybe(false, $value->lookup(static::ANNOTATION_REQUIRED)) && $inputMap->member($key) === false) {
             $missing[] = $key;
             // There's no point on checking constraints on the field
             // since it is missing.
             return;
         } elseif ($inputMap->member($key) === false) {
             // There's no point on checking constraints on the field
             // since it is missing.
             return;
         }
         $fieldValue = Maybe::fromJust($inputMap->lookup($key));
         $this->getInternalFieldConstraints($key)->each(function ($constraint) use($check, $key, $fieldValue, $input) {
             $check($constraint, $key, $fieldValue, $input);
         });
     });
     if (count($missing) === 0 && count($invalid) === 0) {
         return new SpecResult($missing, $invalid, SpecResult::STATUS_PASS);
     }
     return new SpecResult($missing, $invalid, SpecResult::STATUS_FAIL);
 }
コード例 #4
0
ファイル: StdTest.php プロジェクト: chromabits/nucleus
 public function testConcat()
 {
     $this->assertEqualsMatrix([['hello world', Std::concat('hello ', 'world')], [[1, 'one' => 'two', 2, 'six' => 'seven'], Std::concat([1, 'one' => 'two'], [2, 'six' => 'seven'])]]);
 }