sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
protected function getVerboseChildrenName($modelClass) { $info = $this->getInformationRepository()->getByModelClass($modelClass); if ( ! $info) { return cms_trans('models.list-parents.models'); } return $info->labelPlural(); }
Returns name, plural for child records. @param $modelClass @return string
entailment
protected function resolveStrategyClass($strategy) { if ( ! str_contains($strategy, '.')) { $strategy = config('cms-models.strategies.list.sort-aliases.' . $strategy, $strategy); } if (class_exists($strategy) && is_a($strategy, SortStrategyInterface::class, true)) { ...
Resolves strategy assuming it is the class name or FQN of a sort interface implementation, or a configured alias. @param $strategy @return string|false returns full class namespace if it was resolved succesfully
entailment
protected function fireEvent($event, $halt = true) { if (! isset(static::$dispatcher)) { return true; } $method = $halt ? 'until' : 'fire'; return static::$dispatcher->{$method}( "admin.component.{$event}: " . static::class, $this ); ...
Fire the given event for the component @param string $event @param bool $halt @return bool
entailment
public function handle(ModelInformationRepositoryInterface $repository) { $model = $this->argument('model'); if ( ! $model) { $infos = $repository->getAll(); } else { $info = $repository->getByKey($model); if ( ! $info) { $info = $repo...
Execute the console command. @param ModelInformationRepositoryInterface $repository
entailment
public function handle() { /** @var \Illuminate\Database\Connection|CouchbaseConnection $connection */ $connection = $this->databaseManager->connection($this->option('database')); if ($connection instanceof CouchbaseConnection) { $bucket = $connection->openBucket($this->argument(...
Execute the console command
entailment
public function analyze($modelClass) { $information = new ModelInformation; $information->model = $modelClass; $information->original_model = $modelClass; $this->makeModelInstance($modelClass); foreach ($this->getSteps() as $stepClass) { /** @var Anal...
Analyzes a model and returns normalized information about it. @param string $modelClass FQN of model to analyze @return ModelInformationInterface
entailment
protected function makeModelInstance($class) { if ( ! class_exists($class)) { throw new UnexpectedValueException("Class '{$class}' does not exist"); } $instance = new $class; if ( ! $instance instanceof Model) { throw new UnexpectedValueException("Instance o...
Makes and sets instance of the model class and stores it. @param string $class @return $this
entailment
public function deleteConditionStrategy(string $strategy, array $parameters = []): Model { if ( ! array_has($this->main, 'delete_condition')) { $this->main['delete_condition'] = ''; } $this->main['delete_condition'] .= ($this->main['delete_condition'] ? '|' : '') . $strategy; ...
A strategy for allowing deletion (such as not being linked to from other models, etc) Multiple delete strategies may be set (they stack). @param string $strategy alias or FQN @param array $parameters scalar values in order @return Model
entailment
public function hasTimestamps(string $createdAttribute = null, string $updatedAttribute = null): Model { $this->main['timestamps'] = true; $this->main['timestamp_created'] = $createdAttribute ?: 'created_at'; $this->main['timestamp_updated'] = $updatedAttribute ?: 'updated_at'; ...
Model has timestamp columns @param string $createdAttribute defaults to 'created_at' @param string $updatedAttribute defaults to 'updated_at' @return Model|$this
entailment
protected function performStep() { if (count($this->model()->getGlobalScopes())) { $this->info->meta->disable_global_scopes = true; } }
Performs the analyzer step on the stored model information instance.
entailment
protected function checkActivePage($update = true) { $request = request(); $pageSetByRequest = $request->has('page') || $this->resetActivePage; $pageSizeSetByRequest = $request->filled('pagesize'); if ($update && $pageSetByRequest) { $this->activePage = $request->g...
Checks and sets the active sort settings. @param bool $update @return $this
entailment
protected function storeActivePageValuesInSession() { $this->getListMemory()->setPage($this->activePage); $this->getListMemory()->setPageSize($this->activePageSize); }
Stores the currently active page settings for the session.
entailment
protected function getModelPageSize() { $pageSize = $this->getModelInformation()->list->page_size; if (is_array($pageSize)) { return (int) head($pageSize); } return (int) $pageSize; }
Returns model defined default page size. @return int
entailment
protected function getPageSizeOptions() { $pageSizes = $this->getModelInformation()->list->page_size; if (is_array($pageSizes)) { return $pageSizes; } return config('cms-models.strategies.list.page-size-options', false); }
Returns the page size options that users can choose from. @return int[]|false
entailment
protected function getDefaultRowActionInstance() { // Make the first action that is allowed for the current user foreach ($this->getModelInformation()->list->default_action as $data) { $permissions = $data->permissions(); if ( ! empty($permissions) && ! cms_auth()->can($per...
Collects and returns (permitted) strategy instance for the default row click action. @return ActionStrategyInterface|false
entailment
public function decorate(array $rules, Model $model = null) { $this->rules = $rules; $this->model = $model; $this ->replaceTranslationPlaceholders() ->replaceKeyPlaceholders(); return $this->rules; }
Decorates given validation rules @param array $rules @param Model|null $model if updating, the model being updated @return array
entailment
protected function replaceKeyPlaceholders() { if ( ! $this->model) { return $this; } $placeholder = static::MODEL_KEY_PLACEHOLDER; foreach ($this->rules as $key => &$ruleSet) { if (is_string($ruleSet)) { $ruleSet = str_replace($placeholder,...
Decorates rules by replacing a model key value placeholder. @return $this
entailment
protected function replaceTranslationPlaceholders() { $locales = $this->getTranslationLocales(); $placeholder = $this->getTranslatedRulePlaceHolder(); $processed = []; // Detect and duplicate special rules for translated locales foreach ($this->rules as $key => $ruleSe...
Decorates rules by replacing translation placeholders and create rules per locale. @return $this
entailment
public function set($values) { $this->clear(); if (! is_array($values)) { $values = func_get_args(); } foreach ($values as $value) { $this->add($value); } return $this; }
{@inheritdoc}
entailment
protected function checkFilters() { if ($this->getModelInformation()->list->disable_filters) { return $this; } if ($this->getListMemory()->hasFilters()) { $this->retrieveFiltersFromSession(); } return $this; }
Checks and loads filters from the session. @return $this
entailment
protected function applyFilter($query) { if ($this->getModelInformation()->list->disable_filters) { return $this; } $filter = $this->makeFilter(); if ($filter) { $filter->apply($query); } return $this; }
Applies the current filters, if any, to the model's query builder. @param Builder $query @return $this
entailment
protected function updateFilters() { $request = request(); if ($request->filled('_clear')) { $this->filters = []; $resetPage = ! empty($this->filters); } else { $this->filters = $request->get('filter', []); $resetPage = true; } ...
Checks and sets the active sort settings. @return $this
entailment
protected function makeFilter() { $data = new ModelFilterData($this->getModelInformation(), $this->filters); return new ModelFilter($this->getModelInformation(), $data); }
Makes and returns filter instance given current context. @return ModelFilter
entailment
public function getReferenceForModel(Model $model, $strategy = null, $source = null) { return $this->getReferenceValue($model, $strategy, $source); }
Returns reference for a given model instance. @param Model $model @param string|null $strategy @param string|null $source @return string
entailment
public function getReferencesForModels($models, $strategy = null, $source = null) { $references = new Collection; if ( ! count($models)) { return $references; } /** @var Model $firstModel */ if ($models instanceof Collection) { $firstModel = $models-...
Returns list of references for a collection of model instances. Note: all models must be the same class! @param \ArrayAccess|Model[] $models @param string|null $strategy @param string|null $source @return Collection|string[] reference values, keyed by model key
entailment
public function getReferenceForModelMetaReferenceByKey(ModelMetaReferenceInterface $referenceData, $key) { $query = $this->getQueryBuilderForModelClass($referenceData->model()); /** @var Model $model */ $model = $query->find($key); if ( ! $model) return false; return $this...
Returns a reference for a model class, by meta reference data. @param ModelMetaReferenceInterface $referenceData @param $key @return string|false false if the model could not be found
entailment
public function getReferenceForModelMetaReferenceByModel(ModelMetaReferenceInterface $referenceData, Model $model) { return $this->getReferenceForModel($model, $referenceData->strategy(), $referenceData->source()); }
Returns a reference for a model instance, by meta reference data. @param ModelMetaReferenceInterface $referenceData @param Model $model @return string|false false if the model could not be found
entailment
public function getReferencesForModelMetaReference(ModelMetaReferenceInterface $referenceData, $search = null) { $modelClass = $referenceData->model(); $query = $this->getQueryBuilderForModelClass($modelClass); $this->applySortingToQueryBuilder( $query, $referenceDa...
Returns references for models by meta reference data, keyed by the model keys. @param ModelMetaReferenceInterface $referenceData @param string|null $search optional search string to limit results @return Collection keyed by model key (or class:key)
entailment
protected function getQueryBuilderForModelClass($modelClass) { if ( ! is_a($modelClass, Model::class, true)) { throw new UnexpectedValueException("{$modelClass} is not an Eloquent model."); } // If the targeted model is a CMS model, we can default back to its reference data ...
Returns @param string $modelClass @return Builder
entailment
protected function getQueryBuilderForNonCmsModelClass($modelClass) { if ( ! is_a($modelClass, Model::class, true)) { // @codeCoverageIgnoreStart throw new UnexpectedValueException("{$modelClass} is not an Eloquent model"); // @codeCoverageIgnoreEnd } /** ...
Returns a query builder instance for a given model class. @param string $modelClass @return \Illuminate\Database\Eloquent\Builder
entailment
protected function applyContextStrategyToQueryBuilder($query, $strategy, array $parameters = []) { $strategy = $this->resolveContextStrategy($strategy); if ( ! $strategy) return; $strategy->apply($query, $parameters); }
Applies a context strategy to a model query builder. @param Builder $query @param string|null $strategy @param array $parameters
entailment
protected function applySearchTermFilterToQueryBuilder($query, $target, $search) { // Make sure we have a target to work with $target = $target ?: $query->getModel()->getKeyName(); $this->applyFilterStrategyToQuery($query, $target, $search); return $this; }
Applies search term based filtering to a query builder. @param Builder $query @param string|null $target @param string $search @return $this
entailment
protected function applyFilterStrategyToQuery($query, $target, $value, $strategy = null) { if (null === $strategy) { $strategy = config('cms-models.meta-references.filter-strategy'); } $filter = $this->getFilterFactory()->make($strategy); $filter->apply($query, $target,...
Applies a filter strategy for 'searching' on the model query. @param Builder $query @param string $target @param string $value @param string|null $strategy the filter strategy to use, if not default
entailment
protected function applySortingToQueryBuilder($query, $source, $direction = 'asc', $strategy = null) { $source = $source ?: $query->getModel()->getKeyName(); // Prepare the sorting strategy if (null === $strategy) { $strategy = config('cms-models.meta-references.sort-strategy');...
Applies sorting to a query builder, based on source string. @param Builder $query @param string $source @param string $direction sorting direction: 'asc' or 'desc' @param string|null $strategy @return $this
entailment
protected function getModelRepositoryForInformation(ModelInformationInterface $information) { /** @var ModelRepositoryFactoryInterface $factory */ $factory = app(ModelRepositoryFactoryInterface::class); $modelRepository = $factory->make($information->modelClass()); $this->applyRepo...
Returns instance of a model repository for given model information. @param ModelInformationInterface $information @return ModelRepositoryInterface
entailment
public function defaultSortingStrategy(string $strategy): ModelList { if (is_string($this->main['default_sort'])) { $this->main['default_sort'] = [ $this->main['default_sort'] ]; $this->main['default_sort'][] = $strategy; return $this; } $this->main['def...
Set a sorting strategy to enable by default Stacks strategies if called more than once @param string $strategy alias/name or <FQN>@<method> for custom ordering @return ModelList|$this
entailment
public function rowClickAction(string $action): ModelList { if ( ! array_has($this->main, 'default_action')) { $this->main['default_action'] = []; } $this->main['default_action'][] = $action; return $this; }
Adds an action to be performed when clicking a row. Will stack if called multiple times, in order. The first action that is permitted, is performed. @param string $action action alias @return ModelList|$this
entailment
public function parentRelationActiveByDefault(string $relation): ModelList { $this->main['default_top_relation'] = $relation; if ( ! array_get($this->main, 'parents')) { // Assume the relation (= the field) if no parents set yet. $this->main['parents'] = [ [...
Hide everything but top-level list parents by default to this relation Useful to remove clutter for nested content with a click-through-to-children setup. Set to relation method name that must be present in 'parents'. @param string $relation @return ModelList|$this
entailment
public function parentRelations(array $relations): ModelList { $this->main['parents'] = []; foreach ($relations as $key => $value) { if (is_string($key)) { $parent = [ 'relation' => $key, 'field' => $value, ]; ...
List parents for list hierarchy handling The relations by which this listing may be 'filtered'. @param string[] $relations either relation names, or key-value pairs: relation => field @return ModelList|$this
entailment
public function enrich(ModelInformationInterface $information) { $this->info = $information; try { foreach ($this->steps as $step) { /** @var EnricherStepInterface $instance */ $instance = app($step); $this->info = $instance->setEnricher(...
Enriches a single model's information. Note that this does not offer contextual information for other models. @param ModelInformationInterface|ModelInformation $information @return ModelInformationInterface|ModelInformation @throws ModelInformationEnrichmentException
entailment
public function availableLocales() { $locales = $this->getCore()->config('locale.translation-locales'); if (is_array($locales)) { return $locales; } return $this->getLocaleRepository()->getAvailable(); }
Returns list of locales available for content transla @return string[]
entailment
public function defaultLocale() { $locale = $this->getCore()->config('locale.translation-default'); if ($locale) { return $locale; } // Fall back to default based on CMS configuration and app locale. $locale = app()->getLocale(); $available = $this->a...
Returns default translation locale. @return string
entailment
public function activeLocale() { $active = $this->getCore()->session()->get(static::ACTIVE_LOCALE_SESSION_KEY); if ($active && in_array($active, $this->availableLocales())) { return $active; } return $this->defaultLocale(); }
Returns currently active translation locale. @return string
entailment
public function setActiveLocale($locale) { if (empty($locale)) { $this->getCore()->session()->forget(static::ACTIVE_LOCALE_SESSION_KEY); } else { $this->getCore()->session()->put(static::ACTIVE_LOCALE_SESSION_KEY, $locale); } return $this; }
Set currently active translation locale. @param string|null $locale if empty/null, unsets the active locale @return $this
entailment
protected function performEnrichment() { if ( ! count($this->info->form->fields)) { $this->fillDataForEmpty(); } else { $this->enrichCustomData(); } }
Performs enrichment.
entailment
protected function fillDataForEmpty() { // Fill field references if they are empty $fields = []; // Add columns for attributes foreach ($this->info->attributes as $attribute) { if ($attribute->hidden || ! $this->shouldAttributeBeEditableByDefault($attribute, $this->info...
Fills form field data if no field data is set.
entailment
protected function enrichField($key, ModelFormFieldDataInterface $field, array &$fields) { $normalizedRelationName = $this->normalizeRelationName($key); // Check if we can enrich, if we must. if ( ! isset($this->info->attributes[ $key ]) && ! isset($this->info->relations[ $n...
Enriches a single form field and saves the data. @param ModelFormFieldDataInterface|ModelFormFieldData $field @param string $key @param array $fields by reference, data array to build, updated with enriched data
entailment
protected function shouldAttributeBeEditableByDefault(ModelAttributeData $attribute, ModelInformationInterface $info) { // Auto-incrementing key if ($attribute->name === $this->model->getKeyName() && $info->incrementing) { return false; } // Activatable column is used in...
Returns whether an attribute should be editable if no user-defined fields are configured. @param ModelAttributeData $attribute @param ModelInformationInterface|ModelInformation $info @return bool
entailment
protected function makeModelFormFieldDataForAttributeData(ModelAttributeData $attribute) { $strategy = $this->determineFormDisplayStrategyForAttribute($attribute); return new ModelFormFieldData([ 'key' => $attribute->name, 'display_strategy' => $strategy, ...
Makes data set for form field given attribute data. @param ModelAttributeData $attribute @return ModelFormFieldData
entailment
protected function makeModelFormFieldDataForRelationData(ModelRelationData $relation, $key = null) { $required = ( in_array($relation->type, [ RelationType::BELONGS_TO, RelationType::BELONGS_TO_THROUGH, RelationType::MORPH...
Makes data set for form field given relation data. @param ModelRelationData $relation @param string|null $key @return ModelFormFieldData
entailment
protected function determineMorphModelsForRelationData(ModelRelationData $data) { if ($data->morphModels && count($data->morphModels)) { return $data->morphModels; } // Use information for other models in the CMS to find (some of) the related models $context = $this->enr...
Determines models for MorphTo relation data. @param ModelRelationData $data @return string[]
entailment
public function strategy(string $strategy, array $options = []): ListFilter { $this->main['strategy'] = $strategy; if (count($options)) { $this->main['options'] = $options; } return $this; }
Set the filter strategy @param string $strategy alias or FQN @param array $options options specific for the strategy @return ListFilter|$this
entailment
protected function renderedFormFieldStrategies(Model $model, array $fields, array $values, array $errors = []) { $views = []; foreach ($fields as $key => $field) { try { $instance = $this->getFormFieldStrategyFactory()->make($field->display_strategy); /...
Renders Vies or HTML for form field strategies. @param Model $model @param array $fields @param array $values @param array $errors @return View[]|\string[] @throws StrategyRenderException
entailment
public function setMappings($mappings) { if ($mappings instanceof \Closure) { $mappings = $mappings(); } $this->mappings = (array) $mappings; return $this; }
@param array|\Closure $mappings @return $this
entailment
protected function resolveContextStrategy($strategy) { if ( ! $strategy) { $strategy = config('cms-models.strategies.repository.default-strategy'); } if ( ! ($strategyClass = $this->resolveContextStrategyClass($strategy))) { return null; } return app...
Resolves the context strategy, if possible. @param $strategy @return ContextStrategyInterface|null
entailment
protected function resolveContextStrategyClass($strategy) { if ( ! empty($strategy)) { if ( ! str_contains($strategy, '.')) { $strategy = config('cms-models.strategies.repository.aliases.' . $strategy, $strategy); } if (class_exists($strategy) && is_a($s...
Resolves strategy assuming it is the class name or FQN of a sort interface implementation, or a configured alias. @param $strategy @return string|false returns full class namespace if it was resolved succesfully
entailment
protected function performStep() { $scopes = []; foreach ($this->reflection()->getMethods() as $method) { if ( ! starts_with($method->name, 'scope') || ! $this->isScopeMethodUsable($method)) { continue; } $scopeName = camel_case(substr($method->...
Performs the analyzer step on the stored model information instance.
entailment
protected function isScopeMethodUsable(ReflectionMethod $method) { // Scope methods with more or less required parameters than the query, should not be used. if ($method->getNumberOfRequiredParameters() != 1) { return false; } // If the required parameter is not the firs...
Returns whether a reflection method is usabled as a CMS scope. @param ReflectionMethod $method @return bool
entailment
public function removeHyphens($isbn) { if(is_string($isbn) === false) { throw new Exception('Invalid parameter type.'); } $isbn = str_replace(' ', '', $isbn); $isbn = str_replace('-', '', $isbn); return $isbn; }
Remove Hyphens @param string $isbn @return string @throws Exception
entailment
public function fixHyphens($isbn, $char = '-') { $isbn = $this->removeHyphens($isbn); return $this->addHyphens($isbn, $char); }
Fix Hypens @param string $isbn @param string $char @return string
entailment
public function addHyphens($isbn, $char = '-') { if(is_string($isbn) === false || is_string($char) === false) { throw new Exception('Invalid parameter type.'); } $this->isbn = $isbn; $this->isbnSplit = array(); if (strlen($this->isbn)...
Add Hypens @param string $isbn @param string $char @throws Exception
entailment
private function range($min, $max, $chars, $p) { if (!$chars) { return false; } $val = substr($this->isbn, $this->parsed($p), $chars); $min = substr($min, 0, $chars); $max = substr($max, 0, $chars); if ($val >= $min and $val <= $max) { $this-...
Range @param int $min @param int $max @param int $chars @param int $p @return boolean
entailment
private function parsed($now = null) { $chars = 0; foreach ($this->isbnSplit as $key => $split) { if (isset($now) === false or $key < $now) { $chars = $chars + strlen($split); } } return $chars; }
Get Parsed Length @param null|int $now @return int
entailment
private function getRegistrationGroupElement() { if (isset($this->isbnSplit[0]) === false or $this->isbnSplit[0] === '978') { $this->range("0000000", "5999999", 1, 1); $this->range("6000000", "6499999", 3, 1); $this->range("6500000", "6999999", 0, 1); $this->r...
Get Registration Group Element @return boolean
entailment
private function getRegistrantElement() { if (isset($this->isbnSplit[0]) === true) { $soFar = implode('-', $this->isbnSplit); } else { $soFar = '978-'.$this->isbnSplit[1]; } switch ($soFar) { case '978-0': $this->range("0000000", "...
Get Registrant Element
entailment
public function identify($isbn) { if($this->is10($isbn) === true) { return 10; } return ($this->is13($isbn) === true ? 13 : false); }
Identifies the ISBN format and returns the corresponding number or false if no pattern matches. @param string @return int|false
entailment
public function is10($isbn) { if(is_string($isbn) === false) { throw new Exception('Invalid parameter type.'); } $isbn = $this->hyphens->removeHyphens($isbn); return (strlen($isbn) === 10); }
Checks whether $isbn matches the ISBN-10 format. @param string $isbn @return boolean @throws Exception
entailment
public function isbn($isbn) { if ($this->check->is13($isbn)) return $this->isbn13($isbn); if ($this->check->is10($isbn)) return $this->isbn10($isbn); return false; }
Validate the ISBN $isbn @param string $isbn @return boolean
entailment
public function isbn10($isbn) { if(is_string($isbn) === false) { throw new Exception('Invalid parameter type.'); } //Verify ISBN-10 scheme $isbn = $this->hyphens->removeHyphens($isbn); if (strlen($isbn) != 10) { return false; } if (pre...
Validate the ISBN-10 $isbn @param string $isbn @return boolean @throws Exception
entailment
public function isbn13($isbn) { if(is_string($isbn) === false) { throw new Exception('Invalid parameter type.'); } //Verify ISBN-13 scheme $isbn = $this->hyphens->removeHyphens($isbn); if (strlen($isbn) != 13) { return false; } ...
Validate the ISBN-13 $isbn @param string $isbn @return boolean @throws Exception
entailment
public function make($isbn) { if(is_string($isbn) === false) { throw new Exception('Invalid parameter type.'); } $isbn = $this->hyphens->removeHyphens($isbn); if (strlen($isbn) === 12 or strlen($isbn) === 13) { return $this->make13($isbn); } elseif (s...
Calculate the check digit of $isbn. @param string $isbn @return boolean|string|int
entailment
public function make10($isbn) { if(is_string($isbn) === false) { throw new Exception('Invalid parameter type.'); } //Verify length $isbnLength = strlen($isbn); if ($isbnLength < 9 or $isbnLength > 10) { throw new Exception('Invalid ISBN-10 format.'); ...
Calculate the check digit of the ISBN-10 $isbn. @param string $isbn @return string|int @throws Exception
entailment
public function make13($isbn) { if(is_string($isbn) === false) { throw new Exception('Invalid parameter type.'); } //Verify length $isbnLength = strlen($isbn); if ($isbnLength < 12 or $isbnLength > 13) { throw new Exception('Invalid ISBN-13 fo...
Calculate the check digit of the ISBN-13 $isbn @param string $isbn @return int @throws Exception
entailment
public function aroundGetConfigurationDesignTheme(Design $subject, callable $proceed, ...$args) { $forceLuma = $this->scopeConfig->getValue(self::CONFIG_PATH_FORCE_LUMA_CHECKOUT, ScopeInterface::SCOPE_STORE); if ($forceLuma && $this->httpRequest->getModuleName() === 'checkout' && ...
Forces the Luma theme when httpRequest is being handled by checkout. @param Design $subject @param callable $proceed @param array ...$args @return int
entailment
public function load() { foreach ($this->config['autoload'] as $file) { if ( ! locate_template($this->getRelativePath($file), true, true)) { throw new FileNotFoundException("Autoloaded file [{$this->getPath($file)}] cannot be found. Please, check your autoloaded entries in `confi...
Localize and autoloads files. @return void
entailment
public function getClientIp() { $ipaddress = getenv('HTTP_CLIENT_IP') ?: getenv('HTTP_X_FORWARDED_FOR') ?: getenv('HTTP_X_FORWARDED') ?: getenv('HTTP_FORWARDED_FOR') ?: getenv('HTTP_FORWARDED') ?: getenv('REM...
Get the customers IP Address @return string
entailment
public function getClientIpFromServerVar() { $ipaddress = ''; if (isset($_SERVER['HTTP_CLIENT_IP'])) $ipaddress = $_SERVER['HTTP_CLIENT_IP']; else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; else if(isset($_SERVER...
Get the customers IP address from server variables @return string
entailment
public function request($method, $api_method, $body = NULL, $checksum) { /** * Check if the Merchant ID is set */ if (empty($this->api_key)) { throw new \Exception("Please configure your ICEPAY Merchant ID."); } /** * Check if the Secret Code i...
Request function to call our API Rest Payment Server @param $method @param $api_method @param $body @param $checksum @return mixed @throws \Exception
entailment
public function get($key, array $parameters = []) { // If service is a factory, we should always // return new instance of the service. if (isset($this->factories[$key])) { return $this->resolve($this->factories[$key], $parameters); } // Otherwise, look for servi...
Resolve service form container. @param string $key @param array $parameters @return mixed
entailment
public function has($key) { return isset($this->factories[$key]) || isset($this->services[$key]); }
Determine if the given service exists. @param string $key @return bool
entailment
public function offsetSet($key, $service) { if ( ! is_callable($service)) { throw new BindingResolutionException("Service definition [{$service}] is not an instance of Closure"); } $this->bind($key, $service); }
Sets a service. @param string $key @param Closure $service @return void
entailment
public function compile(\Twig_Compiler $compiler) { $extensionName = (version_compare(\Twig_Environment::VERSION, '1.26.0') >= 0) ? 'Hampe\Bundle\ZurbInkBundle\Twig\InkyExtension' : InkyExtension::NAME; $compiler ->addDebugInfo($this) ->write('ob_start();' . PHP_EOL) ...
Compiles the node to PHP. @param \Twig_Compiler A Twig_Compiler instance
entailment
protected function _getElementHtml(AbstractElement $element) { $element->addData([ 'wysiwyg' => true, 'config' => $this->wysiwygConfig->getConfig($element) ]); return parent::_getElementHtml($element); }
Enable wysiwyg editor for the element. @param AbstractElement $element @return string
entailment
public function to10($isbn) { if(is_string($isbn) === false) { throw new Exception('Invalid parameter type.'); } if (strlen($isbn) > 13) { $isbn = substr($isbn, 4, -1); } else { $isbn = substr($isbn, 3, -1); } return $isbn.$this->...
Convert $isbn to ISBN-10 @param string $isbn @return string @throws Exception
entailment
public function parse(Twig_Token $token) { $lineno = $token->getLine(); $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE); $body = $this->parser->subparse(array($this, 'decideInkyEnd'), true); $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE); retu...
Parses a token and returns a node. @param Twig_Token $token A Twig_Token instance @return Twig_NodeInterface A Twig_NodeInterface instance @throws Twig_Error_Syntax
entailment
public function render(array $context = []) { if ($template = locate_template($path = $this->getRelativePath(), false, false)) { $this->doActions(); extract(apply_filters("tonik/gin/template/context/{$this->getFilename()}", $context)); require $template; re...
Render template. @param array $context @throws \Tonik\Gin\Foundation\Exception\FileNotFoundException @return void
entailment
public function doActions() { if ($this->isNamed()) { list($slug, $name) = $this->file; do_action("get_template_part_{$slug}", $slug, $name); return; } // Use first template name, if template // file is an array, but is not named. if (is...
Calls before including template actions. @return void
entailment
public function getRelativePath() { $templates = $this->config['directories']['templates']; $extension = $this->config['templates']['extension']; return $templates . '/' . $this->getFilename($extension); }
Gets template path within `resources/templates` directory. @return string
entailment
public function getFilename($extension = '.php') { // If template is named, // return joined template names. if ($this->isNamed()) { return join('-', $this->file) . $extension; } // Use first template name, if template // file is an array, but is not name...
Gets template name. @return string
entailment
public function isNamed() { // If file is not array, then template // is not named for sure. if ( ! is_array($this->file)) { return false; } // Return false if template is named, but name // is invalid. A valid name should be: if ( is...
Checks if temlate has variant name. @return boolean
entailment
private static function prettyFormat($difference, $unit) { // $prepend is added to the start of the string if the supplied // difference is greater than 0, and $append if less than $prepend = ($difference < 0) ? 'In ' : ''; $append = ($difference > 0) ? ' ago' : ''; $differe...
A helper used by parse() to create the human readable strings. Given a positive difference, corresponding to a date in the past, it appends the word 'ago'. And given a negative difference, corresponding to a date in the future, it prepends the word 'In'. Also makes the unit of time plural if necessary. @param integer...
entailment
public static function parse(\DateTime $dateTime, \DateTime $reference = null) { // If not provided, set $reference to the current DateTime if (!$reference) { $reference = new \DateTime(NULL, new \DateTimeZone($dateTime->getTimezone()->getName())); } // Get the differenc...
Returns a pretty, or human readable string corresponding to the supplied $dateTime. If an optional secondary DateTime object is provided, it is used as the reference - otherwise the current time and date is used. Examples: 'Moments ago', 'Yesterday', 'In 2 years' @param DateTime $dateTime The DateTime to parse @par...
entailment
public function encrypt($cleartext) { $cipher = "AES-256-CBC"; $ivlen = openssl_cipher_iv_length($cipher); $iv = openssl_random_pseudo_bytes($ivlen); $ciphertext_raw = openssl_encrypt($cleartext, $cipher, $this->saltedKey, $options = OPENSSL_RAW_DATA, $iv); $hmac = hash_hmac(...
Encrypt and then sign some cleartext @param string $cleartext - The cleartext to encrypt and sign @return string - The encrypted-and-signed message as base64 ASCII.
entailment
public function decrypt($data) { $c = base64_decode($data); $cipher = "AES-256-CBC"; $ivlen = openssl_cipher_iv_length($cipher); $iv = substr($c, 0, $ivlen); $hmac = substr($c, $ivlen, $sha2len = 32); $ciphertext_raw = substr($c, $ivlen+$sha2len); $cleartext =...
Check the signature on an encrypted-and-signed message, and if valid decrypt the content @param string $data - The encrypted-and-signed message as base64 ASCII @return bool|string - The decrypted cleartext or false if signature failed
entailment
protected function isDatabaseReady() { // Such as during setup of testsession prior to DB connection. if (!DB::is_active()) { return false; } // If we have a DB of the wrong type then complain if (!(DB::get_conn() instanceof MySQLDatabase)) { throw ne...
Determine if the DB is ready to use. @return bool @throws Exception
entailment
protected function getLifetime() { $params = session_get_cookie_params(); $cookieLifetime = (int)$params['lifetime']; $gcLifetime = (int)ini_get('session.gc_maxlifetime'); return $cookieLifetime ? min($cookieLifetime, $gcLifetime) : $gcLifetime; }
Get lifetime in number of seconds @return int
entailment
public static function all($options = array()) { $queryString = ""; if (!empty($options)) { $queryString .= "?"; $queryString .= http_build_query($options); } return Request::get("/online/v1/users$queryString", array( "sign" => true )); }
Get users list @param array $options
entailment
public function setHandlers($handlers) { $this->handlers = $handlers; $this->setKey($this->getKey()); return $this; }
@param SessionHandlerInterface[] @return $this
entailment
public function setKey($key) { parent::setKey($key); foreach ($this->getHandlers() as $handler) { $handler->setKey($key); } return $this; }
@param string @return $this
entailment
public function open($save_path, $name) { foreach ($this->getHandlers() as $handler) { $handler->open($save_path, $name); } return true; }
@param string $save_path @param string $name @return bool
entailment