/**
  * Parse each product in the response and add it to the rich response.
  *
  * @param SearchResponse $searchResponse
  * @param array $body
  */
 protected function parseProducts(SearchResponse $searchResponse, array $body)
 {
     $factory = new SearchProductFactory();
     $searchResponse->setSearchProducts(Std::map(function ($rawProduct) use($factory) {
         return $factory->makeFromArray($rawProduct);
     }, Arr::dotGet($body, 'searchCatalogs.result', [])));
 }
예제 #2
0
 /**
  * Render the object into a string.
  *
  * @return mixed
  */
 public function render()
 {
     return (new Table(['class' => 'table'], [new TableHeader([], new TableRow([], Std::map(function ($columnLabel) {
         return new TableHeaderCell([], $columnLabel);
     }, $this->headerLabels))), new TableBody([], Std::map(function ($row) {
         return new TableRow([], Std::map(function ($cell) {
             return new TableCell([], $cell);
         }, $row));
     }, $this->rows))]))->render();
 }
예제 #3
0
 /**
  * Generate a URL for a path inside the dashboard.
  *
  * @param string $path
  * @param array $parameters
  * @param null|bool $secure
  *
  * @return string
  */
 public function url($path = '', $parameters = [], $secure = null)
 {
     $queryString = '';
     if (count($parameters)) {
         $queryString = '?' . implode('&', Std::map(function ($value, $name) {
             return urlencode($name) . '=' . urlencode($value);
         }, $parameters));
     }
     return url($this->basePath . $path, [], $secure) . $queryString;
 }
 /**
  * Parse category mappings.
  *
  * @param GetAsinCategoriesResponse $categoriesResponse
  * @param array $body
  */
 protected function parseMappings(GetAsinCategoriesResponse $categoriesResponse, array $body)
 {
     $factory = new CategoryMappingFactory();
     $categoriesResponse->setCategoryMappings(Std::map(function ($rawMapping) use($factory, $categoriesResponse) {
         $mapping = $factory->makeFromArray($rawMapping);
         if ($mapping->isMainCategory()) {
             $categoriesResponse->setMainCategory($mapping);
         }
         return $mapping;
     }, $body['categoryMappings']));
 }
예제 #5
0
 /**
  * Build an instance of an Impersonator included common dependencies
  * defined in the map returned by getCommonProvisions().
  *
  * @return Impersonator
  * @throws LackOfCoffeeException
  */
 public function impersonatorWithCommon()
 {
     $impersonator = $this->impersonator();
     Std::map(function ($value, $key) use($impersonator) {
         if (is_array($value) || $value instanceof Closure) {
             $impersonator->mock($key, $value);
             return;
         }
         $impersonator->provide($value);
     }, $this->getCommonProvisions());
     return $impersonator;
 }
 /**
  * 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())))]);
 }
예제 #7
0
 /**
  * Render the object into a string.
  *
  * @return mixed
  */
 public function render()
 {
     return new Div([], Std::map(function (Alert $alert) {
         $classes = ['alert'];
         switch ($alert->getType()) {
             case Alert::TYPE_SUCCESS:
                 $classes[] = 'alert-success';
                 break;
             case Alert::TYPE_WARNING:
                 $classes[] = 'alert-warning';
                 break;
             case Alert::TYPE_INFO:
                 $classes[] = 'alert-info';
                 break;
             case Alert::TYPE_ERROR:
                 $classes[] = 'alert-danger';
                 break;
         }
         return new Div(['class' => $classes], $alert->getContent());
     }, $this->alerts));
 }
예제 #8
0
 /**
  * Get an array representation of this object.
  *
  * @return array
  */
 public function toArray()
 {
     return RamlUtils::filterEmptyValues(['example' => $this->example, 'schema' => $this->schema, 'formParameters' => Std::map(function (RamlParameter $parameter) {
         return $parameter->toArray();
     }, $this->formParameters)]);
 }
