/**
  * 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', [])));
 }
Exemple #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();
 }
 /**
  * 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']));
 }
 /**
  * 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;
 }
 /**
  * Parse and build a rich response object from an HTTP response.
  *
  * @param ResponseInterface $response
  *
  * @return SubscriptionResponse
  * @throws CoreException
  */
 public function makeFromResponse(ResponseInterface $response)
 {
     $body = $this->parse($response);
     $subscriptionsResponse = new SubscriptionResponse();
     $subscriptionsResponse->setSubscriptions(Std::map(function ($s) {
         $subscription = new Subscription();
         // Maps from the new subscription format from SLAPP
         // to the legacy format.
         $subscription->fill(['id' => Arr::dotGet($s, 'stripe_plan.id'), 'plan_id' => $s['stripe_plan_id'], 'cycle_length' => sprintf('%s %s', Arr::dotGet($s, 'stripe_plan.interval_count'), Arr::dotGet($s, 'stripe_plan.interval')), 'created_at' => $s['current_period_start'], 'expires_at' => $s['current_period_end'], 'autorenew' => !$s['cancel_at_period_end'], 'cancelled_at' => $s['canceled_at'], 'status' => $s['status']]);
         return $subscription;
     }, Arr::dotGet($body, 'subscriptions', [])));
     return $subscriptionsResponse;
 }
 /**
  * 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())))]);
 }
 /**
  * Report errors to the alerts manager and redirect to a page.
  *
  * @param CheckableInterface $check
  * @param CheckResultInterface $result
  */
 public function handleFailure(CheckableInterface $check, CheckResultInterface $result)
 {
     $response = $this->redirector->to($this->getRedirectUrl())->withInput($this->request->except($this->dontFlash));
     if (count($result->getFailed())) {
         if ($check instanceof Validator) {
             $messages = Std::map(function ($value) {
                 return implode(', ', $value);
             }, $result->getFailed());
             $this->pushValidationAlert($messages);
         } else {
             $this->pushValidationSpecAlert($result);
         }
     }
     if (count($result->getMissing())) {
         $this->pushMissingAlert($result->getMissing());
     }
     throw new HttpResponseException($response);
 }
 /**
  * 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:
             case Alert::TYPE_VALIDATION:
                 $classes[] = 'alert-danger';
                 break;
         }
         return new Div(['class' => $classes], $alert->getContent());
     }, $this->alerts));
 }
 /**
  * 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]);
 }
 /**
  * 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::thunk($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;
 }
 /**
  * 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!']);
     }))]);
 }
 /**
  * Get an array representation of this object.
  *
  * @return array
  */
 public function toArray()
 {
     return Std::map(function (RamlBody $body) {
         return $body->toArray();
     }, $this->bodyTypes);
 }
Exemple #13
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()))]);
 }
Exemple #15
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)]]);
 }
 /**
  * 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));
 }
 /**
  * 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);
 }
 /**
  * @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)]);
 }
 /**
  * Get an array representation of this object.
  *
  * @return array
  */
 public function toArray()
 {
     return Std::map(function (RamlResponse $response) {
         return $response->toArray();
     }, $this->responses);
 }
Exemple #20
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)]);
 }
 /**
  * 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.']);
     });
 }
Exemple #22
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 [];
 }
Exemple #23
0
 public function benchMap()
 {
     Std::map(function ($value, $key) {
         return $value . ' ' . $key;
     }, $this->keyValueArray);
 }