code
stringlengths 17
247k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function setConditions(Closure|array $conditions)
{
$this->_conditions = $conditions;
return $this;
} | Sets a list of conditions to be always included when fetching records from
the target association.
@param \Closure|array $conditions list of conditions to be used
@see \Cake\Database\Query::where() for examples on the format of the array
@return $this | setConditions | php | cakephp/cakephp | src/ORM/Association.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association.php | MIT |
public function setBindingKey(array|string $key)
{
$this->_bindingKey = $key;
return $this;
} | Sets the name of the field representing the binding field with the target table.
When not manually specified the primary key of the owning side table is used.
@param array<string>|string $key the table field or fields to be used to link both tables together
@return $this | setBindingKey | php | cakephp/cakephp | src/ORM/Association.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association.php | MIT |
public function setForeignKey(array|string $key)
{
$this->_foreignKey = $key;
return $this;
} | Sets the name of the field representing the foreign key to the target table.
@param array<string>|string $key the key or keys to be used to link both tables together
@return $this | setForeignKey | php | cakephp/cakephp | src/ORM/Association.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association.php | MIT |
public function setDependent(bool $dependent)
{
$this->_dependent = $dependent;
return $this;
} | Sets whether the records on the target table are dependent on the source table.
This is primarily used to indicate that records should be removed if the owning record in
the source table is deleted.
If no parameters are passed the current setting is returned.
@param bool $dependent Set the dependent mode. Use null to read the current state.
@return $this | setDependent | php | cakephp/cakephp | src/ORM/Association.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association.php | MIT |
public function setJoinType(string $type)
{
$this->_joinType = $type;
return $this;
} | Sets the type of join to be used when adding the association to a query.
@param string $type the join type to be used (e.g. INNER)
@return $this | setJoinType | php | cakephp/cakephp | src/ORM/Association.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association.php | MIT |
public function setProperty(string $name)
{
$this->_propertyName = $name;
return $this;
} | Sets the property name that should be filled with data from the target table
in the source table record.
@param string $name The name of the association property. Use null to read the current value.
@return $this | setProperty | php | cakephp/cakephp | src/ORM/Association.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association.php | MIT |
public function setStrategy(string $name)
{
if (!in_array($name, $this->_validStrategies, true)) {
throw new InvalidArgumentException(sprintf(
'Invalid strategy `%s` was provided. Valid options are `(%s)`.',
$name,
implode(', ', $this->_validStrategies),
));
}
$this->_strategy = $name;
return $this;
} | Sets the strategy name to be used to fetch associated records. Keep in mind
that some association types might not implement but a default strategy,
rendering any changes to this setting void.
@param string $name The strategy type. Use null to read the current value.
@return $this
@throws \InvalidArgumentException When an invalid strategy is provided. | setStrategy | php | cakephp/cakephp | src/ORM/Association.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association.php | MIT |
public function setFinder(array|string $finder)
{
$this->_finder = $finder;
return $this;
} | Sets the default finder to use for fetching rows from the target table.
@param array|string $finder the finder name to use or array of finder name and option.
@return $this | setFinder | php | cakephp/cakephp | src/ORM/Association.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association.php | MIT |
public function setResultSetClass(string $resultSetClass)
{
if (!is_a($resultSetClass, ResultSetInterface::class, true)) {
throw new InvalidArgumentException(sprintf(
'Invalid ResultSet class `%s`. It must implement `%s`',
$resultSetClass,
ResultSetInterface::class,
));
}
$this->resultSetClass = $resultSetClass;
return $this;
} | Set the ResultSet class to use.
@param class-string<\Cake\Datasource\ResultSetInterface> $resultSetClass Class name.
@return $this | setResultSetClass | php | cakephp/cakephp | src/ORM/ResultSetFactory.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/ResultSetFactory.php | MIT |
public function setResult(iterable $results)
{
$this->_results = $results;
return $this;
} | Set the result set for a query.
Setting the result set of a query will make execute() a no-op. Instead
of executing the SQL query and fetching results, the ResultSet provided to this
method will be returned.
This method is most useful when combined with results stored in a persistent cache.
@param iterable $results The results this query should return.
@return $this | setResult | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function eagerLoaded(bool $value)
{
$this->_eagerLoaded = $value;
return $this;
} | Sets the query instance to be an eager loaded query. If no argument is
passed, the current configured query `_eagerLoaded` value is returned.
@param bool $value Whether to eager load.
@return $this | eagerLoaded | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function mapReduce(?Closure $mapper = null, ?Closure $reducer = null, bool $overwrite = false)
{
if ($overwrite) {
$this->_mapReduce = [];
}
if ($mapper === null) {
if (!$overwrite) {
throw new InvalidArgumentException('$mapper can be null only when $overwrite is true.');
}
return $this;
}
$this->_mapReduce[] = compact('mapper', 'reducer');
return $this;
} | Register a new MapReduce routine to be executed on top of the database results
The MapReduce routing will only be run when the query is executed and the first
result is attempted to be fetched.
If the third argument is set to true, it will erase previous map reducers
and replace it with the arguments passed.
@param \Closure|null $mapper The mapper function
@param \Closure|null $reducer The reducing function
@param bool $overwrite Set to true to overwrite existing map + reduce functions.
@return $this
@see \Cake\Collection\Iterator\MapReduce for details on how to use emit data to the map reducer. | mapReduce | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function selectAlso(
ExpressionInterface|Table|Association|Closure|array|string|float|int $fields,
) {
$this->select($fields);
$this->_autoFields = true;
return $this;
} | Behaves the exact same as `select()` except adds the field to the list of fields selected and
does not disable auto-selecting fields for Associations.
Use this instead of calling `select()` then `enableAutoFields()` to re-enable auto-fields.
@param \Cake\Database\ExpressionInterface|\Cake\ORM\Table|\Cake\ORM\Association|\Closure|array|string|float|int $fields Fields
to be added to the list.
@return $this | selectAlso | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function selectAllExcept(Table|Association $table, array $excludedFields, bool $overwrite = false)
{
if ($table instanceof Association) {
$table = $table->getTarget();
}
$fields = array_diff($table->getSchema()->columns(), $excludedFields);
if ($this->aliasingEnabled) {
$fields = $this->aliasFields($fields);
}
return $this->select($fields, $overwrite);
} | All the fields associated with the passed table except the excluded
fields will be added to the select clause of the query. Passed excluded fields should not be aliased.
After the first call to this method, a second call cannot be used to remove fields that have already
been added to the query by the first. If you need to change the list after the first call,
pass overwrite boolean true which will reset the select clause removing all previous additions.
@param \Cake\ORM\Table|\Cake\ORM\Association $table The table to use to get an array of columns
@param array<string> $excludedFields The un-aliased column names you do not want selected from $table
@param bool $overwrite Whether to reset/remove previous selected fields
@return $this | selectAllExcept | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function setEagerLoader(EagerLoader $instance)
{
$this->_eagerLoader = $instance;
return $this;
} | Sets the instance of the eager loader class to use for loading associations
and storing containments.
@param \Cake\ORM\EagerLoader $instance The eager loader to use.
@return $this | setEagerLoader | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function clearContain()
{
$this->getEagerLoader()->clearContain();
$this->_dirty();
return $this;
} | Clears the contained associations from the current query.
@return $this | clearContain | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function clearResult()
{
$this->_dirty();
return $this;
} | Clears the internal result cache and the internal count value from the current
query object.
@return $this | clearResult | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function counter(?Closure $counter)
{
$this->_counter = $counter;
return $this;
} | Registers a callback that will be executed when the `count` method in
this query is called. The return value for the function will be set as the
return value of the `count` method.
This is particularly useful when you need to optimize a query for returning the
count, for example removing unnecessary joins, removing group by or just return
an estimated number of rows.
The callback will receive as first argument a clone of this query and not this
query itself.
If the first param is a null value, the built-in counter function will be called
instead
@param \Closure|null $counter The counter value
@return $this | counter | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function enableHydration(bool $enable = true)
{
$this->_dirty();
$this->_hydrate = $enable;
return $this;
} | Toggle hydrating entities.
If set to false array results will be returned for the query.
@param bool $enable Use a boolean to set the hydration mode.
@return $this | enableHydration | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function disableHydration()
{
$this->_dirty();
$this->_hydrate = false;
return $this;
} | Disable hydrating entities.
Disabling hydration will cause array results to be returned for the query
instead of entities.
@return $this | disableHydration | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function disableAutoAliasing()
{
$this->aliasingEnabled = false;
return $this;
} | Disable auto adding table's alias to the fields of SELECT clause.
@return $this | disableAutoAliasing | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function enableAutoFields(bool $value = true)
{
$this->_autoFields = $value;
return $this;
} | Sets whether the ORM should automatically append fields.
By default, calling select() will disable auto-fields. You can re-enable
auto-fields with this method.
@param bool $value Set true to enable, false to disable.
@return $this | enableAutoFields | php | cakephp/cakephp | src/ORM/Query/SelectQuery.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/SelectQuery.php | MIT |
public function addDefaultTypes(Table $table)
{
$alias = $table->getAlias();
$map = $table->getSchema()->typeMap();
$fields = [];
foreach ($map as $f => $type) {
$fields[$f] = $fields[$alias . '.' . $f] = $fields[$alias . '__' . $f] = $type;
}
$this->getTypeMap()->addDefaults($fields);
return $this;
} | Hints this object to associate the correct types when casting conditions
for the database. This is done by extracting the field types from the schema
associated to the passed table object. This prevents the user from repeating
themselves when specifying conditions.
This method returns the same query object for chaining.
@param \Cake\ORM\Table $table The table to pull types from
@return $this | addDefaultTypes | php | cakephp/cakephp | src/ORM/Query/CommonQueryTrait.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/CommonQueryTrait.php | MIT |
public function setRepository(RepositoryInterface $repository)
{
assert(
$repository instanceof Table,
'`$repository` must be an instance of `' . Table::class . '`.',
);
$this->_repository = $repository;
return $this;
} | Set the default Table object that will be used by this query
and form the `FROM` clause.
@param \Cake\Datasource\RepositoryInterface $repository The default table object to use
@return $this | setRepository | php | cakephp/cakephp | src/ORM/Query/CommonQueryTrait.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Query/CommonQueryTrait.php | MIT |
public function setForeignKey(array|string|false $key)
{
$this->_foreignKey = $key;
return $this;
} | Sets the name of the field representing the foreign key to the target table.
@param array<string>|string|false $key the key or keys to be used to link both tables together, if set to `false`
no join conditions will be generated automatically.
@return $this | setForeignKey | php | cakephp/cakephp | src/ORM/Association/HasOne.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association/HasOne.php | MIT |
public function setSaveStrategy(string $strategy)
{
if (!in_array($strategy, [self::SAVE_APPEND, self::SAVE_REPLACE], true)) {
$msg = sprintf('Invalid save strategy `%s`', $strategy);
throw new InvalidArgumentException($msg);
}
$this->_saveStrategy = $strategy;
return $this;
} | Sets the strategy that should be used for saving.
@param string $strategy the strategy name to be used
@throws \InvalidArgumentException if an invalid strategy name is passed
@return $this | setSaveStrategy | php | cakephp/cakephp | src/ORM/Association/HasMany.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association/HasMany.php | MIT |
public function setSort(ExpressionInterface|Closure|array|string $sort)
{
$this->_sort = $sort;
return $this;
} | Sets the sort order in which target records should be returned.
@param \Cake\Database\ExpressionInterface|\Closure|array<\Cake\Database\ExpressionInterface|string>|string $sort A find() compatible order clause
@return $this | setSort | php | cakephp/cakephp | src/ORM/Association/HasMany.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association/HasMany.php | MIT |
public function setTargetForeignKey(array|string $key)
{
$this->_targetForeignKey = $key;
return $this;
} | Sets the name of the field representing the foreign key to the target table.
@param array<string>|string $key the key to be used to link both tables together
@return $this | setTargetForeignKey | php | cakephp/cakephp | src/ORM/Association/BelongsToMany.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association/BelongsToMany.php | MIT |
public function setJunctionProperty(string $junctionProperty)
{
$this->_junctionProperty = $junctionProperty;
return $this;
} | Set the junction property name.
@param string $junctionProperty Property name.
@return $this | setJunctionProperty | php | cakephp/cakephp | src/ORM/Association/BelongsToMany.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association/BelongsToMany.php | MIT |
public function setThrough(Table|string $through)
{
$this->_through = $through;
return $this;
} | Sets the current join table, either the name of the Table instance or the instance itself.
@param \Cake\ORM\Table|string $through Name of the Table instance or the instance itself
@return $this | setThrough | php | cakephp/cakephp | src/ORM/Association/BelongsToMany.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association/BelongsToMany.php | MIT |
public function __construct(array $options)
{
$this->alias = $options['alias'];
$this->sourceAlias = $options['sourceAlias'];
$this->targetAlias = $options['targetAlias'];
$this->foreignKey = $options['foreignKey'];
$this->strategy = $options['strategy'];
$this->bindingKey = $options['bindingKey'];
$this->finder = $options['finder'];
$this->associationType = $options['associationType'];
$this->sort = $options['sort'] ?? null;
} | Copies the options array to properties in this class. The keys in the array correspond
to properties in this class.
@param array<string, mixed> $options Properties to be copied to this class | __construct | php | cakephp/cakephp | src/ORM/Association/Loader/SelectLoader.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Association/Loader/SelectLoader.php | MIT |
public function __construct(Table $table, array $config = [])
{
$config += [
'defaultLocale' => I18n::getDefaultLocale(),
'referenceName' => $this->referenceName($table),
'tableLocator' => $table->associations()->getTableLocator(),
];
parent::__construct($table, $config);
} | Constructor
### Options
- `fields`: List of fields which need to be translated. Providing this fields
list is mandatory when using `EavStrategy`. If the fields list is empty when
using `ShadowTableStrategy` then the list will be auto generated based on
shadow table schema.
- `defaultLocale`: The locale which is treated as default by the behavior.
Fields values for default locale will be stored in the primary table itself
and the rest in translation table. If not explicitly set the value of
`I18n::getDefaultLocale()` will be used to get default locale.
If you do not want any default locale and want translated fields
for all locales to be stored in translation table then set this config
to empty string `''`.
- `allowEmptyTranslations`: By default if a record has been translated and
stored as an empty string the translate behavior will take and use this
value to overwrite the original field value. If you don't want this behavior
then set this option to `false`.
- `validator`: The validator that should be used when translation records
are created/modified. Default `null`.
@param \Cake\ORM\Table $table The table this behavior is attached to.
@param array<string, mixed> $config The config for this behavior. | __construct | php | cakephp/cakephp | src/ORM/Behavior/TranslateBehavior.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Behavior/TranslateBehavior.php | MIT |
public function setLocale(?string $locale)
{
$this->getStrategy()->setLocale($locale);
return $this;
} | Sets the locale that should be used for all future find and save operations on
the table where this behavior is attached to.
When fetching records, the behavior will include the content for the locale set
via this method, and likewise when saving data, it will save the data in that
locale.
Note that in case an entity has a `_locale` property set, that locale will win
over the locale set via this method (and over the globally configured one for
that matter)!
@param string|null $locale The locale to use for fetching and saving records. Pass `null`
in order to unset the current locale, and to make the behavior falls back to using the
globally configured locale.
@return $this
@see \Cake\ORM\Behavior\TranslateBehavior::getLocale()
@link https://book.cakephp.org/5/en/orm/behaviors/translate.html#retrieving-one-language-without-using-i18n-locale
@link https://book.cakephp.org/5/en/orm/behaviors/translate.html#saving-in-another-language | setLocale | php | cakephp/cakephp | src/ORM/Behavior/TranslateBehavior.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Behavior/TranslateBehavior.php | MIT |
public function translation(string $language)
{
if ($language === $this->get('_locale')) {
return $this;
}
$i18n = $this->has('_translations') ? $this->get('_translations') : null;
$created = false;
if (!$i18n) {
$i18n = [];
$created = true;
}
if ($created || empty($i18n[$language]) || !($i18n[$language] instanceof EntityInterface)) {
$className = static::class;
$i18n[$language] = new $className();
$created = true;
}
if ($created) {
$this->set('_translations', $i18n);
}
// Assume the user will modify any of the internal translations, helps with saving
$this->setDirty('_translations', true);
return $i18n[$language];
} | Returns the entity containing the translated fields for this object and for
the specified language. If the translation for the passed language is not
present, a new empty entity will be created so that values can be added to
it.
@param string $language Language to return entity for.
@return \Cake\Datasource\EntityInterface|$this | translation | php | cakephp/cakephp | src/ORM/Behavior/Translate/TranslateTrait.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Behavior/Translate/TranslateTrait.php | MIT |
public function setLocale(?string $locale)
{
$this->locale = $locale;
return $this;
} | Sets the locale to be used.
When fetching records, the content for the locale set via this method,
and likewise when saving data, it will save the data in that locale.
Note that in case an entity has a `_locale` property set, that locale
will win over the locale set via this method (and over the globally
configured one for that matter)!
@param string|null $locale The locale to use for fetching and saving
records. Pass `null` in order to unset the current locale, and to make
the behavior falls back to using the globally configured locale.
@return $this | setLocale | php | cakephp/cakephp | src/ORM/Behavior/Translate/TranslateStrategyTrait.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Behavior/Translate/TranslateStrategyTrait.php | MIT |
public function __construct(array $fields, array $options = [])
{
$this->_fields = $fields;
$this->_options = $options + $this->_options;
} | Constructor.
### Options
- `allowMultipleNulls` Allows any field to have multiple null values. Defaults to true.
@param array<string> $fields The list of fields to check uniqueness for
@param array<string, mixed> $options The options for unique checks. | __construct | php | cakephp/cakephp | src/ORM/Rule/IsUnique.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Rule/IsUnique.php | MIT |
public function __construct(array|string $fields, Table|Association|string $repository, array $options = [])
{
$options += ['allowNullableNulls' => false];
$this->_options = $options;
$this->_fields = (array)$fields;
$this->_repository = $repository;
} | Constructor.
Available option for $options is 'allowNullableNulls' flag.
Set to true to accept composite foreign keys where one or more nullable columns are null.
@param array<string>|string $fields The field or fields to check existence as primary key.
@param \Cake\ORM\Table|\Cake\ORM\Association|string $repository The repository where the
field will be looked for, or the association name for the repository.
@param array<string, mixed> $options The options that modify the rule's behavior.
Options 'allowNullableNulls' will make the rule pass if given foreign keys are set to `null`.
Notice: allowNullableNulls cannot pass by database columns set to `NOT NULL`. | __construct | php | cakephp/cakephp | src/ORM/Rule/ExistsIn.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Rule/ExistsIn.php | MIT |
public function allowFallbackClass(bool $allow)
{
$this->allowFallbackClass = $allow;
return $this;
} | Set if fallback class should be used.
Controls whether a fallback class should be used to create a table
instance if a concrete class for alias used in `get()` could not be found.
@param bool $allow Flag to enable or disable fallback
@return $this | allowFallbackClass | php | cakephp/cakephp | src/ORM/Locator/TableLocator.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Locator/TableLocator.php | MIT |
public function setFallbackClassName(string $className)
{
$this->fallbackClassName = $className;
return $this;
} | Set fallback class name.
The class that should be used to create a table instance if a concrete
class for alias used in `get()` could not be found. Defaults to
`Cake\ORM\Table`.
@param string $className Fallback class name
@return $this
@phpstan-param class-string<\Cake\ORM\Table> $className | setFallbackClassName | php | cakephp/cakephp | src/ORM/Locator/TableLocator.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Locator/TableLocator.php | MIT |
public function addLocation(string $location)
{
$location = str_replace('\\', '/', $location);
$this->locations[] = trim($location, '/');
return $this;
} | Adds a location where tables should be looked for.
@param string $location Location to add.
@return $this
@since 3.8.0 | addLocation | php | cakephp/cakephp | src/ORM/Locator/TableLocator.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Locator/TableLocator.php | MIT |
public function __construct(
EntityInterface $entity,
array|string $message,
?int $code = null,
?Throwable $previous = null,
) {
$this->_entity = $entity;
if (is_array($message)) {
$errors = [];
foreach (Hash::flatten($entity->getErrors()) as $field => $error) {
$errors[] = $field . ': "' . $error . '"';
}
if ($errors) {
$message[] = implode(', ', $errors);
$this->_messageTemplate = 'Entity %s failure. Found the following errors (%s).';
}
}
parent::__construct($message, $code, $previous);
} | Constructor.
@param \Cake\Datasource\EntityInterface $entity The entity on which the persistence operation failed
@param array<string>|string $message Either the string of the error message, or an array of attributes
that are made available in the view, and sprintf()'d into Exception::$_messageTemplate
@param int|null $code The code of the error, is also the HTTP status code for the error.
@param \Throwable|null $previous the previous exception. | __construct | php | cakephp/cakephp | src/ORM/Exception/PersistenceFailedException.php | https://github.com/cakephp/cakephp/blob/master/src/ORM/Exception/PersistenceFailedException.php | MIT |
public function setStopOnFailure(bool $stopOnFailure = true)
{
$this->_stopOnFailure = $stopOnFailure;
return $this;
} | Whether to stop validation rule evaluation on the first failed rule.
When enabled the first failing rule per field will cause validation to stop.
When disabled all rules will be run even if there are failures.
@param bool $stopOnFailure If to apply last flag.
@return $this | setStopOnFailure | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function setProvider(string $name, object|string $object)
{
$this->_providers[$name] = $object;
return $this;
} | Associates an object to a name so it can be used as a provider. Providers are
objects or class names that can contain methods used during validation of for
deciding whether a validation rule can be applied. All validation methods,
when called will receive the full list of providers stored in this validator.
@param string $name The name under which the provider should be set.
@param object|string $object Provider object or class name.
@phpstan-param object|class-string $object
@return $this | setProvider | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function remove(string $field, ?string $rule = null)
{
if ($rule === null) {
unset($this->_fields[$field]);
} else {
$this->field($field)->remove($rule);
}
return $this;
} | Removes a rule from the set by its name
### Example:
```
$validator
->remove('title', 'required')
->remove('user_id')
```
@param string $field The name of the field from which the rule will be removed
@param string|null $rule the name of the rule to be removed
@return $this | remove | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function allowEmptyString(string $field, ?string $message = null, Closure|string|bool $when = true)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING, $when, $message);
} | Allows a field to be an empty string.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING flag.
@param string $field The name of the field.
@param string|null $message The message to show if the field is not
@param \Closure|string|bool $when Indicates when the field is allowed to be empty
Valid values are true, false, 'create', 'update'. If a Closure is passed then
the field will allowed to be empty only when the callback returns true.
@return $this
@see \Cake\Validation\Validator::allowEmptyFor() For detail usage | allowEmptyString | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function notEmptyString(string $field, ?string $message = null, Closure|string|bool $when = false)
{
$when = $this->invertWhenClause($when);
return $this->allowEmptyFor($field, self::EMPTY_STRING, $when, $message);
} | Requires a field to not be an empty string.
Opposite to allowEmptyString()
@param string $field The name of the field.
@param string|null $message The message to show if the field is empty.
@param \Closure|string|bool $when Indicates when the field is not allowed
to be empty. Valid values are false (never), 'create', 'update'. If a
Closure is passed then the field will be required to be not empty when
the callback returns true.
@return $this
@see \Cake\Validation\Validator::allowEmptyString()
@since 3.8.0 | notEmptyString | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function allowEmptyArray(string $field, ?string $message = null, Closure|string|bool $when = true)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_ARRAY, $when, $message);
} | Allows a field to be an empty array.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING +
EMPTY_ARRAY flags.
@param string $field The name of the field.
@param string|null $message The message to show if the field is not
@param \Closure|string|bool $when Indicates when the field is allowed to be empty
Valid values are true, false, 'create', 'update'. If a Closure is passed then
the field will allowed to be empty only when the callback returns true.
@return $this
@since 3.7.0
@see \Cake\Validation\Validator::allowEmptyFor() for examples. | allowEmptyArray | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function notEmptyArray(string $field, ?string $message = null, Closure|string|bool $when = false)
{
$when = $this->invertWhenClause($when);
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_ARRAY, $when, $message);
} | Require a field to be a non-empty array
Opposite to allowEmptyArray()
@param string $field The name of the field.
@param string|null $message The message to show if the field is empty.
@param \Closure|string|bool $when Indicates when the field is not allowed
to be empty. Valid values are false (never), 'create', 'update'. If a
Closure is passed then the field will be required to be not empty when
the callback returns true.
@return $this
@see \Cake\Validation\Validator::allowEmptyArray() | notEmptyArray | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function allowEmptyFile(string $field, ?string $message = null, Closure|string|bool $when = true)
{
return $this->allowEmptyFor($field, self::EMPTY_FILE, $when, $message);
} | Allows a field to be an empty file.
This method is equivalent to calling allowEmptyFor() with EMPTY_FILE flag.
File fields will not accept `''`, or `[]` as empty values. Only `null` and a file
upload with `error` equal to `UPLOAD_ERR_NO_FILE` will be treated as empty.
@param string $field The name of the field.
@param string|null $message The message to show if the field is not
@param \Closure|string|bool $when Indicates when the field is allowed to be empty
Valid values are true, 'create', 'update'. If a Closure is passed then
the field will allowed to be empty only when the callback returns true.
@return $this
@since 3.7.0
@see \Cake\Validation\Validator::allowEmptyFor() For detail usage | allowEmptyFile | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function notEmptyFile(string $field, ?string $message = null, Closure|string|bool $when = false)
{
$when = $this->invertWhenClause($when);
return $this->allowEmptyFor($field, self::EMPTY_FILE, $when, $message);
} | Require a field to be a not-empty file.
Opposite to allowEmptyFile()
@param string $field The name of the field.
@param string|null $message The message to show if the field is empty.
@param \Closure|string|bool $when Indicates when the field is not allowed
to be empty. Valid values are false (never), 'create', 'update'. If a
Closure is passed then the field will be required to be not empty when
the callback returns true.
@return $this
@since 3.8.0
@see \Cake\Validation\Validator::allowEmptyFile() | notEmptyFile | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function allowEmptyDate(string $field, ?string $message = null, Closure|string|bool $when = true)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_DATE, $when, $message);
} | Allows a field to be an empty date.
Empty date values are `null`, `''`, `[]` and arrays where all values are `''`
and the `year` key is present.
@param string $field The name of the field.
@param string|null $message The message to show if the field is not
@param \Closure|string|bool $when Indicates when the field is allowed to be empty
Valid values are true, false, 'create', 'update'. If a Closure is passed then
the field will allowed to be empty only when the callback returns true.
@return $this
@see \Cake\Validation\Validator::allowEmptyFor() for examples | allowEmptyDate | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function notEmptyDate(string $field, ?string $message = null, Closure|string|bool $when = false)
{
$when = $this->invertWhenClause($when);
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_DATE, $when, $message);
} | Require a non-empty date value
@param string $field The name of the field.
@param string|null $message The message to show if the field is empty.
@param \Closure|string|bool $when Indicates when the field is not allowed
to be empty. Valid values are false (never), 'create', 'update'. If a
Closure is passed then the field will be required to be not empty when
the callback returns true.
@return $this
@see \Cake\Validation\Validator::allowEmptyDate() for examples | notEmptyDate | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function allowEmptyTime(string $field, ?string $message = null, Closure|string|bool $when = true)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_TIME, $when, $message);
} | Allows a field to be an empty time.
Empty date values are `null`, `''`, `[]` and arrays where all values are `''`
and the `hour` key is present.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING +
EMPTY_TIME flags.
@param string $field The name of the field.
@param string|null $message The message to show if the field is not
@param \Closure|string|bool $when Indicates when the field is allowed to be empty
Valid values are true, false, 'create', 'update'. If a Closure is passed then
the field will allowed to be empty only when the callback returns true.
@return $this
@since 3.7.0
@see \Cake\Validation\Validator::allowEmptyFor() for examples. | allowEmptyTime | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function notEmptyTime(string $field, ?string $message = null, Closure|string|bool $when = false)
{
$when = $this->invertWhenClause($when);
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_TIME, $when, $message);
} | Require a field to be a non-empty time.
Opposite to allowEmptyTime()
@param string $field The name of the field.
@param string|null $message The message to show if the field is empty.
@param \Closure|string|bool $when Indicates when the field is not allowed
to be empty. Valid values are false (never), 'create', 'update'. If a
Closure is passed then the field will be required to be not empty when
the callback returns true.
@return $this
@since 3.8.0
@see \Cake\Validation\Validator::allowEmptyTime() | notEmptyTime | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function allowEmptyDateTime(string $field, ?string $message = null, Closure|string|bool $when = true)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_DATE | self::EMPTY_TIME, $when, $message);
} | Allows a field to be an empty date/time.
Empty date values are `null`, `''`, `[]` and arrays where all values are `''`
and the `year` and `hour` keys are present.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING +
EMPTY_DATE + EMPTY_TIME flags.
@param string $field The name of the field.
@param string|null $message The message to show if the field is not
@param \Closure|string|bool $when Indicates when the field is allowed to be empty
Valid values are true, false, 'create', 'update'. If a Closure is passed then
the field will allowed to be empty only when the callback returns false.
@return $this
@since 3.7.0
@see \Cake\Validation\Validator::allowEmptyFor() for examples. | allowEmptyDateTime | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function notEmptyDateTime(string $field, ?string $message = null, Closure|string|bool $when = false)
{
$when = $this->invertWhenClause($when);
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_DATE | self::EMPTY_TIME, $when, $message);
} | Require a field to be a non empty date/time.
Opposite to allowEmptyDateTime
@param string $field The name of the field.
@param string|null $message The message to show if the field is empty.
@param \Closure|string|bool $when Indicates when the field is not allowed
to be empty. Valid values are false (never), 'create', 'update'. If a
Closure is passed then the field will be required to be not empty when
the callback returns true.
@return $this
@since 3.8.0
@see \Cake\Validation\Validator::allowEmptyDateTime() | notEmptyDateTime | php | cakephp/cakephp | src/Validation/Validator.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php | MIT |
public function requirePresence(callable|string|bool $validatePresent)
{
$this->_validatePresent = $validatePresent;
return $this;
} | Sets whether a field is required to be present in data array.
@param callable|string|bool $validatePresent Valid values are true, false, 'create', 'update' or a callable.
@return $this | requirePresence | php | cakephp/cakephp | src/Validation/ValidationSet.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/ValidationSet.php | MIT |
public function allowEmpty(callable|string|bool $allowEmpty)
{
$this->_allowEmpty = $allowEmpty;
return $this;
} | Sets whether a field value is allowed to be empty.
@param callable|string|bool $allowEmpty Valid values are true, false,
'create', 'update' or a callable.
@return $this | allowEmpty | php | cakephp/cakephp | src/Validation/ValidationSet.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/ValidationSet.php | MIT |
public function add(string $name, ValidationRule|array $rule)
{
if (!($rule instanceof ValidationRule)) {
$rule = new ValidationRule($rule);
}
if (array_key_exists($name, $this->_rules)) {
throw new CakeException("A validation rule with the name `{$name}` already exists");
}
$this->_rules[$name] = $rule;
return $this;
} | Sets a ValidationRule $rule with a $name
### Example:
```
$set
->add('notBlank', ['rule' => 'notBlank'])
->add('inRange', ['rule' => ['between', 4, 10])
```
@param string $name The name under which the rule should be set
@param \Cake\Validation\ValidationRule|array $rule The validation rule to be set
@return $this
@throws \Cake\Core\Exception\CakeException If a rule with the same name already exists | add | php | cakephp/cakephp | src/Validation/ValidationSet.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/ValidationSet.php | MIT |
public function remove(string $name)
{
unset($this->_rules[$name]);
return $this;
} | Removes a validation rule from the set
### Example:
```
$set
->remove('notBlank')
->remove('inRange')
```
@param string $name The name under which the rule should be unset
@return $this | remove | php | cakephp/cakephp | src/Validation/ValidationSet.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/ValidationSet.php | MIT |
public function __construct(object|string $class = Validation::class)
{
deprecationWarning(
'5.2.0',
sprintf(
'The class Cake\Validation\RulesProvider is deprecated. '
. 'Directly set %s as a validation provider.',
(is_string($class) ? $class : get_class($class)),
),
);
$this->_class = $class;
$this->_reflection = new ReflectionClass($class);
} | Constructor, sets the default class to use for calling methods
@param object|string $class the default class to proxy
@throws \ReflectionException
@phpstan-param object|class-string $class | __construct | php | cakephp/cakephp | src/Validation/RulesProvider.php | https://github.com/cakephp/cakephp/blob/master/src/Validation/RulesProvider.php | MIT |
public function reset()
{
$this->_viewBuilder = null;
$this->viewBuilder()
->setClassName(View::class)
->setLayout('default')
->setHelpers(['Html']);
return $this;
} | Reset view builder to defaults.
@return $this | reset | php | cakephp/cakephp | src/Mailer/Renderer.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Renderer.php | MIT |
public function __clone()
{
if ($this->_viewBuilder !== null) {
$this->_viewBuilder = clone $this->_viewBuilder;
}
} | Clone ViewBuilder instance when renderer is cloned.
@return void | __clone | php | cakephp/cakephp | src/Mailer/Renderer.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Renderer.php | MIT |
public function setFrom(array|string $email, ?string $name = null)
{
return $this->setEmailSingle('from', $email, $name, 'From requires only 1 email address.');
} | Sets "from" address.
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this
@throws \InvalidArgumentException | setFrom | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function setSender(array|string $email, ?string $name = null)
{
return $this->setEmailSingle('sender', $email, $name, 'Sender requires only 1 email address.');
} | Sets the "sender" address. See RFC link below for full explanation.
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this
@throws \InvalidArgumentException
@link https://tools.ietf.org/html/rfc2822.html#section-3.6.2 | setSender | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function setReplyTo(array|string $email, ?string $name = null)
{
return $this->setEmail('replyTo', $email, $name);
} | Sets "Reply-To" address.
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this
@throws \InvalidArgumentException | setReplyTo | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function addReplyTo(array|string $email, ?string $name = null)
{
return $this->addEmail('replyTo', $email, $name);
} | Add "Reply-To" address.
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this | addReplyTo | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function setReadReceipt(array|string $email, ?string $name = null)
{
return $this->setEmailSingle(
'readReceipt',
$email,
$name,
'Disposition-Notification-To requires only 1 email address.',
);
} | Sets Read Receipt (Disposition-Notification-To header).
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this
@throws \InvalidArgumentException | setReadReceipt | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function setReturnPath(array|string $email, ?string $name = null)
{
return $this->setEmailSingle('returnPath', $email, $name, 'Return-Path requires only 1 email address.');
} | Sets return path.
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this
@throws \InvalidArgumentException | setReturnPath | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function setTo(array|string $email, ?string $name = null)
{
return $this->setEmail('to', $email, $name);
} | Sets "to" address.
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this | setTo | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function addTo(array|string $email, ?string $name = null)
{
return $this->addEmail('to', $email, $name);
} | Add "To" address.
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this | addTo | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function setCc(array|string $email, ?string $name = null)
{
return $this->setEmail('cc', $email, $name);
} | Sets "cc" address.
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this | setCc | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function addCc(array|string $email, ?string $name = null)
{
return $this->addEmail('cc', $email, $name);
} | Add "cc" address.
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this | addCc | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function setBcc(array|string $email, ?string $name = null)
{
return $this->setEmail('bcc', $email, $name);
} | Sets "bcc" address.
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this | setBcc | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function addBcc(array|string $email, ?string $name = null)
{
return $this->addEmail('bcc', $email, $name);
} | Add "bcc" address.
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@return $this | addBcc | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function setEmailPattern(?string $regex)
{
$this->emailPattern = $regex;
return $this;
} | EmailPattern setter/getter
@param string|null $regex The pattern to use for email address validation,
null to unset the pattern and make use of filter_var() instead.
@return $this | setEmailPattern | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
protected function setEmailSingle(string $varName, array|string $email, ?string $name, string $throwMessage)
{
if ($email === []) {
$this->{$varName} = $email;
return $this;
}
$current = $this->{$varName};
$this->setEmail($varName, $email, $name);
if (count($this->{$varName}) !== 1) {
$this->{$varName} = $current;
throw new InvalidArgumentException($throwMessage);
}
return $this;
} | Set only 1 email
@param string $varName Property name
@param array|string $email String with email,
Array with email as key, name as value or email as value (without name)
@param string|null $name Name
@param string $throwMessage Exception message
@return $this
@throws \InvalidArgumentException | setEmailSingle | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function setMessageId(string|bool $message)
{
if (is_bool($message)) {
$this->messageId = $message;
} else {
if (!preg_match('/^\<.+@.+\>$/', $message)) {
throw new InvalidArgumentException(
'Invalid format to Message-ID. The text should be something like "<[email protected]>"',
);
}
$this->messageId = $message;
}
return $this;
} | Sets message ID.
@param string|bool $message True to generate a new Message-ID, False to ignore (not send in email),
String to set as Message-ID.
@return $this
@throws \InvalidArgumentException | setMessageId | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function setDomain(string $domain)
{
$this->domain = $domain;
return $this;
} | Sets domain.
Domain as top level (the part after @).
@param string $domain Manually set the domain for CLI mailing.
@return $this | setDomain | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function reset()
{
$this->to = [];
$this->from = [];
$this->sender = [];
$this->replyTo = [];
$this->readReceipt = [];
$this->returnPath = [];
$this->cc = [];
$this->bcc = [];
$this->messageId = true;
$this->subject = '';
$this->headers = [];
$this->textMessage = '';
$this->htmlMessage = '';
$this->message = [];
$this->emailFormat = static::MESSAGE_TEXT;
$this->priority = null;
$this->charset = 'utf-8';
$this->headerCharset = null;
$this->transferEncoding = null;
$this->attachments = [];
$this->emailPattern = static::EMAIL_PATTERN;
return $this;
} | Reset all the internal variables to be able to send out a new email.
@return $this | reset | php | cakephp/cakephp | src/Mailer/Message.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Message.php | MIT |
public function __call(string $method, array $args)
{
$result = $this->message->$method(...$args);
if (str_starts_with($method, 'get')) {
return $result;
}
return $this;
} | Magic method to forward method class to Message instance.
@param string $method Method name.
@param array $args Method arguments
@return $this|mixed | __call | php | cakephp/cakephp | src/Mailer/Mailer.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Mailer.php | MIT |
public function render(string $content = '')
{
$content = $this->getRenderer()->render(
$content,
$this->message->getBodyTypes(),
);
$this->message->setBody($content);
return $this;
} | Render content and set message body.
@param string $content Content.
@return $this | render | php | cakephp/cakephp | src/Mailer/Mailer.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Mailer.php | MIT |
public function setTransport(AbstractTransport|string $name)
{
if (is_string($name)) {
$this->transport = TransportFactory::get($name);
} else {
$this->transport = $name;
}
return $this;
} | Sets the transport.
When setting the transport you can either use the name
of a configured transport or supply a constructed transport.
@param \Cake\Mailer\AbstractTransport|string $name Either the name of a configured
transport, or a transport instance.
@return $this
@throws \LogicException When the chosen transport lacks a send method. | setTransport | php | cakephp/cakephp | src/Mailer/Mailer.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Mailer.php | MIT |
protected function restore()
{
foreach (array_keys($this->clonedInstances) as $key) {
if ($this->clonedInstances[$key] === null) {
if ($key === 'message') {
$this->message->reset();
} else {
$this->{$key} = null;
}
} else {
$this->{$key} = clone $this->clonedInstances[$key];
$this->clonedInstances[$key] = null;
}
}
return $this;
} | Restore message, renderer, transport instances to state before an action was run.
@return $this | restore | php | cakephp/cakephp | src/Mailer/Mailer.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Mailer.php | MIT |
public function __destruct()
{
try {
$this->disconnect();
} catch (Exception) {
// avoid fatal error on script termination
}
} | Destructor
Tries to disconnect to ensure that the connection is being
terminated properly before the socket gets closed. | __destruct | php | cakephp/cakephp | src/Mailer/Transport/SmtpTransport.php | https://github.com/cakephp/cakephp/blob/master/src/Mailer/Transport/SmtpTransport.php | MIT |
public function execute(Arguments $args, ConsoleIo $io)
{
} | Implement this method with your command's logic.
@param \Cake\Console\Arguments $args The command arguments.
@param \Cake\Console\ConsoleIo $io The console io
@return int|null|void The exit code or null for success
@phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint | execute | php | cakephp/cakephp | src/Command/Command.php | https://github.com/cakephp/cakephp/blob/master/src/Command/Command.php | MIT |
public function withPadding(int $padding)
{
if ($padding < 0) {
throw new InvalidArgumentException('padding must be greater than 0');
}
$this->padding = $padding;
return $this;
} | Modify the padding of the helper
@param int $padding The padding value to use.
@return $this | withPadding | php | cakephp/cakephp | src/Command/Helper/BannerHelper.php | https://github.com/cakephp/cakephp/blob/master/src/Command/Helper/BannerHelper.php | MIT |
public function withStyle(string $style)
{
$this->style = $style;
return $this;
} | Modify the padding of the helper
@param string $style The style value to use.
@return $this | withStyle | php | cakephp/cakephp | src/Command/Helper/BannerHelper.php | https://github.com/cakephp/cakephp/blob/master/src/Command/Helper/BannerHelper.php | MIT |
public function draw()
{
$numberLen = strlen(' 100%');
$complete = round($this->_progress / $this->_total, 2);
$barLen = ($this->_width - $numberLen) * $this->_progress / $this->_total;
$bar = '';
if ($barLen > 1) {
$bar = str_repeat('=', (int)$barLen - 1) . '>';
}
$pad = ceil($this->_width - $numberLen - $barLen);
if ($pad > 0) {
$bar .= str_repeat(' ', (int)$pad);
}
$percent = ($complete * 100) . '%';
$bar .= str_pad($percent, $numberLen, ' ', STR_PAD_LEFT);
$this->_io->overwrite($bar, 0);
return $this;
} | Render the progress bar based on the current state.
@return $this | draw | php | cakephp/cakephp | src/Command/Helper/ProgressHelper.php | https://github.com/cakephp/cakephp/blob/master/src/Command/Helper/ProgressHelper.php | MIT |
protected function _getMockFindQuery($table = null)
{
/** @var \Cake\ORM\Query\SelectQuery|\PHPUnit\Framework\MockObject\MockObject $query */
$query = $this->getMockBuilder(SelectQuery::class)
->onlyMethods(['all', 'count', 'applyOptions'])
->disableOriginalConstructor()
->getMock();
$results = $this->getMockBuilder(ResultSet::class)
->disableOriginalConstructor()
->getMock();
$query->expects($this->any())
->method('count')
->willReturn(2);
$query->expects($this->any())
->method('all')
->willReturn($results);
if ($table) {
$query->setRepository($table);
}
return $query;
} | Helper method for mocking queries.
@param string|null $table
@return \Cake\ORM\Query\SelectQuery|\PHPUnit\Framework\MockObject\MockObject | _getMockFindQuery | php | cakephp/cakephp | tests/TestCase/Datasource/Paging/PaginatorTestTrait.php | https://github.com/cakephp/cakephp/blob/master/tests/TestCase/Datasource/Paging/PaginatorTestTrait.php | MIT |
public function mapCallback($value)
{
return $value * 2;
} | testing method for map callbacks.
@param mixed $value Value
@return mixed | mapCallback | php | cakephp/cakephp | tests/TestCase/Utility/HashTest.php | https://github.com/cakephp/cakephp/blob/master/tests/TestCase/Utility/HashTest.php | MIT |
public function reduceCallback($one, $two)
{
return $one + $two;
} | testing method for reduce callbacks.
@param mixed $one First param
@param mixed $two Second param
@return mixed | reduceCallback | php | cakephp/cakephp | tests/TestCase/Utility/HashTest.php | https://github.com/cakephp/cakephp/blob/master/tests/TestCase/Utility/HashTest.php | MIT |
protected function _setMockLocator()
{
$locator = $this->getMockBuilder(LocatorInterface::class)->getMock();
TableRegistry::setTableLocator($locator);
return $locator;
} | Sets and returns mock LocatorInterface instance.
@return \Cake\ORM\Locator\LocatorInterface|\PHPUnit\Framework\MockObject\MockObject | _setMockLocator | php | cakephp/cakephp | tests/TestCase/ORM/TableRegistryTest.php | https://github.com/cakephp/cakephp/blob/master/tests/TestCase/ORM/TableRegistryTest.php | MIT |
public static function setStrategies(array $strategies)
{
self::$strategies = $strategies;
self::clearCache();
} | Set new strategies and clear the cache.
@param string[] $strategies list of fully qualified class names that implement DiscoveryStrategy | setStrategies | php | php-http/discovery | src/ClassDiscovery.php | https://github.com/php-http/discovery/blob/master/src/ClassDiscovery.php | MIT |
public static function appendStrategy($strategy)
{
self::$strategies[] = $strategy;
self::clearCache();
} | Append a strategy at the end of the strategy queue.
@param string $strategy Fully qualified class name of a DiscoveryStrategy | appendStrategy | php | php-http/discovery | src/ClassDiscovery.php | https://github.com/php-http/discovery/blob/master/src/ClassDiscovery.php | MIT |
public static function prependStrategy($strategy)
{
array_unshift(self::$strategies, $strategy);
self::clearCache();
} | Prepend a strategy at the beginning of the strategy queue.
@param string $strategy Fully qualified class name to a DiscoveryStrategy | prependStrategy | php | php-http/discovery | src/ClassDiscovery.php | https://github.com/php-http/discovery/blob/master/src/ClassDiscovery.php | MIT |
protected static function evaluateCondition($condition)
{
if (is_string($condition)) {
// Should be extended for functions, extensions???
return self::safeClassExists($condition);
}
if (is_callable($condition)) {
return (bool) $condition();
}
if (is_bool($condition)) {
return $condition;
}
if (is_array($condition)) {
foreach ($condition as $c) {
if (false === static::evaluateCondition($c)) {
// Immediately stop execution if the condition is false
return false;
}
}
return true;
}
return false;
} | Evaluates conditions to boolean.
@return bool | evaluateCondition | php | php-http/discovery | src/ClassDiscovery.php | https://github.com/php-http/discovery/blob/master/src/ClassDiscovery.php | MIT |
protected static function instantiateClass($class)
{
try {
if (is_string($class)) {
return new $class();
}
if (is_callable($class)) {
return $class();
}
} catch (\Exception $e) {
throw new ClassInstantiationFailedException('Unexpected exception when instantiating class.', 0, $e);
}
throw new ClassInstantiationFailedException('Could not instantiate class because parameter is neither a callable nor a string');
} | Get an instance of the $class.
@param string|\Closure $class a FQCN of a class or a closure that instantiate the class
@return object
@throws ClassInstantiationFailedException | instantiateClass | php | php-http/discovery | src/ClassDiscovery.php | https://github.com/php-http/discovery/blob/master/src/ClassDiscovery.php | MIT |
public static function safeClassExists($class)
{
try {
return class_exists($class) || interface_exists($class);
} catch (\Exception $e) {
return false;
}
} | We need a "safe" version of PHP's "class_exists" because Magento has a bug
(or they call it a "feature"). Magento is throwing an exception if you do class_exists()
on a class that ends with "Factory" and if that file does not exits.
This function catches all potential exceptions and makes sure to always return a boolean.
@param string $class
@return bool | safeClassExists | php | php-http/discovery | src/ClassDiscovery.php | https://github.com/php-http/discovery/blob/master/src/ClassDiscovery.php | MIT |
private static function getPuliDiscovery()
{
if (!isset(self::$puliDiscovery)) {
$factory = self::getPuliFactory();
$repository = $factory->createRepository();
self::$puliDiscovery = $factory->createDiscovery($repository);
}
return self::$puliDiscovery;
} | Returns the Puli discovery layer.
@return Discovery
@throws PuliUnavailableException | getPuliDiscovery | php | php-http/discovery | src/Strategy/PuliBetaStrategy.php | https://github.com/php-http/discovery/blob/master/src/Strategy/PuliBetaStrategy.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.