예제 #9
0
 /**
  * Generate a raml file describing the application.
  *
  * @param ApplicationManifestInterface $manifest
  * @param RamlEncoderOptions $options
  *
  * @return string
  */
 public function encode(ApplicationManifestInterface $manifest, RamlEncoderOptions $options = null)
 {
     $options = Std::coalesceThunk($options, function () use($manifest) {
         if ($manifest->hasProperty('ramlEncoderOptions')) {
             return $manifest->getProperty('ramlEncoderOptions');
         }
         return RamlEncoderOptions::defaultOptions();
     });
     $root = ['title' => $manifest->getName(), 'version' => $manifest->getCurrentVersion(), 'mediaType' => 'application/json', 'baseUri' => $manifest->getBaseUri()];
     if (count($manifest->getProse())) {
         foreach ($manifest->getProse() as $title => $content) {
             $root['documentation'][] = ['title' => $title, 'content' => $content];
         }
     }
     foreach ($manifest->getApiResources() as $resource) {
         $path = $resource->getPrefix();
         if ($path == '') {
             $path = '/';
         }
         if (Arr::has($root, $path)) {
             $root[$path] = Arr::merge($root[$path], $this->encodeResource($resource, $options));
             continue;
         }
         $root[$path] = $this->encodeResource($resource, $options);
     }
     if ($options !== null) {
         $root['securitySchemes'] = Std::map(function ($scheme) {
             $result = [];
             foreach ($scheme as $key => $property) {
                 $result[$key] = $property->toArray();
             }
             return $result;
         }, $options->getSecuritySchemes());
     }
     $yaml = yaml_emit(RamlUtils::filterEmptyValues($root));
     return str_replace("---\n", "#%RAML 0.8\n", $yaml);
 }
예제 #10
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());
 }
 /**
  * Render all router patterns.
  *
  * @param Router $router
  *
  * @return Table
  */
 protected function renderPatterns(Router $router)
 {
     return new Table(['class' => 'table'], [new TableHeader([], new TableRow([], [new TableHeaderCell([], 'Key'), new TableHeaderCell([], 'Pattern')])), new TableBody([], Std::map(function ($pattern, $key) {
         return new TableRow([], [new TableCell([], $key), new TableCell([], new PreformattedText(['class' => 'pre-scrollable'], $pattern))]);
     }, $router->getPatterns()))]);
 }
예제 #12
0
 /**
  * Generate the model.
  *
  * @throws LackOfCoffeeException
  * @return Model
  */
 public function make()
 {
     // Make model instance
     $model = $this->getModelInstance(true);
     $filling = TransformPipeline::define()->inline(function ($input) {
         return array_merge($input, $this->overrides);
     })->inline(function ($input) {
         return Std::map(function ($value) {
             return Std::value($value);
         }, $input);
     })->run($this->getMapping());
     Std::each(function ($value, $key) use(&$model) {
         $model->{$key} = $value;
     }, $filling);
     Std::each(function ($relation, $name) use(&$model) {
         if (!$this->isBelongsTo($name)) {
             return;
         }
         $model->{$name}()->associate($this->generateRelation($name));
     }, $this->relations);
     $model->save();
     Std::each(function ($relation, $name) use(&$model) {
         if ($this->isBelongsTo($name)) {
             return;
         }
         $related = $this->generateRelation($name);
         if (is_array($related)) {
             $model->{$name}()->saveMany($related);
         } else {
             $model->{$name}()->save($related);
         }
     }, $this->relations);
     return $model;
 }
예제 #13
0
 /**
  * Get an array representation of this object.
  *
  * @return array
  */
 public function toArray()
 {
     return Std::map(function (RamlBody $body) {
         return $body->toArray();
     }, $this->bodyTypes);
 }
예제 #14
0
 /**
  * Render the object into a string.
  *
  * @return mixed
  */
 public function render()
 {
     return new Div([], Std::map(function ($content, $term) {
         return new Row([], [new Column(['medium' => 4], new Bold([], $term . ':')), new Column(['medium' => 8], $content)]);
     }, $this->descriptions));
 }
예제 #15
0
 /**
  * Get an array representation of this object.
  *
  * @return array
  */
 public function toArray()
 {
     return Std::map(function (RamlResponse $response) {
         return $response->toArray();
     }, $this->responses);
 }
 /**
  * Get problematic modules.
  *
  * @param DashboardInterface $dashboard
  *
  * @return Div
  */
 public function getIssues(DashboardInterface $dashboard)
 {
     $exceptions = Std::map(function (Exception $exception, $moduleName) {
         return new Div([], [new Div(['class' => 'card card-inverted'], [new CardBlock([], [new HeaderSix(['class' => 'text-muted'], $moduleName), new Bold([], get_class($exception) . ': '), $exception->getMessage(), new Div(['class' => 'collapse p-t', 'id' => 'stack'], new PreformattedText(['class' => 'pre-scrollable'], $exception->getTraceAsString()))]), new Div(['class' => 'card-footer text-muted'], [new Row([], [new Column(['medium' => 6], [basename($exception->getFile()) . ':' . $exception->getLine()]), new Column(['medium' => 6, 'class' => 'text-xs-right'], new Button(['href' => '#', 'class' => ['btn', 'btn-sm', 'btn-primary-outline'], 'data-toggle' => 'collapse', 'data-target' => '#stack', 'aria-expanded' => 'false', 'aria-controls' => '#stack'], 'Toggle stacktrace'))])])])]);
     }, $dashboard->getFailedModules());
     return new Div([], [new Div(['class' => 'card'], [new Div(['class' => 'card-header'], 'Module issues'), new Div(['class' => 'card-block'], ['Below you will find a list of all the modules that ', 'failed to load. If one or more failed to load, it is ', 'not necessarily a bad thing. If you do not intend to ', 'use the component covered by the module, you may ', 'safely ignore it.'])]), new HorizontalLine([]), new Div([], Std::firstBias(count($dashboard->getFailedModules()) > 0, $exceptions, function () {
         return new Card(['class' => 'card card-block text-center'], ['All modules seem fine!']);
     }))]);
 }
