/** * Construct an instance of a ResourceMethod. * * @param string $method * @param string $verb * @param string $path */ public function __construct($method, $verb, $path) { parent::__construct(); Arguments::contain(Boa::string(), Boa::string(), Boa::string())->check($method, $verb, $path); $this->method = $method; $this->verb = $verb; $this->path = $path; }
/** * Register a module with this dashboard. * * @param string $moduleClassName * * @throws CoreException * @throws InvalidArgumentException */ public function register($moduleClassName) { Arguments::contain(Boa::string())->check($moduleClassName); $instance = $this->application->make($moduleClassName); if (!$instance instanceof Module) { throw new InvalidArgumentException('The provided class should extend the Module class.'); } try { $instance->boot(); $this->modules[$instance->getName()] = $instance; } catch (Exception $e) { $this->failedModules[$instance->getName()] = $e; } }
/** * Add a offer to the response. * * @param string $type * @param string $condition * @param Offer $offer * * @throws InvalidArgumentException */ public function addOffer($type, $condition, Offer $offer) { Arguments::contain(Boa::in(OfferType::getValues()), Boa::in(OfferCondition::getValues()), Boa::instance(Offer::class))->check($type, $condition, $offer); if ($type === OfferType::TYPE_FBA) { if ($condition === OfferCondition::CONDITION_NEW) { $this->fbaNewOffers[] = $offer; } elseif ($condition === OfferCondition::CONDITION_USED) { $this->fbaUsedOffers[] = $offer; } } elseif ($type === OfferType::TYPE_MERCHANT_FULFILLED) { if ($condition === OfferCondition::CONDITION_NEW) { $this->merchantNewOffers[] = $offer; } elseif ($condition === OfferCondition::CONDITION_USED) { $this->merchantUsedOffers[] = $offer; } } }
/** * Get a category by ID * * @param string $categoryId * * @return GetCategoryByIdResponse */ public function getCategoryById($categoryId) { Arguments::contain(Boa::string())->check($categoryId); return (new CategoryResponseFactory())->makeFromResponse($this->client->get(vsprintf('/v1/getCategoryById/%s', [$categoryId]))); }
/** * Set a relationship of the model explicitly. * * @param string $relationName * @param Model|Model[] $related * * @throws LackOfCoffeeException * @throws InvalidArgumentException * @return $this */ public function withFixed($relationName, $related) { $inspector = $this->getInspector($this->getModelInstance()); $relation = $inspector->getRelation($relationName); $relationModelClass = get_class($relation->getRelated()); Arguments::contain(Boa::string(), Boa::either(Boa::instance($relationModelClass), Boa::arrOf(Boa::instance($relationModelClass))))->check($relationName, $related); $this->relations[$relationName] = $relation; $this->relationsGenerators[$relationName] = $related; return $this; }
/** * Set the new status for this response. * * @param string $newStatus * * @throws InvalidArgumentException */ public function setStatus($newStatus) { Arguments::contain(Boa::in($this->getValidStatuses()))->check($newStatus); $this->status = $newStatus; }
/** * Set the HTTP method using the request. * * @param $method * * @throws InvalidArgumentException * @return $this */ public function usingMethod($method) { Arguments::contain(Boa::in(HttpMethods::getValues()))->check($method); $this->method = $method; return $this; }
/** * Get a model by its id. * * @param int $id * @param array $columns * @param array $with * * @throws InvalidArgumentException * @throws LackOfCoffeeException * @return Model */ public function getById($id, array $columns = ['*'], array $with = []) { Arguments::contain(Boa::integer(), Boa::arrOf(Boa::string()), Boa::arrOf(Boa::string()))->check($id, $columns, $with); $query = $this->makeModelInstance()->query()->where('id', $id); $this->applyWith($query, $with); return $query->firstOrFail($columns); }