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)) { return $strategy; } $strategy = $this->prefixStrategyNamespace($strategy); if (class_exists($strategy) && is_a($strategy, SortStrategyInterface::class, true)) { return $strategy; } return false; }
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 = $repository->getByModelClass($model); } if ( ! $info) { $this->error("Unable to find information for model by key or class '{$model}'"); return; } $infos = new Collection([ $info ]); } $config = $this->getBaseConfiguration(); foreach ($infos as $info) { $this->writeInformation($info, $config); } }
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('bucket')); $name = $this->argument('name'); $bucket->manager()->dropN1qlIndex( $name, $this->option('ignore') ); $this->info("dropped SECONDARY INDEX [{$name}] for [{$this->argument('bucket')}] bucket."); } return; }
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 AnalyzerStepInterface $step */ $step = app($stepClass); $information = $step->setAnalyzer($this)->analyze($information); } return $information; }
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 of '{$class}' is not a model"); } $this->modelInstance = $instance; $this->modelReflection = new ReflectionClass($class); return $this; }
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; if (count($parameters)) { $serializedParameters = implode( ',', array_map( function ($value) { return (string) $value; }, $parameters ) ); $this->main['delete_condition'] .= ':' . $serializedParameters; } return $this; }
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'; return $this; }
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->get('page') ? (int) $request->get('page') : null; } elseif ($this->getListMemory()->hasPage()) { $this->retrieveActivePageFromSession(); } if ($update && $pageSizeSetByRequest) { $this->activePageSize = $request->get('pagesize') ? (int) $request->get('pagesize') : null; $this->activePage = null; } elseif ($this->getListMemory()->hasPageSize()) { $this->retrieveActivePageSizeFromSession(); } if ($update && ($pageSetByRequest || $pageSizeSetByRequest)) { $this->storeActivePageValuesInSession(); } return $this; }
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($permissions)) { continue; } $instance = $this->getActionStrategyFactory()->make($data->strategy); // Initialize the instance with extra information $instance->initialize($data, $this->getModelInformation()->modelClass()); return $instance; } return false; }
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, $this->model->getKey(), $ruleSet); continue; } if (is_array($ruleSet)) { foreach ($ruleSet as &$rule) { $rule = str_replace($placeholder, $this->model->getKey(), $rule); } unset($rule); } } unset($ruleSet); return $this; }
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 => $ruleSet) { if (false === strpos($key, $placeholder)) { $processed[ $key ] = $ruleSet; continue; } // Add the rule for each translatable locale separately foreach ($locales as $locale) { $localizedKey = str_replace($placeholder, $locale, $key); $localizedRule = $ruleSet; // Replace placeholders for rulesets, whether they formatted as string or array if (is_array($localizedRule)) { $localizedRule = array_map( function ($part) use ($placeholder, $locale) { return str_replace($placeholder, $locale, $part); }, $localizedRule ); } else { $localizedRule = str_replace($placeholder, $locale, $localizedRule); } $processed[ $localizedKey ] = $localizedRule; } } $this->rules = $processed; return $this; }
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; } $this->storeFiltersInSession(); if ($resetPage) { $this->markResetActivePage(); } return $this; }
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->first(); } else { $firstModel = head($models); } $strategy = $this->determineModelReferenceStrategy($firstModel, $strategy); if ( ! $source) { $source = $this->determineModelReferenceSource($firstModel); } foreach ($models as $model) { if ( ! $strategy) { $references->put($model->getKey(), $this->getReferenceFallback($model)); continue; } $references->put($model->getKey(), $strategy->render($model, $source)); } return $references; }
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->getReferenceForModelMetaReferenceByModel($referenceData, $model); }
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, $referenceData->source(), $referenceData->sortDirection(), $referenceData->sortStrategy() ); if (null !== $search) { $this->applySearchTermFilterToQueryBuilder($query, $referenceData->target(), $search); } // If set, apply an (extra) contextual modification to the query builder if ($referenceData->contextStrategy()) { $this->applyContextStrategyToQueryBuilder( $query, $referenceData->contextStrategy(), $referenceData->parameters() ); } /** @var Collection|Model[] $models */ $models = $query->get(); // Get references for query results, keyed by primary key $references = []; foreach ($models as $model) { $references[ $model->getKey() ] = $this->getReferenceForModel( $model, $referenceData->strategy(), $referenceData->source() ); } return new Collection($references); }
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 // if not specifics are given, otherwise, a custom fallback reference must be used. if ($info = $this->getCmsModelInformation($modelClass)) { // Get model records, filtered as necessary $repository = $this->getModelRepositoryForInformation($info); /** @var Model[] $models */ return $repository->query(); } // The model is not part of the CMS return $this->getQueryBuilderForNonCmsModelClass($modelClass); }
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 } /** @var Model $model */ $model = new $modelClass; return $model::query(); }
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, $value); }
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'); } if ( ! $strategy) return $this; $strategyInstance = new $strategy; if ( ! ($strategyInstance instanceof SortStrategyInterface)) { throw new UnexpectedValueException("{$strategy} is not a sort strategy"); } // Explode combined source keys and apply the strategy for each part foreach (explode(',', $source) as $sourcePart) { $query = $strategyInstance->apply($query, $sourcePart, $direction); } return $this; }
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->applyRepositoryContext($modelRepository, $information); return $modelRepository; }
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['default_sort'] = $strategy; return $this; }
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'] = [ [ 'relation' => $relation, 'field' => $relation, ], ]; } return $this; }
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, ]; } else { $parent = [ 'relation' => $value, 'field' => $value, ]; } $this->main['parents'][] = $parent; } return $this; }
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($this)->enrich($this->info); } } catch (Exception $e) { $key = null; $section = null; $message = $e->getMessage(); if ($e instanceof ModelInformationEnrichmentException) { $key = $e->getKey(); $section = $e->getSection(); } elseif ($e instanceof ModelConfigurationDataException) { $message .= " ({$e->getDotKey()})"; } // Wrap and decorate exceptions so it is easier to track the problem source throw (new ModelInformationEnrichmentException( "{$information->modelClass()} model configuration issue: \n{$message}", (int) $e->getCode(), $e )) ->setModelClass($information->modelClass()) ->setSection($section) ->setKey($key); } return $information; }
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->availableLocales(); // If no translation locales are set, use app's locale as default. // If current app locale is available, use it as default. if ( ! count($available) || in_array($locale, $available)) { return $locale; } return head($available); }
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)) { continue; } $fields[ $attribute->name ] = $this->makeModelFormFieldDataForAttributeData($attribute); } // Add fields for relations foreach ($this->info->relations as $relation) { $fields[ $relation->name ] = $this->makeModelFormFieldDataForRelationData($relation); } $this->info->form->fields = $fields; }
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[ $normalizedRelationName ]) ) { // Make sure to set the key if it isn't if ( ! $field->key()) { $field->key = $key; } $fields[ $key ] = $field; return; } if (isset($this->info->attributes[ $key ])) { $enrichFieldInfo = $this->makeModelFormFieldDataForAttributeData($this->info->attributes[ $key ]); } else { // get from relation data $enrichFieldInfo = $this->makeModelFormFieldDataForRelationData( $this->info->relations[ $normalizedRelationName ], $key ); } // Detect whether update/create were not explicitly defined // If they were not, assume that they should be shown, // since they were explicitly included in the config. if (null === $field->update && null === $field->create) { $field->update = true; $field->create = true; } $enrichFieldInfo->merge($field); $fields[ $key ] = $enrichFieldInfo; }
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 listing, so hide in edit form if ($info->list->activatable && $info->list->active_column == $attribute->name) { return false; } // Orderable column for listify is used in listing, hide in edit form if ($info->list->orderable && $info->list->order_column == $attribute->name) { return false; } // Automated timestamp columns if ( $this->model->timestamps && ( $attribute->name == $this->model->getCreatedAtColumn() || $attribute->name == $this->model->getUpdatedAtColumn() ) ) { return false; } // Exclude paperclip fields other than the main field if ( preg_match('#^(?<field>[^_]+)_(file_name|file_size|content_type|updated_at)$#', $attribute->name, $matches) && array_has($info->attributes, $matches['field']) ) { return $info->attributes[ $matches['field'] ]->cast !== AttributeCast::PAPERCLIP_ATTACHMENT; } // Any attribute that is a foreign key and should be handled with relation-based strategies return ! $this->isAttributeForeignKey($attribute->name, $info); }
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, 'store_strategy' => $this->determineFormStoreStrategyForAttribute($attribute), 'translated' => $attribute->translated, 'required' => $this->shouldModelFormFieldBeRequired($attribute, $strategy), 'options' => $this->determineFormFieldOptions($attribute), ]); }
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_TO, ]) && ! $relation->nullable_key); // Shows any relation, regardless of type. Note that this is not optimal for // records with a large number of to-many related items, for instance. return new ModelFormFieldData([ 'key' => $key ?: $relation->name, 'source' => $relation->method, 'required' => $required, 'translated' => $relation->translated, 'display_strategy' => $this->determineFormDisplayStrategyForRelation($relation), 'store_strategy' => $this->determineFormStoreStrategyForRelation($relation), 'options' => $this->determineFormStoreOptionsForRelation($relation), ]); }
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->enricher->getAllModelInformation(); // If there is no context, silently ignore it. if ( ! $context) { // @codeCoverageIgnoreStart return []; // @codeCoverageIgnoreEnd } $models = []; foreach ($context as $information) { // If a relation is related to this model by a reverse morph relation, // it is an intended MorphTo targetable model. foreach ($information->relations as $relation) { if ( $this->info->modelClass() !== $relation->relatedModel || ! in_array($relation->type, [ RelationType::MORPH_ONE, RelationType::MORPH_MANY ]) ) { continue; } $models[ $information->modelClass() ] = []; } } return $models; }
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); // @codeCoverageIgnoreStart } catch (Exception $e) { $message = "Failed to make form field strategy for '{$key}': \n{$e->getMessage()}"; throw new StrategyRenderException($message, $e->getCode(), $e); // @codeCoverageIgnoreEnd } try { $views[ $key ] = $instance->render( $model, $fields[ $key ], old() ? old($key) : array_get($values, $key), array_get($values, $key), array_get($errors, $key, []) ); // @codeCoverageIgnoreStart } catch (Exception $e) { $message = "Failed to render form field '{$key}' for strategy " . get_class($instance) . ": \n{$e->getMessage()}"; throw new StrategyRenderException($message, $e->getCode(), $e); // @codeCoverageIgnoreEnd } } return $views; }
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($strategyClass); }
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($strategy, ContextStrategyInterface::class, true)) { return $strategy; } $strategy = $this->prefixContextStrategyNamespace($strategy); if (class_exists($strategy) && is_a($strategy, ContextStrategyInterface::class, true)) { return $strategy; } } return false; }
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->name, 5)); // Store the scope name without the scope prefix $scopes[ $scopeName ] = new ModelScopeData([ 'method' => $scopeName, 'label' => null, 'strategy' => null, ]); } $this->info->list->scopes = $scopes; }
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 first, don't use it (safeguard) if ( ! ($firstParameter = head($method->getParameters())) || $firstParameter->isOptional()) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd } $scopeName = camel_case(substr($method->name, 5)); // Ignore scope methods with an explicity ignore cms docblock tag $cmsTags = $this->getCmsDocBlockTags($method); if ( array_get($cmsTags, 'ignore') || ( ! array_get($cmsTags, 'scope') && in_array($scopeName, $this->getIgnoredScopeNames() ) ) ) { return false; } return true; }
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) === 13) { $this->isbnSplit[0] = substr($this->isbn, 0, 3); } $this->getRegistrationGroupElement(); $this->getRegistrantElement(); $this->getPublicationElement(); $this->getCheckDigit(); return implode($char, $this->isbnSplit); }
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->isbnSplit[$p] = $val; return true; } else { return false; } }
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->range("7000000", "7999999", 1, 1); $this->range("8000000", "9499999", 2, 1); $this->range("9500000", "9899999", 3, 1); $this->range("9900000", "9989999", 4, 1); $this->range("9990000", "9999999", 5, 1); } if (isset($this->isbnSplit[0]) === true and $this->isbnSplit[0] === '979') { $this->range("0000000", "0999999", 0, 1); $this->range("1000000", "1199999", 2, 1); $this->range("1200000", "9999999", 0, 1); } return (isset($this->isbnSplit[1])); }
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", "1999999", 2, 2); $this->range("2000000", "2279999", 3, 2); $this->range("2280000", "2289999", 4, 2); $this->range("2290000", "6389999", 3, 2); $this->range("6390000", "6398999", 4, 2); $this->range("6399000", "6399999", 7, 2); $this->range("6400000", "6479999", 3, 2); $this->range("6480000", "6489999", 7, 2); $this->range("6490000", "6549999", 3, 2); $this->range("6550000", "6559999", 4, 2); $this->range("6560000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9499999", 6, 2); $this->range("9500000", "9999999", 7, 2); break; case '978-1': $this->range("0000000", "0999999", 2, 2); $this->range("1000000", "3999999", 3, 2); $this->range("4000000", "5499999", 4, 2); $this->range("5500000", "7319999", 5, 2); $this->range("7320000", "7399999", 7, 2); $this->range("7400000", "7749999", 5, 2); $this->range("7750000", "7753999", 7, 2); $this->range("7754000", "8697999", 5, 2); $this->range("8698000", "9729999", 6, 2); $this->range("9730000", "9877999", 4, 2); $this->range("9878000", "9989999", 6, 2); $this->range("9990000", "9999999", 7, 2); break; case '978-2': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "3499999", 3, 2); $this->range("3500000", "3999999", 5, 2); $this->range("4000000", "4899999", 3, 2); $this->range("4900000", "4949999", 6, 2); $this->range("4950000", "6999999", 3, 2); $this->range("7000000", "8399999", 4, 2); $this->range("8400000", "8999999", 5, 2); $this->range("9000000", "9197999", 6, 2); $this->range("9198000", "9198099", 5, 2); $this->range("9198100", "9199429", 6, 2); $this->range("9199430", "9199689", 7, 2); $this->range("9199690", "9499999", 6, 2); $this->range("9500000", "9999999", 7, 2); break; case '978-3': $this->range("0000000", "0299999", 2, 2); $this->range("0300000", "0339999", 3, 2); $this->range("0340000", "0369999", 4, 2); $this->range("0370000", "0399999", 5, 2); $this->range("0400000", "1999999", 2, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9499999", 6, 2); $this->range("9500000", "9539999", 7, 2); $this->range("9540000", "9699999", 5, 2); $this->range("9700000", "9899999", 7, 2); $this->range("9900000", "9949999", 5, 2); $this->range("9950000", "9999999", 5, 2); break; case '978-4': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9499999", 6, 2); $this->range("9500000", "9999999", 7, 2); break; case '978-5': $this->range("0000000", "0049999", 5, 2); $this->range("0050000", "0099999", 4, 2); $this->range("0100000", "1999999", 2, 2); $this->range("2000000", "4209999", 3, 2); $this->range("4210000", "4299999", 4, 2); $this->range("4300000", "4309999", 3, 2); $this->range("4310000", "4399999", 4, 2); $this->range("4400000", "4409999", 3, 2); $this->range("4410000", "4499999", 4, 2); $this->range("4500000", "6039999", 3, 2); $this->range("6040000", "6049999", 7, 2); $this->range("6050000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9099999", 6, 2); $this->range("9100000", "9199999", 5, 2); $this->range("9200000", "9299999", 4, 2); $this->range("9300000", "9499999", 5, 2); $this->range("9500000", "9500999", 7, 2); $this->range("9501000", "9799999", 4, 2); $this->range("9800000", "9899999", 5, 2); $this->range("9900000", "9909999", 7, 2); $this->range("9910000", "9999999", 4, 2); break; case '978-600': $this->range("0000000", "0999999", 2, 2); $this->range("1000000", "4999999", 3, 2); $this->range("5000000", "8999999", 4, 2); $this->range("9000000", "9867999", 5, 2); $this->range("9868000", "9929999", 4, 2); $this->range("9930000", "9959999", 3, 2); $this->range("9960000", "9999999", 5, 2); break; case '978-601': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "7999999", 4, 2); $this->range("8000000", "8499999", 5, 2); $this->range("8500000", "9999999", 2, 2); break; case '978-602': $this->range("0000000", "0799999", 2, 2); $this->range("0800000", "0899999", 4, 2); $this->range("0900000", "1099999", 4, 2); $this->range("1100000", "1199999", 4, 2); $this->range("1200000", "1399999", 4, 2); $this->range("1400000", "1499999", 5, 2); $this->range("1500000", "1699999", 4, 2); $this->range("1700000", "1799999", 5, 2); $this->range("1800000", "1899999", 5, 2); $this->range("1900000", "1999999", 5, 2); $this->range("2000000", "4999999", 3, 2); $this->range("5000000", "5399999", 5, 2); $this->range("5400000", "5999999", 4, 2); $this->range("6000000", "6199999", 5, 2); $this->range("6200000", "6749999", 4, 2); $this->range("6750000", "6999999", 4, 2); $this->range("7000000", "7499999", 5, 2); $this->range("7500000", "7999999", 4, 2); $this->range("8000000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-603': $this->range("0000000", "0499999", 2, 2); $this->range("0500000", "4999999", 2, 2); $this->range("5000000", "7999999", 3, 2); $this->range("8000000", "8999999", 4, 2); $this->range("9000000", "9999999", 5, 2); break; case '978-604': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "8999999", 2, 2); $this->range("9000000", "9799999", 3, 2); $this->range("9800000", "9999999", 4, 2); break; case '978-605': $this->range("0000000", "0099999", 0, 2); $this->range("0100000", "0299999", 2, 2); $this->range("0300000", "0399999", 3, 2); $this->range("0400000", "0999999", 2, 2); $this->range("1000000", "1999999", 3, 2); $this->range("2000000", "2399999", 4, 2); $this->range("2400000", "3999999", 3, 2); $this->range("4000000", "5999999", 4, 2); $this->range("6000000", "8999999", 5, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-606': $this->range("0000000", "0999999", 3, 2); $this->range("1000000", "4999999", 2, 2); $this->range("5000000", "7999999", 3, 2); $this->range("8000000", "9099999", 4, 2); $this->range("9100000", "9199999", 3, 2); $this->range("9200000", "9749999", 5, 2); $this->range("9750000", "9999999", 3, 2); break; case '978-607': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "7499999", 3, 2); $this->range("7500000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-608': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "1999999", 2, 2); $this->range("2000000", "4499999", 3, 2); $this->range("4500000", "6499999", 4, 2); $this->range("6500000", "6999999", 5, 2); $this->range("7000000", "9999999", 1, 2); break; case '978-609': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "7999999", 3, 2); $this->range("8000000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-611': $this->range("0000000", "9999999", 0, 2); break; case '978-612': $this->range("0000000", "2999999", 2, 2); $this->range("3000000", "3999999", 3, 2); $this->range("4000000", "4499999", 4, 2); $this->range("4500000", "4999999", 5, 2); $this->range("5000000", "9999999", 2, 2); break; case '978-613': $this->range("0000000", "9999999", 1, 2); break; case '978-614': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "7999999", 3, 2); $this->range("8000000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-615': $this->range("0000000", "0999999", 2, 2); $this->range("1000000", "4999999", 3, 2); $this->range("5000000", "7999999", 4, 2); $this->range("8000000", "8999999", 5, 2); $this->range("9000000", "9999999", 0, 2); break; case '978-616': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "8999999", 4, 2); $this->range("9000000", "9999999", 5, 2); break; case '978-617': $this->range("0000000", "4999999", 2, 2); $this->range("5000000", "6999999", 3, 2); $this->range("7000000", "8999999", 4, 2); $this->range("9000000", "9999999", 5, 2); break; case '978-618': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "4999999", 3, 2); $this->range("5000000", "7999999", 4, 2); $this->range("8000000", "9999999", 5, 2); break; case '978-619': $this->range("0000000", "1499999", 2, 2); $this->range("1500000", "6999999", 3, 2); $this->range("7000000", "8999999", 4, 2); $this->range("9000000", "9999999", 5, 2); break; case '978-620': $this->range("0000000", "9999999", 1, 2); break; case '978-621': $this->range("0000000", "2999999", 2, 2); $this->range("3000000", "3999999", 0, 2); $this->range("4000000", "5999999", 3, 2); $this->range("6000000", "7999999", 0, 2); $this->range("8000000", "8999999", 4, 2); $this->range("9000000", "9499999", 0, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-7': $this->range("0000000", "0999999", 2, 2); $this->range("1000000", "4999999", 3, 2); $this->range("5000000", "7999999", 4, 2); $this->range("8000000", "8999999", 5, 2); $this->range("9000000", "9999999", 6, 2); break; case '978-80': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9999999", 6, 2); break; case '978-81': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9999999", 6, 2); break; case '978-82': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6899999", 3, 2); $this->range("6900000", "6999999", 6, 2); $this->range("7000000", "8999999", 4, 2); $this->range("9000000", "9899999", 5, 2); $this->range("9900000", "9999999", 6, 2); break; case '978-83': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "5999999", 3, 2); $this->range("6000000", "6999999", 5, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9999999", 6, 2); break; case '978-84': $this->range("0000000", "1299999", 2, 2); $this->range("1300000", "1399999", 4, 2); $this->range("1400000", "1499999", 3, 2); $this->range("1500000", "1999999", 5, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9199999", 4, 2); $this->range("9200000", "9239999", 6, 2); $this->range("9240000", "9299999", 5, 2); $this->range("9300000", "9499999", 6, 2); $this->range("9500000", "9699999", 5, 2); $this->range("9700000", "9999999", 4, 2); break; case '978-85': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "5439999", 3, 2); $this->range("5440000", "5479999", 4, 2); $this->range("5480000", "5499999", 5, 2); $this->range("5500000", "5999999", 4, 2); $this->range("6000000", "6999999", 5, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9249999", 6, 2); $this->range("9250000", "9449999", 5, 2); $this->range("9450000", "9599999", 4, 2); $this->range("9600000", "9799999", 2, 2); $this->range("9800000", "9999999", 5, 2); break; case '978-86': $this->range("0000000", "2999999", 2, 2); $this->range("3000000", "5999999", 3, 2); $this->range("6000000", "7999999", 4, 2); $this->range("8000000", "8999999", 5, 2); $this->range("9000000", "9999999", 6, 2); break; case '978-87': $this->range("0000000", "2999999", 2, 2); $this->range("3000000", "3999999", 0, 2); $this->range("4000000", "6499999", 3, 2); $this->range("6500000", "6999999", 0, 2); $this->range("7000000", "7999999", 4, 2); $this->range("8000000", "8499999", 0, 2); $this->range("8500000", "9499999", 5, 2); $this->range("9500000", "9699999", 0, 2); $this->range("9700000", "9999999", 6, 2); break; case '978-88': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "3269999", 3, 2); $this->range("3270000", "3389999", 4, 2); $this->range("3390000", "5999999", 3, 2); $this->range("6000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9099999", 6, 2); $this->range("9100000", "9299999", 3, 2); $this->range("9300000", "9399999", 4, 2); $this->range("9400000", "9479999", 6, 2); $this->range("9480000", "9499999", 5, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-89': $this->range("0000000", "2499999", 2, 2); $this->range("2500000", "5499999", 3, 2); $this->range("5500000", "8499999", 4, 2); $this->range("8500000", "9499999", 5, 2); $this->range("9500000", "9699999", 6, 2); $this->range("9700000", "9899999", 5, 2); $this->range("9900000", "9999999", 3, 2); break; case '978-90': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "4999999", 3, 2); $this->range("5000000", "6999999", 4, 2); $this->range("7000000", "7999999", 5, 2); $this->range("8000000", "8499999", 6, 2); $this->range("8500000", "8999999", 4, 2); $this->range("9000000", "9099999", 2, 2); $this->range("9100000", "9399999", 0, 2); $this->range("9400000", "9499999", 2, 2); $this->range("9500000", "9999999", 0, 2); break; case '978-91': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "4999999", 2, 2); $this->range("5000000", "6499999", 3, 2); $this->range("6500000", "6999999", 0, 2); $this->range("7000000", "7999999", 4, 2); $this->range("8000000", "8499999", 0, 2); $this->range("8500000", "9499999", 5, 2); $this->range("9500000", "9699999", 0, 2); $this->range("9700000", "9999999", 6, 2); break; case '978-92': $this->range("0000000", "5999999", 1, 2); $this->range("6000000", "7999999", 2, 2); $this->range("8000000", "8999999", 3, 2); $this->range("9000000", "9499999", 4, 2); $this->range("9500000", "9899999", 5, 2); $this->range("9900000", "9999999", 6, 2); break; case '978-93': $this->range("0000000", "0999999", 2, 2); $this->range("1000000", "4999999", 3, 2); $this->range("5000000", "7999999", 4, 2); $this->range("8000000", "9499999", 5, 2); $this->range("9500000", "9999999", 6, 2); break; case '978-94': $this->range("0000000", "5999999", 3, 2); $this->range("6000000", "8999999", 4, 2); $this->range("9000000", "9999999", 5, 2); break; case '978-950': $this->range("0000000", "4999999", 2, 2); $this->range("5000000", "8999999", 3, 2); $this->range("9000000", "9899999", 4, 2); $this->range("9900000", "9999999", 5, 2); break; case '978-951': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "5499999", 2, 2); $this->range("5500000", "8899999", 3, 2); $this->range("8900000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-952': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "4999999", 3, 2); $this->range("5000000", "5999999", 4, 2); $this->range("6000000", "6599999", 2, 2); $this->range("6600000", "6699999", 4, 2); $this->range("6700000", "6999999", 5, 2); $this->range("7000000", "7999999", 4, 2); $this->range("8000000", "9499999", 2, 2); $this->range("9500000", "9899999", 4, 2); $this->range("9900000", "9999999", 5, 2); break; case '978-953': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "1499999", 2, 2); $this->range("1500000", "5099999", 3, 2); $this->range("5100000", "5499999", 2, 2); $this->range("5500000", "5999999", 5, 2); $this->range("6000000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-954': $this->range("0000000", "2899999", 2, 2); $this->range("2900000", "2999999", 4, 2); $this->range("3000000", "7999999", 3, 2); $this->range("8000000", "8999999", 4, 2); $this->range("9000000", "9299999", 5, 2); $this->range("9300000", "9999999", 4, 2); break; case '978-955': $this->range("0000000", "1999999", 4, 2); $this->range("2000000", "3599999", 2, 2); $this->range("3600000", "3799999", 4, 2); $this->range("3800000", "3899999", 5, 2); $this->range("3900000", "4099999", 4, 2); $this->range("4100000", "4499999", 5, 2); $this->range("4500000", "4999999", 4, 2); $this->range("5000000", "5499999", 5, 2); $this->range("5500000", "7199999", 3, 2); $this->range("7200000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-956': $this->range("0000000", "0899999", 2, 2); $this->range("0900000", "0999999", 5, 2); $this->range("1000000", "1999999", 2, 2); $this->range("2000000", "5999999", 3, 2); $this->range("6000000", "6999999", 4, 2); $this->range("7000000", "9999999", 4, 2); break; case '978-957': $this->range("0000000", "0299999", 2, 2); $this->range("0300000", "0499999", 4, 2); $this->range("0500000", "1999999", 2, 2); $this->range("2000000", "2099999", 4, 2); $this->range("2100000", "2799999", 2, 2); $this->range("2800000", "3099999", 5, 2); $this->range("3100000", "4399999", 2, 2); $this->range("4400000", "8199999", 3, 2); $this->range("8200000", "9699999", 4, 2); $this->range("9700000", "9999999", 5, 2); break; case '978-958': $this->range("0000000", "5399999", 2, 2); $this->range("5400000", "5599999", 4, 2); $this->range("5600000", "5699999", 5, 2); $this->range("5700000", "5999999", 5, 2); $this->range("6000000", "7999999", 3, 2); $this->range("8000000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-959': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "9999999", 5, 2); break; case '978-960': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6599999", 3, 2); $this->range("6600000", "6899999", 4, 2); $this->range("6900000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "9299999", 5, 2); $this->range("9300000", "9399999", 2, 2); $this->range("9400000", "9799999", 4, 2); $this->range("9800000", "9999999", 5, 2); break; case '978-961': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "5999999", 3, 2); $this->range("6000000", "8999999", 4, 2); $this->range("9000000", "9499999", 5, 2); $this->range("9500000", "9999999", 0, 2); break; case '978-962': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8699999", 5, 2); $this->range("8700000", "8999999", 4, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-963': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-964': $this->range("0000000", "1499999", 2, 2); $this->range("1500000", "2499999", 3, 2); $this->range("2500000", "2999999", 4, 2); $this->range("3000000", "5499999", 3, 2); $this->range("5500000", "8999999", 4, 2); $this->range("9000000", "9699999", 5, 2); $this->range("9700000", "9899999", 3, 2); $this->range("9900000", "9999999", 4, 2); break; case '978-965': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "5999999", 3, 2); $this->range("6000000", "6999999", 0, 2); $this->range("7000000", "7999999", 4, 2); $this->range("8000000", "8999999", 0, 2); $this->range("9000000", "9999999", 5, 2); break; case '978-966': $this->range("0000000", "1299999", 2, 2); $this->range("1300000", "1399999", 3, 2); $this->range("1400000", "1499999", 2, 2); $this->range("1500000", "1699999", 4, 2); $this->range("1700000", "1999999", 3, 2); $this->range("2000000", "2789999", 4, 2); $this->range("2790000", "2899999", 3, 2); $this->range("2900000", "2999999", 4, 2); $this->range("3000000", "6999999", 3, 2); $this->range("7000000", "8999999", 4, 2); $this->range("9000000", "9099999", 5, 2); $this->range("9100000", "9499999", 3, 2); $this->range("9500000", "9799999", 5, 2); $this->range("9800000", "9999999", 3, 2); break; case '978-967': $this->range("0000000", "0099999", 2, 2); $this->range("0100000", "0999999", 4, 2); $this->range("1000000", "1999999", 5, 2); $this->range("2000000", "2499999", 4, 2); $this->range("2500000", "2999999", 0, 2); $this->range("3000000", "4999999", 3, 2); $this->range("5000000", "5999999", 4, 2); $this->range("6000000", "8999999", 2, 2); $this->range("9000000", "9899999", 3, 2); $this->range("9900000", "9989999", 4, 2); $this->range("9990000", "9999999", 5, 2); break; case '978-968': $this->range("0100000", "3999999", 2, 2); $this->range("4000000", "4999999", 3, 2); $this->range("5000000", "7999999", 4, 2); $this->range("8000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-969': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "2299999", 2, 2); $this->range("2300000", "2399999", 5, 2); $this->range("2400000", "3999999", 2, 2); $this->range("4000000", "7499999", 3, 2); $this->range("7500000", "9999999", 4, 2); break; case '978-970': $this->range("0100000", "5999999", 2, 2); $this->range("6000000", "8999999", 3, 2); $this->range("9000000", "9099999", 4, 2); $this->range("9100000", "9699999", 5, 2); $this->range("9700000", "9999999", 4, 2); break; case '978-971': $this->range("0000000", "0159999", 3, 2); $this->range("0160000", "0199999", 4, 2); $this->range("0200000", "0299999", 2, 2); $this->range("0300000", "0599999", 4, 2); $this->range("0600000", "4999999", 2, 2); $this->range("5000000", "8499999", 3, 2); $this->range("8500000", "9099999", 4, 2); $this->range("9100000", "9599999", 5, 2); $this->range("9600000", "9699999", 4, 2); $this->range("9700000", "9899999", 2, 2); $this->range("9900000", "9999999", 4, 2); break; case '978-972': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "5499999", 2, 2); $this->range("5500000", "7999999", 3, 2); $this->range("8000000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-973': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "1699999", 3, 2); $this->range("1700000", "1999999", 4, 2); $this->range("2000000", "5499999", 2, 2); $this->range("5500000", "7599999", 3, 2); $this->range("7600000", "8499999", 4, 2); $this->range("8500000", "8899999", 5, 2); $this->range("8900000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-974': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "8499999", 4, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9499999", 5, 2); $this->range("9500000", "9999999", 4, 2); break; case '978-975': $this->range("0000000", "0199999", 5, 2); $this->range("0200000", "2399999", 2, 2); $this->range("2400000", "2499999", 4, 2); $this->range("2500000", "5999999", 3, 2); $this->range("6000000", "9199999", 4, 2); $this->range("9200000", "9899999", 5, 2); $this->range("9900000", "9999999", 3, 2); break; case '978-976': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "5999999", 2, 2); $this->range("6000000", "7999999", 3, 2); $this->range("8000000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-977': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "4999999", 3, 2); $this->range("5000000", "6999999", 4, 2); $this->range("7000000", "8499999", 3, 2); $this->range("8500000", "8999999", 5, 2); $this->range("9000000", "9999999", 2, 2); break; case '978-978': $this->range("0000000", "1999999", 3, 2); $this->range("2000000", "2999999", 4, 2); $this->range("3000000", "7999999", 5, 2); $this->range("8000000", "8999999", 4, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-979': $this->range("0000000", "0999999", 3, 2); $this->range("1000000", "1499999", 4, 2); $this->range("1500000", "1999999", 5, 2); $this->range("2000000", "2999999", 2, 2); $this->range("3000000", "3999999", 4, 2); $this->range("4000000", "7999999", 3, 2); $this->range("8000000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-980': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "5999999", 3, 2); $this->range("6000000", "9999999", 4, 2); break; case '978-981': $this->range("0000000", "1699999", 2, 2); $this->range("1700000", "1999999", 5, 2); $this->range("2000000", "2999999", 3, 2); $this->range("3000000", "3099999", 4, 2); $this->range("3100000", "3999999", 3, 2); $this->range("4000000", "9999999", 4, 2); break; case '978-982': $this->range("0000000", "0999999", 2, 2); $this->range("1000000", "6999999", 3, 2); $this->range("7000000", "8999999", 2, 2); $this->range("9000000", "9799999", 4, 2); $this->range("9800000", "9999999", 5, 2); break; case '978-983': $this->range("0000000", "0199999", 2, 2); $this->range("0200000", "1999999", 3, 2); $this->range("2000000", "3999999", 4, 2); $this->range("4000000", "4499999", 5, 2); $this->range("4500000", "4999999", 2, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "8999999", 3, 2); $this->range("9000000", "9899999", 4, 2); $this->range("9900000", "9999999", 5, 2); break; case '978-984': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "7999999", 3, 2); $this->range("8000000", "8999999", 4, 2); $this->range("9000000", "9999999", 5, 2); break; case '978-985': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "5999999", 3, 2); $this->range("6000000", "8999999", 4, 2); $this->range("9000000", "9999999", 5, 2); break; case '978-986': $this->range("0000000", "1199999", 2, 2); $this->range("1200000", "5599999", 3, 2); $this->range("5600000", "7999999", 4, 2); $this->range("8000000", "9999999", 5, 2); break; case '978-987': $this->range("0000000", "0999999", 2, 2); $this->range("1000000", "1999999", 4, 2); $this->range("2000000", "2999999", 5, 2); $this->range("3000000", "3599999", 2, 2); $this->range("3600000", "3999999", 4, 2); $this->range("4000000", "4199999", 4, 2); $this->range("4200000", "4399999", 2, 2); $this->range("4400000", "4499999", 4, 2); $this->range("4500000", "4899999", 5, 2); $this->range("4900000", "4999999", 4, 2); $this->range("5000000", "8999999", 3, 2); $this->range("9000000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-988': $this->range("0000000", "1199999", 2, 2); $this->range("1200000", "1499999", 5, 2); $this->range("1500000", "1699999", 5, 2); $this->range("1700000", "1999999", 5, 2); $this->range("2000000", "7699999", 3, 2); $this->range("7700000", "7999999", 5, 2); $this->range("8000000", "9699999", 4, 2); $this->range("9700000", "9999999", 5, 2); break; case '978-989': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "5399999", 2, 2); $this->range("5400000", "5499999", 5, 2); $this->range("5500000", "7999999", 3, 2); $this->range("8000000", "9499999", 4, 2); $this->range("9500000", "9999999", 5, 2); break; case '978-9921': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "2999999", 0, 2); $this->range("3000000", "3999999", 2, 2); $this->range("4000000", "6999999", 0, 2); $this->range("7000000", "8999999", 3, 2); $this->range("9000000", "9699999", 0, 2); $this->range("9700000", "9999999", 4, 2); break; case '978-9922': $this->range("0000000", "1999999", 0, 2); $this->range("2000000", "2999999", 2, 2); $this->range("3000000", "5999999", 0, 2); $this->range("6000000", "7999999", 3, 2); $this->range("8000000", "8999999", 0, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9923': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "4999999", 2, 2); $this->range("5000000", "6999999", 0, 2); $this->range("7000000", "8999999", 3, 2); $this->range("9000000", "9699999", 0, 2); $this->range("9700000", "9999999", 4, 2); break; case '978-9924': $this->range("0000000", "2999999", 0, 2); $this->range("3000000", "3999999", 2, 2); $this->range("4000000", "4999999", 0, 2); $this->range("5000000", "6499999", 3, 2); $this->range("6500000", "8999999", 0, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9925': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "5499999", 2, 2); $this->range("5500000", "7349999", 3, 2); $this->range("7350000", "9999999", 4, 2); break; case '978-9926': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "3999999", 2, 2); $this->range("4000000", "7999999", 3, 2); $this->range("8000000", "9999999", 4, 2); break; case '978-9927': $this->range("0000000", "0999999", 2, 2); $this->range("1000000", "3999999", 3, 2); $this->range("4000000", "4999999", 4, 2); $this->range("5000000", "9999999", 0, 2); break; case '978-9928': $this->range("0000000", "0999999", 2, 2); $this->range("1000000", "3999999", 3, 2); $this->range("4000000", "4999999", 4, 2); $this->range("5000000", "9999999", 0, 2); break; case '978-9929': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "5499999", 2, 2); $this->range("5500000", "7999999", 3, 2); $this->range("8000000", "9999999", 4, 2); break; case '978-9930': $this->range("0000000", "4999999", 2, 2); $this->range("5000000", "9399999", 3, 2); $this->range("9400000", "9999999", 4, 2); break; case '978-9931': $this->range("0000000", "2999999", 2, 2); $this->range("3000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9932': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "8499999", 3, 2); $this->range("8500000", "9999999", 4, 2); break; case '978-9933': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "3999999", 2, 2); $this->range("4000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9934': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "4999999", 2, 2); $this->range("5000000", "7999999", 3, 2); $this->range("8000000", "9999999", 4, 2); break; case '978-9935': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "3999999", 2, 2); $this->range("4000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9936': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "3999999", 2, 2); $this->range("4000000", "7999999", 3, 2); $this->range("8000000", "9999999", 4, 2); break; case '978-9937': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "4999999", 2, 2); $this->range("5000000", "7999999", 3, 2); $this->range("8000000", "9999999", 4, 2); break; case '978-9938': $this->range("0000000", "7999999", 2, 2); $this->range("8000000", "9499999", 3, 2); $this->range("9500000", "9999999", 4, 2); break; case '978-9939': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9940': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "4999999", 2, 2); $this->range("5000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9941': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "3999999", 2, 2); $this->range("4000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9942': $this->range("0000000", "7499999", 2, 2); $this->range("7500000", "8499999", 3, 2); $this->range("8500000", "8999999", 4, 2); $this->range("9000000", "9849999", 3, 2); $this->range("9850000", "9999999", 4, 2); break; case '978-9943': $this->range("0000000", "2999999", 2, 2); $this->range("3000000", "3999999", 3, 2); $this->range("4000000", "9749999", 4, 2); $this->range("9750000", "9999999", 3, 2); break; case '978-9944': $this->range("0000000", "0999999", 4, 2); $this->range("1000000", "4999999", 3, 2); $this->range("5000000", "5999999", 4, 2); $this->range("6000000", "6999999", 2, 2); $this->range("7000000", "7999999", 3, 2); $this->range("8000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-9945': $this->range("0000000", "0099999", 2, 2); $this->range("0100000", "0799999", 3, 2); $this->range("0800000", "3999999", 2, 2); $this->range("4000000", "5699999", 3, 2); $this->range("5700000", "5799999", 2, 2); $this->range("5800000", "8499999", 3, 2); $this->range("8500000", "9999999", 4, 2); break; case '978-9946': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "3999999", 2, 2); $this->range("4000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9947': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-9948': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "8499999", 3, 2); $this->range("8500000", "9999999", 4, 2); break; case '978-9949': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "3999999", 2, 2); $this->range("4000000", "6999999", 3, 2); $this->range("7000000", "7199999", 2, 2); $this->range("7200000", "7499999", 4, 2); $this->range("7500000", "8999999", 2, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9950': $this->range("0000000", "2999999", 2, 2); $this->range("3000000", "8499999", 3, 2); $this->range("8500000", "9999999", 4, 2); break; case '978-9951': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "8499999", 3, 2); $this->range("8500000", "9999999", 4, 2); break; case '978-9952': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "3999999", 2, 2); $this->range("4000000", "7999999", 3, 2); $this->range("8000000", "9999999", 4, 2); break; case '978-9953': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "3999999", 2, 2); $this->range("4000000", "5999999", 3, 2); $this->range("6000000", "8999999", 2, 2); $this->range("9000000", "9299999", 4, 2); $this->range("9300000", "9699999", 2, 2); $this->range("9700000", "9999999", 3, 2); break; case '978-9954': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "3999999", 2, 2); $this->range("4000000", "7999999", 3, 2); $this->range("8000000", "9899999", 4, 2); $this->range("9900000", "9999999", 2, 2); break; case '978-9955': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "9299999", 3, 2); $this->range("9300000", "9999999", 4, 2); break; case '978-9956': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "3999999", 2, 2); $this->range("4000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9957': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "6499999", 3, 2); $this->range("6500000", "6799999", 2, 2); $this->range("6800000", "6999999", 3, 2); $this->range("7000000", "8499999", 2, 2); $this->range("8500000", "8799999", 4, 2); $this->range("8800000", "9999999", 2, 2); break; case '978-9958': $this->range("0000000", "0199999", 2, 2); $this->range("0200000", "0299999", 3, 2); $this->range("0300000", "0399999", 4, 2); $this->range("0400000", "0899999", 3, 2); $this->range("0900000", "0999999", 4, 2); $this->range("1000000", "1899999", 2, 2); $this->range("1900000", "1999999", 4, 2); $this->range("2000000", "4999999", 2, 2); $this->range("5000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9959': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "7999999", 2, 2); $this->range("8000000", "9499999", 3, 2); $this->range("9500000", "9699999", 4, 2); $this->range("9700000", "9799999", 3, 2); $this->range("9800000", "9999999", 2, 2); break; case '978-9960': $this->range("0000000", "5999999", 2, 2); $this->range("6000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9961': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "6999999", 2, 2); $this->range("7000000", "9499999", 3, 2); $this->range("9500000", "9999999", 4, 2); break; case '978-9962': $this->range("0000000", "5499999", 2, 2); $this->range("5500000", "5599999", 4, 2); $this->range("5600000", "5999999", 2, 2); $this->range("6000000", "8499999", 3, 2); $this->range("8500000", "9999999", 4, 2); break; case '978-9963': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "2499999", 4, 2); $this->range("2500000", "2799999", 3, 2); $this->range("2800000", "2999999", 4, 2); $this->range("3000000", "5499999", 2, 2); $this->range("5500000", "7349999", 3, 2); $this->range("7350000", "7499999", 4, 2); $this->range("7500000", "9999999", 4, 2); break; case '978-9964': $this->range("0000000", "6999999", 1, 2); $this->range("7000000", "9499999", 2, 2); $this->range("9500000", "9999999", 3, 2); break; case '978-9965': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9966': $this->range("0000000", "1499999", 3, 2); $this->range("1500000", "1999999", 4, 2); $this->range("2000000", "6999999", 2, 2); $this->range("7000000", "7499999", 4, 2); $this->range("7500000", "9599999", 3, 2); $this->range("9600000", "9999999", 4, 2); break; case '978-9967': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9968': $this->range("0000000", "4999999", 2, 2); $this->range("5000000", "9399999", 3, 2); $this->range("9400000", "9999999", 4, 2); break; case '978-9970': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9971': $this->range("0000000", "5999999", 1, 2); $this->range("6000000", "8999999", 2, 2); $this->range("9000000", "9899999", 3, 2); $this->range("9900000", "9999999", 4, 2); break; case '978-9972': $this->range("0000000", "0999999", 2, 2); $this->range("1000000", "1999999", 1, 2); $this->range("2000000", "2499999", 3, 2); $this->range("2500000", "2999999", 4, 2); $this->range("3000000", "5999999", 2, 2); $this->range("6000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9973': $this->range("0000000", "0599999", 2, 2); $this->range("0600000", "0899999", 3, 2); $this->range("0900000", "0999999", 4, 2); $this->range("1000000", "6999999", 2, 2); $this->range("7000000", "9699999", 3, 2); $this->range("9700000", "9999999", 4, 2); break; case '978-9974': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "5499999", 2, 2); $this->range("5500000", "7499999", 3, 2); $this->range("7500000", "8799999", 4, 2); $this->range("8800000", "9099999", 3, 2); $this->range("9100000", "9499999", 2, 2); $this->range("9500000", "9999999", 2, 2); break; case '978-9975': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "2999999", 3, 2); $this->range("3000000", "3999999", 4, 2); $this->range("4000000", "4499999", 4, 2); $this->range("4500000", "8999999", 2, 2); $this->range("9000000", "9499999", 3, 2); $this->range("9500000", "9999999", 4, 2); break; case '978-9976': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "5999999", 4, 2); $this->range("6000000", "8999999", 2, 2); $this->range("9000000", "9899999", 3, 2); $this->range("9900000", "9999999", 4, 2); break; case '978-9977': $this->range("0000000", "8999999", 2, 2); $this->range("9000000", "9899999", 3, 2); $this->range("9900000", "9999999", 4, 2); break; case '978-9978': $this->range("0000000", "2999999", 2, 2); $this->range("3000000", "3999999", 3, 2); $this->range("4000000", "9499999", 2, 2); $this->range("9500000", "9899999", 3, 2); $this->range("9900000", "9999999", 4, 2); break; case '978-9979': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "6499999", 2, 2); $this->range("6500000", "6599999", 3, 2); $this->range("6600000", "7599999", 2, 2); $this->range("7600000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9980': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "8999999", 2, 2); $this->range("9000000", "9899999", 3, 2); $this->range("9900000", "9999999", 4, 2); break; case '978-9981': $this->range("0000000", "0999999", 2, 2); $this->range("1000000", "1599999", 3, 2); $this->range("1600000", "1999999", 4, 2); $this->range("2000000", "7999999", 2, 2); $this->range("8000000", "9499999", 3, 2); $this->range("9500000", "9999999", 4, 2); break; case '978-9982': $this->range("0000000", "7999999", 2, 2); $this->range("8000000", "9899999", 3, 2); $this->range("9900000", "9999999", 4, 2); break; case '978-9983': $this->range("0000000", "7999999", 0, 2); $this->range("8000000", "9499999", 2, 2); $this->range("9500000", "9899999", 3, 2); $this->range("9900000", "9999999", 4, 2); break; case '978-9984': $this->range("0000000", "4999999", 2, 2); $this->range("5000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9985': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "8999999", 3, 2); $this->range("9000000", "9999999", 4, 2); break; case '978-9986': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "8999999", 3, 2); $this->range("9000000", "9399999", 4, 2); $this->range("9400000", "9699999", 3, 2); $this->range("9700000", "9999999", 2, 2); break; case '978-9987': $this->range("0000000", "3999999", 2, 2); $this->range("4000000", "8799999", 3, 2); $this->range("8800000", "9999999", 4, 2); break; case '978-9988': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "5499999", 2, 2); $this->range("5500000", "7499999", 3, 2); $this->range("7500000", "9999999", 4, 2); break; case '978-9989': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "1999999", 3, 2); $this->range("2000000", "2999999", 4, 2); $this->range("3000000", "5999999", 2, 2); $this->range("6000000", "9499999", 3, 2); $this->range("9500000", "9999999", 4, 2); break; case '978-99901': $this->range("0000000", "4999999", 2, 2); $this->range("5000000", "7999999", 3, 2); $this->range("8000000", "9999999", 2, 2); break; case '978-99902': $this->range("0000000", "9999999", 0, 2); break; case '978-99903': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99904': $this->range("0000000", "5999999", 1, 2); $this->range("6000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99905': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99906': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "5999999", 2, 2); $this->range("6000000", "6999999", 3, 2); $this->range("7000000", "8999999", 2, 2); $this->range("9000000", "9499999", 2, 2); $this->range("9500000", "9999999", 3, 2); break; case '978-99908': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99909': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "9499999", 2, 2); $this->range("9500000", "9999999", 3, 2); break; case '978-99910': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99911': $this->range("0000000", "5999999", 2, 2); $this->range("6000000", "9999999", 3, 2); break; case '978-99912': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "5999999", 3, 2); $this->range("6000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99913': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "3599999", 2, 2); $this->range("3600000", "5999999", 0, 2); $this->range("6000000", "6049999", 3, 2); $this->range("6050000", "9999999", 0, 2); break; case '978-99914': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "6999999", 2, 2); $this->range("7000000", "7999999", 1, 2); $this->range("8000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99915': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99916': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "6999999", 2, 2); $this->range("7000000", "9999999", 3, 2); break; case '978-99917': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99918': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99919': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "3999999", 3, 2); $this->range("4000000", "6999999", 2, 2); $this->range("7000000", "7999999", 2, 2); $this->range("8000000", "8499999", 3, 2); $this->range("8500000", "8999999", 3, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99920': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99921': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "6999999", 2, 2); $this->range("7000000", "7999999", 3, 2); $this->range("8000000", "8999999", 1, 2); $this->range("9000000", "9999999", 2, 2); break; case '978-99922': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "6999999", 2, 2); $this->range("7000000", "9999999", 3, 2); break; case '978-99923': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99924': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99925': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99926': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "5999999", 2, 2); $this->range("6000000", "8699999", 3, 2); $this->range("8700000", "8999999", 2, 2); $this->range("9000000", "9999999", 2, 2); break; case '978-99927': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "5999999", 2, 2); $this->range("6000000", "9999999", 3, 2); break; case '978-99928': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99929': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99930': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99931': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99932': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "5999999", 2, 2); $this->range("6000000", "6999999", 3, 2); $this->range("7000000", "7999999", 1, 2); $this->range("8000000", "9999999", 2, 2); break; case '978-99933': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "5999999", 2, 2); $this->range("6000000", "9999999", 3, 2); break; case '978-99934': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99935': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "5999999", 2, 2); $this->range("6000000", "6999999", 3, 2); $this->range("7000000", "8999999", 1, 2); $this->range("9000000", "9999999", 2, 2); break; case '978-99936': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "5999999", 2, 2); $this->range("6000000", "9999999", 3, 2); break; case '978-99937': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "5999999", 2, 2); $this->range("6000000", "9999999", 3, 2); break; case '978-99938': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "5999999", 2, 2); $this->range("6000000", "8999999", 3, 2); $this->range("9000000", "9999999", 2, 2); break; case '978-99939': $this->range("0000000", "5999999", 1, 2); $this->range("6000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99940': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "6999999", 2, 2); $this->range("7000000", "9999999", 3, 2); break; case '978-99941': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99942': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99943': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "5999999", 2, 2); $this->range("6000000", "9999999", 3, 2); break; case '978-99944': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99945': $this->range("0000000", "5999999", 1, 2); $this->range("6000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99946': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "5999999", 2, 2); $this->range("6000000", "9999999", 3, 2); break; case '978-99947': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "6999999", 2, 2); $this->range("7000000", "9999999", 3, 2); break; case '978-99948': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99949': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99950': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99951': $this->range("0000000", "9999999", 0, 2); break; case '978-99952': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99953': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "7999999", 2, 2); $this->range("8000000", "9399999", 3, 2); $this->range("9400000", "9999999", 2, 2); break; case '978-99954': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "6999999", 2, 2); $this->range("7000000", "8799999", 3, 2); $this->range("8800000", "9999999", 2, 2); break; case '978-99955': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "5999999", 2, 2); $this->range("6000000", "7999999", 3, 2); $this->range("8000000", "9999999", 2, 2); break; case '978-99956': $this->range("0000000", "5999999", 2, 2); $this->range("6000000", "8599999", 3, 2); $this->range("8600000", "9999999", 2, 2); break; case '978-99957': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "7999999", 2, 2); $this->range("8000000", "9399999", 3, 2); $this->range("9400000", "9999999", 2, 2); break; case '978-99958': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "9399999", 2, 2); $this->range("9400000", "9499999", 3, 2); $this->range("9500000", "9999999", 3, 2); break; case '978-99959': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "5999999", 2, 2); $this->range("6000000", "9999999", 3, 2); break; case '978-99960': $this->range("0000000", "0999999", 1, 2); $this->range("1000000", "9499999", 2, 2); $this->range("9500000", "9999999", 3, 2); break; case '978-99961': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "3999999", 3, 2); $this->range("4000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99962': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99963': $this->range("0000000", "4999999", 2, 2); $this->range("5000000", "9199999", 3, 2); $this->range("9200000", "9999999", 2, 2); break; case '978-99964': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99965': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "3599999", 3, 2); $this->range("3600000", "6299999", 2, 2); $this->range("6300000", "9999999", 3, 2); break; case '978-99966': $this->range("0000000", "2999999", 1, 2); $this->range("3000000", "6999999", 2, 2); $this->range("7000000", "7999999", 3, 2); $this->range("8000000", "9699999", 2, 2); $this->range("9700000", "9999999", 3, 2); break; case '978-99967': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "5999999", 2, 2); $this->range("6000000", "8999999", 3, 2); $this->range("9000000", "9999999", 0, 2); break; case '978-99968': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "5999999", 3, 2); $this->range("6000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99969': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99970': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99971': $this->range("0000000", "5999999", 1, 2); $this->range("6000000", "8499999", 2, 2); $this->range("8500000", "9999999", 3, 2); break; case '978-99972': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "8999999", 2, 2); $this->range("9000000", "9999999", 3, 2); break; case '978-99973': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99974': $this->range("0000000", "3999999", 0, 2); $this->range("4000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99975': $this->range("0000000", "3999999", 1, 2); $this->range("4000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99976': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "5999999", 2, 2); $this->range("6000000", "7999999", 3, 2); $this->range("8000000", "9999999", 0, 2); break; case '978-99977': $this->range("0000000", "1999999", 1, 2); $this->range("2000000", "3999999", 0, 2); $this->range("4000000", "6999999", 2, 2); $this->range("7000000", "7999999", 3, 2); $this->range("8000000", "9999999", 0, 2); break; case '978-99978': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '978-99979': $this->range("0000000", "4999999", 1, 2); $this->range("5000000", "7999999", 2, 2); $this->range("8000000", "9999999", 3, 2); break; case '979-10': $this->range("0000000", "1999999", 2, 2); $this->range("2000000", "6999999", 3, 2); $this->range("7000000", "8999999", 4, 2); $this->range("9000000", "9759999", 5, 2); $this->range("9760000", "9999999", 6, 2); break; case '979-11': $this->range("0000000", "2499999", 2, 2); $this->range("2500000", "5499999", 3, 2); $this->range("5500000", "8499999", 4, 2); $this->range("8500000", "9499999", 5, 2); $this->range("9500000", "9999999", 6, 2); break; case '979-12': $this->range("0000000", "1999999", 0, 2); $this->range("2000000", "2009999", 3, 2); $this->range("2010000", "9999999", 0, 2); break; } }
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 (preg_match('/\d{9}[0-9xX]/i',$isbn) == false) { return false; } //Verify checksum $check = 0; for ($i = 0; $i < 10; $i++) { if (strtoupper($isbn[$i]) === 'X') { $check += 10 * intval(10 - $i); } else { $check += intval($isbn[$i]) * intval(10 - $i); } } return $check % 11 === 0; }
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; } if (preg_match('/\d{13}/i',$isbn) == false) { return false; } //Verify checksum $check = 0; for ($i = 0; $i < 13; $i += 2) { $check += substr($isbn, $i, 1); } for ($i = 1; $i < 12; $i += 2) { $check += 3 * substr($isbn, $i, 1); } return $check % 10 === 0; }
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 (strlen($isbn) === 9 or strlen($isbn) === 10) { return $this->make10($isbn); } return false; }
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 check digit $check = 0; for ($i = 0; $i < 9; $i++) { if ($isbn[$i] === 'X') { $check += 10 * intval(10 - $i); } else { $check += intval($isbn[$i]) * intval(10 - $i); } } $check = 11 - $check % 11; if ($check === 10) { return 'X'; } elseif ($check === 11) { return 0; } return $check; }
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 format.'); } //Calculate check digit $check = 0; for ($i = 0; $i < 12; $i += 2) { $check += substr($isbn, $i, 1); } for ($i = 1; $i < 12; $i += 2) { $check += 3 * substr($isbn, $i, 1); } $check = 10 - $check % 10; if ($check === 10) { return 0; } return $check; }
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' && $this->httpRequest->getControllerName() === 'index') { return $this->getLumaThemeId(); } return $proceed(...$args); }
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 `config/app.php` file."); } } }
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('REMOTE_ADDR'); //Try to get client IP from SERVER variables if(!$ipaddress) { return $this->getClientIpFromServerVar(); } return $ipaddress; }
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['HTTP_X_FORWARDED'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED']; else if(isset($_SERVER['HTTP_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; else if(isset($_SERVER['HTTP_FORWARDED'])) $ipaddress = $_SERVER['HTTP_FORWARDED']; else if(isset($_SERVER['REMOTE_ADDR'])) $ipaddress = $_SERVER['REMOTE_ADDR']; else $ipaddress = 'UNKNOWN'; return $ipaddress; }
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 is set */ if (empty($this->api_secret)) { throw new \Exception("Please configure your ICEPAY Secret Code."); } /** * Check if the CompletedURL is set */ if (empty($this->api_completed_url)) { throw new \Exception("Please configure your setCompletedURL()"); } /** * Check if the ErrorURL is set */ if (empty($this->api_error_url)) { throw new \Exception("Please configure your setErrorURL()"); } /** * Start a curl session */ if (empty($this->ch) || !function_exists("curl_reset")) { $this->ch = curl_init(); } else { curl_reset($this->ch); } /** * Set the curl options */ curl_setopt($this->ch, CURLOPT_URL, $this->api_endpoint . $api_method); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($this->ch, CURLOPT_TIMEOUT, 15); curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($this->ch, CURLOPT_HEADER, TRUE); /** * Possible output: 5.6.9 */ $php_version = phpversion(); /** * Prepare the curl headers */ $api_headers = array( "MerchantID: {$this->api_key}", "Checksum: {$checksum}", "User-Agent: ICEPAY API/{$this->api_version} PHP/{$php_version}", "Accept: application/json" ); /** * If the body is not null, let curl post the request as json content */ if ($body !== NULL) { $api_headers[] = "Content-Type: application/json"; curl_setopt($this->ch, CURLOPT_POST, 1); curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($body)); } /** * Set the curl headers for the payment server */ curl_setopt($this->ch, CURLOPT_HTTPHEADER, $api_headers); /** * Set the SSL options */ curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, TRUE); /** * Execute the request */ $response = curl_exec($this->ch); /** * Invalid or no certificate authority found, using bundled information */ if (curl_errno($this->ch) == 77 /* CURLE_SSL_CACERT_BADFILE */ || curl_errno($this->ch) == 60 /* CURLE_SSL_CACERT */) { curl_setopt($this->ch, CURLOPT_CAINFO, realpath(dirname(__FILE__) . '/Assets/icepay.pem')); $response = curl_exec($this->ch); } // /** // * Verifying peer certificate fails on OpenSSL 0.9 or earlier. // * We done all we could to check the certificate on the host. // * This webserver simply will not accept it and we need to connect. // */ // Uncommenting this code block can be insecure, use at your own risk // if (strpos(curl_error($this->ch), 'certificate subject name') !== FALSE) { // curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0); // // $response = curl_exec($this->ch); // } /** * Check if we got any error, if so, exception it */ if (curl_errno($this->ch)) { $exception_no = curl_errno($this->ch); $exception = curl_error($this->ch); curl_close($this->ch); $this->ch = NULL; throw new \Exception('Unable to reach the ICEPAY payment server (' . $exception_no . '):' . $exception); } /** * Separate headers and response body */ $header_size = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE); $response_header = substr($response, 0, $header_size); $response_body = substr($response, $header_size); /** * Close the connection */ if (!function_exists("curl_reset")) { curl_close($this->ch); $this->ch = null; } else { curl_reset($this->ch); $this->ch = null; } /** * Verify response checksum. If it does not match, throw an exception. * Always require presence of a checksum header. */ $parsed_headers = $this->parse_headers($response_header); if (isset($parsed_headers[0]["Checksum"])) { $checksumVerification = $this->generateChecksum( $this->api_endpoint . $api_method . $this->api_post . $this->api_key . $this->api_secret . $response_body ); if ($checksumVerification != $parsed_headers[0]["Checksum"]) { throw new \Exception("Response checksum invalid"); } } else { //if no checksum header was present in the response, the most likely cause is that the sender ID was invalid throw new \Exception("Response checksum not found. Verify your merchant ID."); } /** * Return the decoded json response */ return json_decode($response_body); }
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 service // in services collection. if (isset($this->services[$key])) { // Resolve service jf we don't have // a deposit for this service. if ( ! isset($this->deposit[$key])) { $this->deposit[$key] = $this->resolve($this->services[$key], $parameters); } return $this->deposit[$key]; } throw new BindingResolutionException("Unresolvable resolution. The [{$key}] binding is not registered."); }
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) ->subcompile($this->getNode('body')) ->write('$inkyHtml = ob_get_clean();' . PHP_EOL) ->write("echo \$this->env->getExtension('{$extensionName}')->parse(\$inkyHtml);" . 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->checkDigit->make($isbn); }
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); return new InkyNode($body, $lineno, $this->getTag()); }
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; return; } throw new FileNotFoundException("Template file [{$this->getRelativePath()}] cannot be located."); }
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_array($this->file) && isset($this->file[0])) { return do_action("get_template_part_{$this->file[0]}", $this->file[0], null); } do_action("get_template_part_{$this->file}", $this->file, null); }
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 named. if (is_array($this->file) && isset($this->file[0])) { return "{$this->file[0]}{$extension}"; } return apply_filters('tonik/gin/template/filename', "{$this->file}{$extension}"); }
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 ( isset($this->file[1]) && is_bool($this->file[1]) // should be set and not be a boolean || null === $this->file[1] // or null value || empty($this->file[1]) // or empty sting or array ) { return false; } return true; }
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' : ''; $difference = floor(abs($difference)); // If difference is plural, add an 's' to $unit if ($difference > 1) { $unit = $unit . 's'; } return sprintf('%s%d %s%s', $prepend, $difference, $unit, $append); }
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 $difference The difference between dates in any unit @param string $unit The unit of time @return string The date in human readable format
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 difference between the current date and the supplied $dateTime $difference = $reference->format('U') - $dateTime->format('U'); $absDiff = abs($difference); // Get the date corresponding to the $dateTime $date = $dateTime->format('Y/m/d'); // Throw exception if the difference is NaN if (is_nan($difference)) { throw new Exception('The difference between the DateTimes is NaN.'); } // Today if ($reference->format('Y/m/d') == $date) { if (0 <= $difference && $absDiff < self::MINUTE) { return 'Moments ago'; } elseif ($difference < 0 && $absDiff < self::MINUTE) { return 'Seconds from now'; } elseif ($absDiff < self::HOUR) { return self::prettyFormat($difference / self::MINUTE, 'minute'); } else { return self::prettyFormat($difference / self::HOUR, 'hour'); } } $yesterday = clone $reference; $yesterday->modify('- 1 day'); $tomorrow = clone $reference; $tomorrow->modify('+ 1 day'); if ($yesterday->format('Y/m/d') == $date) { return 'Yesterday'; } else if ($tomorrow->format('Y/m/d') == $date) { return 'Tomorrow'; } else if ($absDiff / self::DAY <= 7) { return self::prettyFormat($difference / self::DAY, 'day'); } else if ($absDiff / self::WEEK <= 5) { return self::prettyFormat($difference / self::WEEK, 'week'); } else if ($absDiff / self::MONTH < 12) { return self::prettyFormat($difference / self::MONTH, 'month'); } // Over a year ago return self::prettyFormat($difference / self::YEAR, 'year'); }
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 @param DateTime $reference (Optional) Defaults to the DateTime('now') @return string The date in human readable format
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('sha256', $ciphertext_raw, $this->saltedKey, $as_binary = true); $ciphertext = base64_encode($iv.$hmac.$ciphertext_raw); return base64_encode($iv.$hmac.$ciphertext_raw); }
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 = openssl_decrypt($ciphertext_raw, $cipher, $this->saltedKey, $options = OPENSSL_RAW_DATA, $iv); $calcmac = hash_hmac('sha256', $ciphertext_raw, $this->saltedKey, $as_binary = true); if (hash_equals($hmac, $calcmac)) { return $cleartext; } return false; }
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 new Exception('HybridSessions\Store\DatabaseStore currently only works with MySQL databases'); } // Prevent freakout during dev/build return ClassInfo::hasTable('HybridSessionDataObject'); }
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