예제 #17
0
 /**
  * Get the type of each field.
  *
  * @return array
  */
 public function getTypes()
 {
     if ($this->spec instanceof Spec) {
         return Std::map(function ($field) {
             if ($field instanceof AbstractConstraint) {
                 return $field->toString();
             }
             return implode(' ^ ', Std::map(function ($innerField) {
                 if ($innerField instanceof Spec) {
                     return '{spec}';
                 } elseif ($innerField instanceof AbstractConstraint) {
                     return $innerField->toString();
                 }
                 return '{???}';
             }, $field));
         }, $this->spec->getConstraints());
     }
     return [];
 }
 /**
  * Render a table showing jobs.
  *
  * @param Paginator $jobs
  *
  * @return mixed
  */
 protected function renderJobsTable(Paginator $jobs)
 {
     return Std::firstBias(count($jobs->items()) > 0, function () use($jobs) {
         return new SimpleTable(['ID', 'Task', 'State', 'Runs', 'Created At', 'Duration'], Std::map(function (Job $job) {
             return [$job->id, $job->state, $job->task, $job->attempts, $job->created_at->toDayDateTimeString(), $job->getExecutionTime()];
         }, $jobs->items()));
     }, function () {
         return new CardBlock(['class' => 'card-block text-center'], [new Paragraph([], [new Italic(['class' => 'fa fa-4x fa-search text-light'])]), 'No jobs found matching the specified criteria.']);
     });
 }
 /**
  * @param Spec $spec
  * @param string $field
  *
  * @return TableRow
  */
 protected function renderConstraint(Spec $spec, $field)
 {
     $constraints = $spec->getConstraints();
     $defaults = $spec->getDefaults();
     $default = '';
     if (array_key_exists($field, $defaults)) {
         $default = $defaults[$field];
     }
     $constraint = $constraints[$field];
     if ($constraint instanceof AbstractConstraint) {
         return new TableRow([], [new TableCell([], $field), new TableCell([], $constraint->toString()), new TableCell([], (string) $default)]);
     }
     return new TableRow([], [new TableCell([], $field), new TableCell([], Std::map(function (AbstractConstraint $constraint) {
         return $constraint->toString() . ', ';
     }, $constraint)), new TableCell([], (string) $default)]);
 }
예제 #20
0
 public function benchMap()
 {
     Std::map(function ($value, $key) {
         return $value . ' ' . $key;
     }, $this->keyValueArray);
 }
예제 #21
0
 /**
  * Get an array representation of this object.
  *
  * @return array
  */
 public function toArray()
 {
     return RamlUtils::filterEmptyValues(['description' => $this->description, 'type' => $this->type, 'describedBy' => RamlUtils::filterEmptyValues(['headers' => Std::map(function (RamlParameter $header) {
         return $header->toArray();
     }, $this->headers), 'queryParameters' => Std::map(function (RamlParameter $query) {
         return $query->toArray();
     }, $this->queryParameters), 'responses' => $this->responses ? $this->responses->toArray() : null]), 'settings' => $this->settings]);
 }
예제 #22
0
 /**
  * Apply a function to this functor.
  *
  * @param callable $closure
  *
  * @return FunctorInterface
  */
 public function fmap(callable $closure)
 {
     return static::of(Std::map($closure, $this->value));
 }
예제 #23
0
 public function testMap()
 {
     $doubler = function ($item) {
         return $item * 2;
     };
     $list = new SplDoublyLinkedList();
     $list->push(1);
     $list->push(3);
     $list->push(4);
     $list->push(5);
     $this->assertEqualsMatrix([[[2, 6, 8, 10], Std::map($doubler, [1, 3, 4, 5])], [[2, 6, 8, 10], Std::map($doubler, $list)]]);
 }