/** * Get an array with only the specified keys of the provided array. * * @param array|null $included * * @return static */ public function only($included = []) { Arguments::define(Boa::either(Boa::arrOf(Boa::either(Boa::string(), Boa::integer())), Boa::null()))->check($included); if (is_null($included)) { return $this; } if (count($included) == 0) { return static::zero(); } return static::of(array_intersect_key($this->value, array_flip($included))); }
/** * Get an array with only the specified keys of the provided array. * * @param array $input * @param array|null $included * * @return array */ public static function only(array $input, $included = []) { Arguments::define(Boa::either(Boa::arrOf(Boa::either(Boa::string(), Boa::integer())), Boa::null()))->check($included); if (is_null($included)) { return $input; } if (count($included) == 0) { return []; } return array_intersect_key($input, array_flip($included)); }
/** * Generate an authorization code for the Research API server. * * @param null|integer $timestamp * * @return string */ public function generateCode($timestamp = null) { Arguments::contain(Boa::either(Boa::null(), Boa::integer()))->check($timestamp); $timestamp = Std::coalesce($timestamp, time() + 3600 * 3); $signature = md5(implode('', [$timestamp, $this->clientId, $this->secret])); return vsprintf('%s|%s|%s', [$timestamp, $this->clientId, $signature]); }
/** * Get all models paginated. * * @param array $columns * @param array $with * @param int $take * @param string $pageName * @param null|int $page * * @throws LackOfCoffeeException * @return LengthAwarePaginator */ public function getAllPaginated($columns = ['*'], $with = [], $take = 25, $pageName = 'page', $page = null) { Arguments::contain(Boa::arrOf(Boa::string()), Boa::arrOf(Boa::string()), Boa::integer(), Boa::string(), Boa::either(Boa::null(), Boa::integer()))->check($columns, $with, $take, $pageName, $page); $query = $this->makeModelInstance()->query(); $this->applyWith($query, $with); return $query->paginate($take, $columns, $pageName, $page); }