sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
public function handleServiceRequest( ServiceRequestInterface $request, $service, $resource = null, $check_permission = true, $throw_exception = true ) { if ($check_permission) { if (false === Session::checkServicePermission($request->getMethod(), $service...
@param ServiceRequestInterface $request @param string $service @param string|null $resource @param bool $check_permission @param bool $throw_exception @return \DreamFactory\Core\Contracts\ServiceResponseInterface @throws \Exception
entailment
public function handleRequest( $service, $verb = Verbs::GET, $resource = null, $query = [], $header = [], $payload = null, $format = null, $check_permission = true, $throw_exception = false ) { if ($check_permission === true) { ...
@param string $service @param string $verb @param string|null $resource @param array $query @param array $header @param null $payload @param string|null $format @param bool $check_permission @param bool $throw_exception @return \DreamFactory\Core\Contracts\ServiceResponseInte...
entailment
protected function makeService($name) { $config = $this->getConfig($name); // First we will check by the service name to see if an extension has been // registered specifically for that service. If it has we will call the // Closure and pass it the config allowing it to resolve the ...
Make the service instance. @param string $name @return \DreamFactory\Core\Contracts\ServiceInterface @throws \DreamFactory\Core\Exceptions\NotFoundException
entailment
protected function getConfig($name) { if (empty($name)) { throw new InvalidArgumentException("Service 'name' can not be empty."); } $services = $this->app['config']['df.service']; return array_get($services, $name); }
Get the configuration for a service. @param string $name @return array @throws \InvalidArgumentException
entailment
protected function getDbConfig($name) { if (empty($name)) { throw new InvalidArgumentException("Service 'name' can not be empty."); } return \Cache::rememberForever('service_mgr:' . $name, function () use ($name) { /** @var Service $service */ if (empty($...
Get the configuration for a service. @param string $name @return array @throws \DreamFactory\Core\Exceptions\NotFoundException
entailment
public function up() { $driver = Schema::getConnection()->getDriverName(); // Even though we take care of this scenario in the code, // SQL Server does not allow potential cascading loops, // so set the default no action and clear out created/modified by another user when deleting a ...
Run the migrations. @return void
entailment
public function boot(Router $router, DispatcherContract $events) { $this->baseDir = __DIR__.'/../'; $this->setPublishables(); $this->loadStaticFiles(); $this->registerAliases(); $this->namespace = config('forum.frontend.controllers.namespace'); $this->registerListe...
Perform post-registration booting of services. @param Router $router @param DispatcherContract $events @return void
entailment
public function registerListeners(DispatcherContract $events) { foreach ($this->listen as $event => $listeners) { foreach ($listeners as $listener) { $events->listen($event, $listener); } } }
Register event listeners. @param DispatcherContract $events @return void
entailment
protected function loadRoutes(Router $router) { $router->group([ 'namespace' => $this->namespace, 'middleware' => config('forum.frontend.middleware'), 'as' => config('forum.routing.as'), 'prefix' => config('forum.routing.prefix') ], function ($router) ...
Load routes. @param Router $router @return void
entailment
public function import() { switch ($this->serviceGroupType) { case ServiceTypeGroups::DATABASE: $header = $this->getHeader(); if ($this->createDbTableFromHeader($header)) { try { $this->importData(); ...
Imports CSV data @return bool @throws \DreamFactory\Core\Exceptions\BadRequestException @throws \Exception
entailment
public function revert() { switch ($this->serviceGroupType) { case ServiceTypeGroups::DATABASE: if ($this->resourceExists('_schema/' . $this->resource)) { /** @var \DreamFactory\Core\Contracts\ServiceResponseInterface $rs */ $rs = ServiceMa...
Reverts partial import after failure @return bool @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
entailment
protected function setService($serviceName) { if (empty($serviceName)) { throw new InternalServerErrorException('No target service name provided for CSV import.'); } $this->service = ServiceManager::getService($serviceName); $this->serviceGroupType = $this->service->getSe...
Sets the target service @param $serviceName @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
entailment
protected function getHeader() { ini_set('auto_detect_line_endings', true); if (($handle = fopen($this->file, "r")) !== false) { $header = fgetcsv($handle, 0, ','); static::isHeader($header); return $header; } else { throw new InternalServerEr...
Fetches CSV header @return array @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
entailment
protected function createDbTableFromHeader($header) { if (empty($this->resource)) { $this->resource = 'import_' . time(); } if (!$this->resourceExists('_schema/' . $this->resource)) { $schema = $this->createSchemaFromHeader($header); $this->createTable($sc...
Creates DB table based on CSV header row @param $header @return bool @throws \DreamFactory\Core\Exceptions\BadRequestException
entailment
protected function createSchemaFromHeader($header) { $schema = [ 'name' => $this->resource, 'label' => ucfirst($this->resource), 'description' => 'Table created from CSV data import', 'plural' => ucfirst(str_plural($this->resource)), ...
Creates table schema definition based on CSV header @param array $header @return array
entailment
protected function resourceExists($resource) { /** @var \DreamFactory\Core\Contracts\ServiceResponseInterface $rs */ $rs = ServiceManager::handleRequest($this->service->getName(), Verbs::GET, $resource); if ($rs->getStatusCode() === HttpStatusCodes::HTTP_NOT_FOUND) { return false...
Checks to see if target resource already exists or not @param $resource @return bool
entailment
protected function createTable($schema) { /** @var \DreamFactory\Core\Contracts\ServiceResponseInterface $rs */ $rs = ServiceManager::handleRequest( $this->service->getName(), Verbs::POST, '_schema', [], [], ResourcesWrapper::wr...
Creates import table @param $schema @return bool @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
entailment
protected function importData() { if (($handle = fopen($this->file, "r")) !== false) { $header = fgetcsv($handle, 0, ','); $result = []; while (false !== ($row = fgetcsv($handle))) { $new = []; foreach ($header as $key => $value) { ...
Imports CSV data @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
entailment
protected function insertTableData(& $data, $useQueue = true) { $job = new DBInsert($this->service->getName(), $this->resource, $data); if ($useQueue !== true) { $job->onConnection('sync'); } dispatch($job); $data = []; }
Inserts data into table @param $data @param bool $useQueue
entailment
protected function setImporter($file, $service, $resource) { switch ($this->extension) { case CSV::FILE_EXTENSION: $this->importer = new CSV($file, $service, $resource); break; default: throw new BadRequestException('Importing file type...
@param string $file @param string $service @param null|string $resource @throws \DreamFactory\Core\Exceptions\BadRequestException
entailment
protected function verifyUploadedFile(array $file) { if (is_array($file['error'])) { throw new BadRequestException("Only a single file is allowed for import."); } if (UPLOAD_ERR_OK !== ($error = $file['error'])) { throw new InternalServerErrorException( ...
Verifies the uploaed file for importing process. @param array $file @return string @throws \DreamFactory\Core\Exceptions\BadRequestException @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
entailment
protected function verifyImportFromUrl($url) { $this->checkFileExtension($url); try { // need to download and extract zip file and move contents to storage $file = FileUtilities::importUrlFileToTemp($url); } catch (\Exception $ex) { throw new InternalServe...
Verifies file import from url. @param $url @return string @throws \DreamFactory\Core\Exceptions\BadRequestException @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
entailment
protected function checkFileExtension($filename) { $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if (!in_array($extension, static::FILE_EXTENSION)) { throw new BadRequestException( "Unsupported file type. Supported types are " . implode(', ', static::F...
@param $filename @throws \DreamFactory\Core\Exceptions\BadRequestException
entailment
public function getSchemaExtension($name, ConnectionInterface $conn) { if (isset($this->extensions[$name])) { return call_user_func($this->extensions[$name], $conn); } return null; }
Return the schema extension object. @param string $name @param ConnectionInterface $conn @return DbSchemaInterface
entailment
public static function create( $content, $content_type = null, $status = ServiceResponseInterface::HTTP_OK, $headers = [] ) { return new ServiceResponse($content, $content_type, $status, $headers); }
@param mixed $content @param string|null $content_type @param int $status @param array|null $headers @return ServiceResponse
entailment
public static function sendResponse( ServiceResponseInterface $response, ServiceRequestInterface $request = null, $asFile = null, $resource = 'resource' ) { $accepts = static::getAcceptedTypes($request); if (empty($asFile)) { $asFile = \Request::input('fi...
@param ServiceResponseInterface $response @param ServiceRequestInterface|null $request @param null $asFile @param string $resource @return \Symfony\Component\HttpFoundation\Response @throws \DreamFactory\Core\Exceptions\NotImplementedException
entailment
public static function sendScriptResponse(ServiceResponseInterface $response) { $content = $response->getContent(); $contentType = $response->getContentType(); $format = $response->getDataFormat(); $headers = $response->getHeaders(); $status = $response->getStatusCode(); ...
@param ServiceResponseInterface $response @return array|mixed|string
entailment
public static function sendException(\Exception $e, ServiceRequestInterface $request = null) { $response = static::exceptionToServiceResponse($e); return ResponseFactory::sendResponse($response, $request); }
@param \Exception $e @param ServiceRequestInterface $request @return array|mixed|string @throws \DreamFactory\Core\Exceptions\NotImplementedException
entailment
protected static function makeExceptionContent(\Exception $exception) { if ($exception instanceof DfException) { return ['error' => $exception->toArray()]; } $errorInfo['code'] = ($exception->getCode()) ?: ServiceResponseInterface::HTTP_INTERNAL_SERVER_ERROR; $errorInfo[...
@param \Exception $exception @return array
entailment
public function setMethod($verb) { if (!Verbs::contains($verb)) { throw new \Exception("Invalid method '$verb'"); } $this->method = $verb; return $this; }
@param $verb @return $this @throws \Exception
entailment
public function getParameter($key = null, $default = null) { if (is_null($this->parameters)) { return $default; } if (null === $key) { return $this->parameters; } else { return array_get($this->parameters, $key, $default); } }
{@inheritdoc}
entailment
public function getParameterAsBool($key, $default = false) { if (is_null($this->parameters)) { return $default; } return array_get_bool($this->parameters, $key, $default); }
@param mixed $key @param bool $default @return mixed
entailment
public function setContent($data, $type = DataFormats::PHP_ARRAY) { $this->content = $data; switch ($type) { case DataFormats::PHP_ARRAY: $this->contentAsArray = $data; $this->contentType = ''; // this could be null, but may cause issues with clients ...
@param mixed $data @param int $type @return $this @throws \DreamFactory\Core\Exceptions\NotImplementedException
entailment
public function getPayloadData($key = null, $default = null) { if (null === $key) { return $this->contentAsArray; } else { return array_get($this->contentAsArray, $key, $default); } }
{@inheritdoc}
entailment
public function getHeader($key = null, $default = null) { if (is_null($this->headers)) { return $default; } if (null === $key) { return $this->headers; } else { return array_get($this->headers, $key, $default); } }
{@inheritdoc}
entailment
public function getApiKey() { //Check for API key in request parameters. $apiKey = $this->getParameter('api_key'); if (empty($apiKey)) { //Check for API key in request HEADER. $apiKey = $this->getHeader('X_DREAMFACTORY_API_KEY'); } return $apiKey; ...
{@inheritdoc}
entailment
public function input($key = null, $default = null) { return $this->getParameter($key, $this->getPayloadData($key, $default)); }
Returns request input. @param null $key @param null $default @return array|string
entailment
public function up() { if (Schema::hasColumn('system_config', 'login_with_user_name')) { if ('sqlsrv' == DB::connection()->getDriverName()) { $defaultContraint = DB::selectOne("SELECT OBJECT_NAME([default_object_id]) AS name FROM SYS.COLUMNS WHERE [object_id] = OBJECT_ID('[dbo].[...
Run the migrations. @return void
entailment
public function getValueAttribute($value) { if (!is_array($value)) { $decodedValue = json_decode($value, true); } //Not a JSON string. if (!empty($value) && empty($decodedValue)) { $decodedValue = $value; } return $decodedValue; }
@param $value @return mixed
entailment
public function count(): int { if (gmp_cmp($this->nb_blocks, PHP_INT_MAX) > 0) { throw new \RuntimeException('The number of address blocks is bigger than PHP_INT_MAX, use getNbBlocks() instead'); } return gmp_intval($this->nb_blocks); }
{@inheritdoc}
entailment
public function next() { $this->position = gmp_add($this->position, 1); $this->current_block = $this->current_block->plus(1); }
{@inheritdoc}
entailment
public function valid(): bool { return gmp_cmp($this->position, 0) >= 0 && gmp_cmp($this->position, $this->nb_blocks) < 0; }
{@inheritdoc}
entailment
public static function arrayToMask($array) { $mask = self::NONE_MASK; if (empty($array) || !is_array($array)) { return $mask; } foreach ($array as $verb) { switch ($verb) { case self::GET: $mask |= self::GET_MASK; ...
@param array $array @return int
entailment
public static function maskToArray($mask) { $array = array(); if (empty($mask) || !is_int($mask)) { return $array; } if ($mask & self::GET_MASK) { $array[] = self::GET; } if ($mask & self::POST_MASK) { $array[] = self::POST; ...
@param int $mask @return string
entailment
public function setSource($source): void { if (!\is_string($source)) { throw new Grid\GridException('Source of `SqlSource` should be string with SQL query'); } parent::setSource($source); }
Set SQL source @param string $source @return void @throws \Bluz\Grid\GridException
entailment
public function process(int $page, int $limit, array $filters = [], array $orders = []): Data { // process filters $filters = $this->applyFilters($filters); // process orders $orders = $this->applyOrders($orders); // prepare query $type = Proxy\Db::getOption('connec...
{@inheritdoc}
entailment
private function applyFilters(array $settings): array { $where = []; foreach ($settings as $column => $filters) { foreach ($filters as $filter => $value) { if ($filter === Grid\Grid::FILTER_LIKE) { $value = '%' . $value . '%'; } ...
Apply filters to SQL query @param array[] $settings @return array
entailment
private function applyOrders(array $settings): array { $orders = []; // Obtain a list of columns foreach ($settings as $column => $order) { $column = Proxy\Db::quoteIdentifier($column); $orders[] = $column . ' ' . $order; } return $orders; }
Apply order to SQL query @param array $settings @return array
entailment
public function setFoo($arg1, $arg2 = 0) { /* * This is a "Block Comment." The format is the same as * Docblock Comments except there is only one asterisk at the * top. phpDocumentor doesn't parse these. */ if (is_int($arg1)) { throw new \Exception("Fi...
Registers the status of foo's universe Summaries for methods should use 3rd person declarative rather than 2nd person imperative, beginning with a verb phrase. Summaries should add description beyond the method's name. The best method names are "self-documenting", meaning they tell you basically what the method does....
entailment
public static function toCamelCase($subject): string { $subject = str_replace(['_', '-'], ' ', strtolower($subject)); return str_replace(' ', '', ucwords($subject)); }
Convert string to CamelCase @param string $subject @return string
entailment
public function save() { $this->beforeSave(); /** * If the primary key is empty, this is an INSERT of a new row. * Otherwise check primary key updated or not, if it changed - INSERT * otherwise UPDATE */ if (!\count(\array_filter($this->getPrimaryKey()))) ...
Saves the properties to the database. This performs an intelligent insert/update, and reloads the properties with fresh data from the table on success. @return mixed The primary key value(s), as an associative array if the key is compound, or a scalar if the key is single-column @throws DbException @throws InvalidPri...
entailment
protected function doInsert() { /** * Run pre-INSERT logic */ $this->beforeInsert(); $data = $this->toArray(); /** * Execute validator logic * Can throw ValidatorException */ $this->assert($data); $table = $this->getTable...
Insert row to Db @return mixed The primary key value(s), as an associative array if the key is compound, or a scalar if the key is single-column @throws InvalidPrimaryKeyException @throws TableNotFoundException
entailment
protected function doUpdate(): int { /** * Run pre-UPDATE logic */ $this->beforeUpdate(); $data = $this->toArray(); /** * Execute validator logic * Can throw ValidatorException */ $this->assert($data); $primaryKey = $thi...
Update row @return integer The number of rows updated @throws InvalidPrimaryKeyException @throws TableNotFoundException
entailment
public function delete(): bool { /** * Execute pre-DELETE logic */ $this->beforeDelete(); $primaryKey = $this->getPrimaryKey(); /** * Execute the DELETE (this may throw an exception) */ $table = $this->getTable(); $result = $table...
Delete existing row @return bool Removed or not @throws InvalidPrimaryKeyException @throws TableNotFoundException
entailment
protected function getPrimaryKey(): array { $primary = array_flip($this->getTable()->getPrimaryKey()); return array_intersect_key($this->toArray(), $primary); }
Retrieves an associative array of primary keys, if it exists @return array @throws InvalidPrimaryKeyException @throws TableNotFoundException
entailment
public function execute($sequence = null) { $result = Db::query($this->getSql(), $this->params, $this->types); if ($result) { return Db::handler()->lastInsertId($sequence); } return $result; }
{@inheritdoc} @param null $sequence @return integer|string|array
entailment
public function process(): void { /** @var \Closure|object $closure */ $closure = include $this->file; if (!\is_callable($closure)) { throw new ComponentException("There is no callable structure in file `{$this->file}`"); } $reflection = new \ReflectionFunction(...
Process to get reflection from file @return void @throws ComponentException @throws \ReflectionException
entailment
public function params($requestParams): array { // apply type and default value for request params $params = []; foreach ($this->params as $param => $type) { if (isset($requestParams[$param])) { switch ($type) { case 'bool': ...
Process request params - type conversion - set default value @param array $requestParams @return array
entailment
protected function prepareCache($cache): int { $num = (int)$cache; $time = 'min'; if ($pos = strpos($cache, ' ')) { $time = substr($cache, $pos); } switch ($time) { case 'day': case 'days': return $num * 86400; ...
Prepare Cache @param string $cache @return integer
entailment
public function setAccept($accept): void { // allow accept map $acceptMap = [ 'ANY' => Request::TYPE_ANY, 'HTML' => Request::TYPE_HTML, 'JSON' => Request::TYPE_JSON ]; $accept = strtoupper($accept); if (isset($acceptMap[$accept])) { ...
Set accepted types @param string $accept @return void
entailment
public function setParam($param): void { // prepare params data // setup param types if (strpos($param, '$') === false) { return; } [$type, $key] = preg_split('/[ $]+/', $param); $this->params[$key] = trim($type); }
Set param types @param string $param @return void
entailment
protected function initRoute(): void { foreach ($this->route as $route => &$pattern) { $pattern = $this->prepareRoutePattern($route); } }
Init Route @return void
entailment
protected function prepareRoutePattern($route): string { $pattern = str_replace('/', '\/', $route); foreach ($this->getParams() as $param => $type) { switch ($type) { case 'int': case 'integer': $pattern = str_replace("{\$$param}", "(?...
Prepare Route pattern @param string $route @return string
entailment
public static function getHeader($header, $default = null) { $header = strtolower($header); $headers = self::getInstance()->getHeaders(); $headers = array_change_key_case($headers, CASE_LOWER); if (array_key_exists($header, $headers)) { $value = \is_array($headers[$heade...
Search for a header value @param string $header @param mixed $default @return string
entailment
public static function getParams(): array { $body = (array)self::getInstance()->getParsedBody(); $query = (array)self::getInstance()->getQueryParams(); return array_merge([], $body, $query); }
Get all params from GET and POST or PUT @return array
entailment
public static function getClientIp($checkProxy = true) { $result = null; if ($checkProxy) { $result = self::getServer('HTTP_CLIENT_IP') ?? self::getServer('HTTP_X_FORWARDED_FOR') ?? null; } return $result ?? self::getServer('REMOTE_ADDR'); }
Get the client's IP address @param bool $checkProxy @return string
entailment
public static function getAccept(): array { if (!self::$accept) { // get header from request self::$accept = self::parseAcceptHeader(self::getHeader('Accept')); } return self::$accept; }
Get Accept MIME Type @return array
entailment
public static function getAcceptLanguage(): array { if (!self::$language) { // get header from request self::$language = self::parseAcceptHeader(self::getHeader('Accept-Language')); } return self::$language; }
Get Accept MIME Type @return array
entailment
private static function parseAcceptHeader($header): array { // empty array $accept = []; // check empty if (!$header || $header === '') { return $accept; } // make array from header $values = explode(',', $header); $values = array_map('tr...
parseAcceptHeader @param string $header @return array
entailment
public static function checkAccept(array $allowTypes = []) { $accept = self::getAccept(); // if no parameter was passed, just return first mime type from parsed data if (empty($allowTypes)) { return current(array_keys($accept)); } $allowTypes = array_map('strtol...
Check Accept header @param array $allowTypes @return string|false
entailment
public function addHelperPath(string $path): void { $class = static::class; $realPath = realpath($path); if (false === $realPath) { throw new CommonException("Invalid Helper path `$path` for class `$class`"); } // create store of helpers if (!isset(stati...
Add helper path @param string $path @return void @throws CommonException
entailment
private function loadHelper(string $name): void { $class = static::class; // Somebody forgot to call `addHelperPath` if (!isset(static::$helpersPath[$class])) { throw new CommonException("Helper path not found for class `$class`"); } // Try to find helper file ...
Call helper @param string $name @return void @throws CommonException
entailment
private function addHelper(string $name, string $path): void { $class = static::class; // create store of helpers for this class if (!isset(static::$helpers[$class])) { static::$helpers[$class] = []; } $helper = include $path; if (\is_callable($helper))...
Add helper callable @param string $name @param string $path @return void @throws CommonException
entailment
public function offsetSet($offset, $value): void { if (null === $offset) { throw new \InvalidArgumentException('Class `Common\Container\ArrayAccess` support only associative arrays'); } $this->doSetContainer($offset, $value); }
Offset to set @param mixed $offset @param mixed $value @throws \InvalidArgumentException
entailment
public function setIdentity(IdentityInterface $identity): void { // save identity to Auth $this->identity = $identity; // regenerate session if (PHP_SAPI !== 'cli') { Session::regenerateId(); } // save identity to session Session::set('auth:identit...
Setup identity @param IdentityInterface $identity @return void
entailment
public function getIdentity(): ?IdentityInterface { if (!$this->identity) { // check user agent if (Session::get('auth:agent') === Request::getServer('HTTP_USER_AGENT')) { $this->identity = Session::get('auth:identity'); } else { $this->cle...
Return identity if user agent is correct @return IdentityInterface|null
entailment
public function validate($input): bool { if (\is_array($this->haystack)) { return \in_array($input, $this->haystack, false); } if (!\is_string($this->haystack)) { return false; } if (empty($input)) { return false; } $enc ...
Check input data @param string $input @return bool
entailment
public function getDescription(): string { if (\is_array($this->haystack)) { $haystack = implode(', ', $this->haystack); } else { $haystack = $this->haystack; } return __('must be in "%s"', $haystack); }
Get error template @return string
entailment
public function processRequest(): void { $this->module = Request::getModule(); $this->controller = Request::getController(); $page = (int)Request::getParam($this->prefix . 'page', 1); $this->setPage($page); $limit = (int)Request::getParam($this->prefix . 'limit', $this->lim...
Process request Example of request url - http://domain.com/pages/grid/ - http://domain.com/pages/grid/page/2/ - http://domain.com/pages/grid/page/2/order-alias/desc/ - http://domain.com/pages/grid/page/2/order-created/desc/order-alias/asc/ with prefix for support more than one grid on page - http://domain.com/users/g...
entailment
public function processSource(): void { if (null === $this->adapter) { throw new GridException('Grid Adapter is not initiated, please update method `init()` and try again'); } try { $this->data = $this->getAdapter()->process( $this->getPage(), ...
Process source @return void @throws GridException
entailment
public function getParams(array $rewrite = []): array { $params = $this->params; // change page to first for each new grid (with new filters or orders, or other stuff) $page = $rewrite['page'] ?? 1; if ($page > 1) { $params[$this->prefix . 'page'] = $page; } ...
Return params prepared for url builder @param array $rewrite @return array
entailment
public function getUrl($params): string { // prepare params $params = $this->getParams($params); // retrieve URL return Router::getUrl( $this->getModule(), $this->getController(), $params ); }
Get Url @param array $params @return string
entailment
public function setAllowOrders(array $orders = []): void { $this->allowOrders = []; foreach ($orders as $column) { $this->addAllowOrder($column); } }
Set allow orders @param string[] $orders @return void
entailment
public function addOrder($column, $order = self::ORDER_ASC): void { if (!$this->checkOrderColumn($column)) { throw new GridException("Order for column `$column` is not allowed"); } if (!$this->checkOrderName($order)) { throw new GridException("Order name for column `...
Add order rule @param string $column @param string $order @return void @throws GridException
entailment
public function addOrders(array $orders): void { foreach ($orders as $column => $order) { $this->addOrder($column, $order); } }
Add order rules @param array $orders @return void @throws GridException
entailment
public function setOrder($column, $order = self::ORDER_ASC): void { $this->orders = []; $this->addOrder($column, $order); }
Set order @param string $column @param string $order ASC or DESC @return void @throws GridException
entailment
public function setAllowFilters(array $filters = []): void { $this->allowFilters = []; foreach ($filters as $column) { $this->addAllowFilter($column); } }
Set allowed filters @param string[] $filters @return void
entailment
protected function checkFilterColumn($column): bool { return array_key_exists($column, $this->getAllowFilters()) || \in_array($column, $this->getAllowFilters(), false); }
Check filter column @param string $column @return bool
entailment
public function addFilter($column, $filter, $value): void { if (!$this->checkFilterColumn($column)) { throw new GridException("Filter for column `$column` is not allowed"); } if (!$this->checkFilterName($filter)) { throw new GridException('Filter name is incorrect'); ...
Add filter @param string $column name @param string $filter @param string $value @return void @throws GridException
entailment
public function getFilter($column, $filter = null) { if (null === $filter) { return $this->filters[$column] ?? null; } return $this->filters[$column][$filter] ?? null; }
Get filter @param string $column @param string $filter @return mixed
entailment
public function setDefaultLimit(int $limit): void { if ($limit < 1) { throw new GridException('Wrong default limit value, should be greater than zero'); } $this->setLimit($limit); $this->defaultLimit = $limit; }
Set default limit @param integer $limit @return void @throws GridException
entailment
public function setDefaultOrder($column, $order = self::ORDER_ASC): void { $this->defaultOrder = [$column => $order]; }
Set default order @param string $column @param string $order ASC or DESC @return void
entailment
public function validate($input): bool { if (\is_string($input)) { $input = trim($input); } return (false !== $input) && (null !== $input) && ('' !== $input); }
Check input data @param mixed $input @return bool
entailment
public function setName($name): void { if ($this->sessionExists()) { throw new SessionException( 'Cannot set session name after a session has already started' ); } if (!preg_match('/^[a-zA-Z0-9]+$/', $name)) { throw new SessionException( ...
Attempt to set the session name If the session has already been started, or if the name provided fails validation, an exception will be raised. @param string $name @throws SessionException @return void
entailment
public function getName(): string { if (null === $this->name) { // If we're grabbing via session_name(), we don't need our // validation routine; additionally, calling setName() after // session_start() can lead to issues, and often we just need the name // in...
Get session name Proxies to {@link session_name()}. @return string
entailment
public function regenerateId($deleteOldSession = true): bool { if ($this->sessionExists() && session_id() !== '') { return session_regenerate_id((bool)$deleteOldSession); } return false; }
Regenerate id Regenerate the session ID, using session save handler's native ID generation Can safely be called in the middle of a session. @param bool $deleteOldSession @return bool
entailment
public function destroy(): void { if (!$this->cookieExists() || !$this->sessionExists()) { return; } session_destroy(); // send expire cookies $this->expireSessionCookie(); // clear session data unset($_SESSION[$this->getNamespace()]); }
Destroy/end a session @return void
entailment
protected function initAdapter(): bool { if (null === $this->adapter || 'files' === $this->adapter) { // try to apply settings if ($settings = $this->getOption('settings', 'files')) { $this->setSavePath($settings['save_path']); } return true; ...
Register Save Handler with ext/session Since ext/session is coupled to this particular session manager register the save handler with ext/session. @return bool @throws ComponentException
entailment
public function expireSessionCookie(): void { if (ini_get('session.use_cookies')) { $params = session_get_cookie_params(); setcookie( $this->getName(), '', $_SERVER['REQUEST_TIME'] - 42000, $params['path'], ...
Expire the session cookie Sends a session cookie with no value, and with an expiry in the past. @return void
entailment
protected function setSavePath($savePath): void { if (!is_dir($savePath) || !is_writable($savePath) ) { throw new ComponentException('Session path is not writable'); } session_save_path($savePath); }
Set session save path @param string $savePath @return void @throws ComponentException
entailment