/** * Creates a new {@link LightInstruction}, verifying the action is valid and exactly two * coordinates have been given. * * @param int $action {@link LightInstructionAction} * @param Coordinate[] $coordinatePair two coordinates * @return LightInstruction * @throws \InvalidArgumentException */ public static function create($action, array $coordinatePair) { v::oneOf(v::equals(LightInstructionAction::TURN_ON), v::equals(LightInstructionAction::TURN_OFF), v::equals(LightInstructionAction::TOGGLE))->check($action); v::length(2, 2)->check($coordinatePair); v::each(v::instance('\\Hamdrew\\AdventOfCode\\Day6\\Coordinate'))->check($coordinatePair); return new LightInstruction($action, $coordinatePair); }
protected function validate_items($items) { $validator = Validator::instance($this->collection_of()); foreach ($items as $item) { $this->assert()->is($validator, $item); } }
public function __construct(array $options) { $options = ['baseUri' => Arr::get($options, 'baseUri', $this->baseUri), 'timeout' => Arr::get($options, 'timeout', $this->timeout), 'proxy' => Arr::get($options, 'proxy', $this->proxy), 'auth' => Arr::get($options, 'auth', $this->auth), 'logger' => Arr::get($options, 'logger')]; try { V::arrayVal()->key('baseUri', V::url()->notEmpty())->key('timeout', V::floatVal()->min(0))->key('proxy', V::optional(V::url()))->key('auth', V::arrayVal()->key('user', V::stringType())->key('pass', V::stringType()))->key('logger', V::instance('\\Psr\\Log\\LoggerInterface'))->assert($options); } catch (\InvalidArgumentException $e) { $errors = array_filter($e->findMessages(['baseUri' => 'Required correct baseUri', 'timeout' => 'Required correct timeout', 'proxy' => 'Required correct proxy', 'auth' => 'Required correct authuser', 'logger' => 'Required a logger instance of psr\\log'])); $errmsg = array_shift($errors); throw new Exception($errmsg); } $this->baseUri = $options['baseUri']; $this->timeout = $options['timeout']; $this->proxy = $options['proxy']; $this->auth = $options['auth']; $this->logger = $options['logger']; }
protected function getValidationRules() { v::with('app\\Models\\Validation\\'); return [v::attribute('name', v::notEmpty()->alpha()->length(2, 100)->UniqueDimensionUOMName()), v::attribute('symbol', v::notEmpty()->alpha()->length(2, 2)->UniqueDimensionUOMSymbol()), v::attribute('routeTransaction', v::instance('app\\Models\\RouteTransaction')), v::attribute('statusId', v::notEmpty()->int()->positive()), v::attribute('createdAt', v::notEmpty()->date()), v::attribute('expiresAt', v::notEmpty()->date())]; }
/** * Send messages in bulk. * * @param Message[] $messages * @param array $params * * @return mixed */ public function sendBulkMessages(array $messages, array $params = null) { $sender = $this->createBulkSender(); v::notEmpty()->setName("BulkSms Array")->check($messages); foreach ($messages as $message) { // make sure messages are proper objects v::instance('anlutro\\BulkSms\\Message')->check($message); $sender->addMessage($message); } if ($params) { $sender->setParams($params); } $response = $sender->send($this->testMode); $this->validateResponse($response); return $sender->extractResponse($response); }
protected function getValidationRules() { v::with('app\\Models\\Validation\\'); return [v::attribute('provider', v::oneOf(v::instance('app\\Models\\Provider'))), v::attribute('carrier', v::oneOf(v::instance('app\\Models\\Carrier'))), v::attribute('name', v::notEmpty()->length(3, 100)->alpha()->UniqueProviderName()), v::attribute('symbol', v::notEmpty()->length(3, 100)->UniqueProviderSymbol()), v::attribute('routeTransaction', v::instance('app\\Models\\RouteTransaction')), v::attribute('statusId', v::notEmpty()->int()->positive()), v::attribute('createdAt', v::notEmpty()->date()), v::attribute('expiresAt', v::notEmpty()->date())]; }
/** * * @param \DateTime $logDate * @return boolean */ public function logDate($logDate) : bool { return V::instance('DateTime')->validate($logDate); }