code
stringlengths 15
9.96M
| docstring
stringlengths 1
10.1k
| func_name
stringlengths 1
124
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 6
186
| url
stringlengths 50
236
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function __construct(View $View, array $config = []) {
$this->_defaultConfig += $this->_defaultConfigExt;
$defaultConfig = (array)Configure::read('FormConfig');
if ($defaultConfig) {
$this->_defaultConfig = Hash::merge($this->_defaultConfig, $defaultConfig);
}
parent::__construct($View, $config);
} | Construct the widgets and binds the default context providers
@param \Cake\View\View $View The View this helper is being attached to.
@param array<string, mixed> $config Configuration settings for the helper. | __construct | php | dereuromark/cakephp-tools | src/View/Helper/FormHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/FormHelper.php | MIT |
public function __construct(View $View, array $config = []) {
$defaults = (array)Configure::read('Icon') + $this->_defaults;
$config += $defaults;
$this->collection = new IconCollection($config);
parent::__construct($View, $config);
} | @param \Cake\View\View $View
@param array<string, mixed> $config | __construct | php | dereuromark/cakephp-tools | src/View/Helper/IconHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/IconHelper.php | MIT |
public function __construct(View $view, array $config = []) {
$config += ['engine' => 'Tools.Number'];
parent::__construct($view, $config);
/** @psalm-var class-string<\Cake\I18n\Number>|null $engineClass */
$engineClass = App::className($config['engine'], 'I18n');
if ($engineClass === null) {
throw new CakeException(sprintf('Class for `%s` could not be found', $config['engine']));
}
/** @phpstan-ignore-next-line */
$this->_engine = new $engineClass($config);
} | ### Settings:
- `engine` Class name to use to replace Number functionality.
The class needs to be placed in the `Utility` directory.
@param \Cake\View\View $view The View this helper is being attached to.
@param array<string, mixed> $config Configuration settings for the helper | __construct | php | dereuromark/cakephp-tools | src/View/Helper/NumberHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/NumberHelper.php | MIT |
public function __construct(View $View, array $config = []) {
$defaults = (array)Configure::read('Progress') + $this->_defaults;
$config += $defaults;
parent::__construct($View, $config);
} | @param \Cake\View\View $View
@param array<string, mixed> $config | __construct | php | dereuromark/cakephp-tools | src/View/Helper/ProgressHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/ProgressHelper.php | MIT |
public function calculatePercentage($total, $is) {
$percentage = $total ? $is / $total : 0.0;
return $this->roundPercentage($percentage);
} | @param float|int $total
@param float|int $is
@return float | calculatePercentage | php | dereuromark/cakephp-tools | src/View/Helper/ProgressHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/ProgressHelper.php | MIT |
public function roundPercentage($percentage) {
$percentageRounded = round($percentage, 2);
if ($percentageRounded === 0.00 && $percentage > 0.0) {
$percentage = 0.01;
}
if ($percentageRounded === 1.00 && $percentage < 1.0) {
$percentage = 0.99;
}
return (float)$percentage;
} | @param float $percentage
@return float | roundPercentage | php | dereuromark/cakephp-tools | src/View/Helper/ProgressHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/ProgressHelper.php | MIT |
public function __construct(View $View, array $config = []) {
$defaults = [
'outputTimezone' => Configure::read('App.defaultOutputTimezone'),
];
$config += $defaults;
parent::__construct($View, $config);
$config = $this->_config + $defaults;
/** @var class-string<\Tools\I18n\DateTime>|null $engineClass */
$engineClass = App::className($config['engine'], 'I18n');
if (!$engineClass) {
throw new CakeException(sprintf('Class for %s could not be found', $config['engine']));
}
$this->_engine = new $engineClass($config);
} | ### Settings:
- `engine` Class name to use to replace Cake\I18n\Time functionality
The class needs to be placed in the `Utility` directory.
@param \Cake\View\View $View The View this helper is being attached to.
@param array<string, mixed> $config Configuration settings for the helper
@throws \Cake\Core\Exception\CakeException When the engine class could not be found. | __construct | php | dereuromark/cakephp-tools | src/View/Helper/TimeHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/TimeHelper.php | MIT |
public function __call($method, $params) {
/** @var callable $callable */
$callable = [$this->_engine, $method];
return call_user_func_array($callable, $params);
} | Call methods from Cake\I18n\Number utility class
@param string $method Method to invoke
@param array $params Array of params for the method.
@return mixed Whatever is returned by called method, or false on failure | __call | php | dereuromark/cakephp-tools | src/View/Helper/TimeHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/TimeHelper.php | MIT |
public function userAge($date = null, $default = '') {
if ($date === null) {
return $default;
}
if ($date instanceof Date) {
$date = $date->toNative();
}
$age = $this->age($date);
if ($age >= 1 && $age <= 99) {
return (string)$age;
}
return $default;
} | Output the age of a person within a sane range.
Defaults to the $default string if outside of that range.
@param \Cake\I18n\Date|string|int|null $date
@param string $default
@return string Age on success, $default otherwise | userAge | php | dereuromark/cakephp-tools | src/View/Helper/TimeHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/TimeHelper.php | MIT |
public function timezones() {
$timezones = [
'America/Adak' => '(GMT-10:00) America/Adak (Hawaii-Aleutian Standard Time)',
'America/Atka' => '(GMT-10:00) America/Atka (Hawaii-Aleutian Standard Time)',
'America/Anchorage' => '(GMT-9:00) America/Anchorage (Alaska Standard Time)',
'America/Juneau' => '(GMT-9:00) America/Juneau (Alaska Standard Time)',
'America/Nome' => '(GMT-9:00) America/Nome (Alaska Standard Time)',
'America/Yakutat' => '(GMT-9:00) America/Yakutat (Alaska Standard Time)',
'America/Dawson' => '(GMT-8:00) America/Dawson (Pacific Standard Time)',
'America/Ensenada' => '(GMT-8:00) America/Ensenada (Pacific Standard Time)',
'America/Los_Angeles' => '(GMT-8:00) America/Los_Angeles (Pacific Standard Time)',
'America/Tijuana' => '(GMT-8:00) America/Tijuana (Pacific Standard Time)',
'America/Vancouver' => '(GMT-8:00) America/Vancouver (Pacific Standard Time)',
'America/Whitehorse' => '(GMT-8:00) America/Whitehorse (Pacific Standard Time)',
'Canada/Pacific' => '(GMT-8:00) Canada/Pacific (Pacific Standard Time)',
'Canada/Yukon' => '(GMT-8:00) Canada/Yukon (Pacific Standard Time)',
'Mexico/BajaNorte' => '(GMT-8:00) Mexico/BajaNorte (Pacific Standard Time)',
'America/Boise' => '(GMT-7:00) America/Boise (Mountain Standard Time)',
'America/Cambridge_Bay' => '(GMT-7:00) America/Cambridge_Bay (Mountain Standard Time)',
'America/Chihuahua' => '(GMT-7:00) America/Chihuahua (Mountain Standard Time)',
'America/Dawson_Creek' => '(GMT-7:00) America/Dawson_Creek (Mountain Standard Time)',
'America/Denver' => '(GMT-7:00) America/Denver (Mountain Standard Time)',
'America/Edmonton' => '(GMT-7:00) America/Edmonton (Mountain Standard Time)',
'America/Hermosillo' => '(GMT-7:00) America/Hermosillo (Mountain Standard Time)',
'America/Inuvik' => '(GMT-7:00) America/Inuvik (Mountain Standard Time)',
'America/Mazatlan' => '(GMT-7:00) America/Mazatlan (Mountain Standard Time)',
'America/Phoenix' => '(GMT-7:00) America/Phoenix (Mountain Standard Time)',
'America/Shiprock' => '(GMT-7:00) America/Shiprock (Mountain Standard Time)',
'America/Yellowknife' => '(GMT-7:00) America/Yellowknife (Mountain Standard Time)',
'Canada/Mountain' => '(GMT-7:00) Canada/Mountain (Mountain Standard Time)',
'Mexico/BajaSur' => '(GMT-7:00) Mexico/BajaSur (Mountain Standard Time)',
'America/Belize' => '(GMT-6:00) America/Belize (Central Standard Time)',
'America/Cancun' => '(GMT-6:00) America/Cancun (Central Standard Time)',
'America/Chicago' => '(GMT-6:00) America/Chicago (Central Standard Time)',
'America/Costa_Rica' => '(GMT-6:00) America/Costa_Rica (Central Standard Time)',
'America/El_Salvador' => '(GMT-6:00) America/El_Salvador (Central Standard Time)',
'America/Guatemala' => '(GMT-6:00) America/Guatemala (Central Standard Time)',
'America/Knox_IN' => '(GMT-6:00) America/Knox_IN (Central Standard Time)',
'America/Managua' => '(GMT-6:00) America/Managua (Central Standard Time)',
'America/Menominee' => '(GMT-6:00) America/Menominee (Central Standard Time)',
'America/Merida' => '(GMT-6:00) America/Merida (Central Standard Time)',
'America/Mexico_City' => '(GMT-6:00) America/Mexico_City (Central Standard Time)',
'America/Monterrey' => '(GMT-6:00) America/Monterrey (Central Standard Time)',
'America/Rainy_River' => '(GMT-6:00) America/Rainy_River (Central Standard Time)',
'America/Rankin_Inlet' => '(GMT-6:00) America/Rankin_Inlet (Central Standard Time)',
'America/Regina' => '(GMT-6:00) America/Regina (Central Standard Time)',
'America/Swift_Current' => '(GMT-6:00) America/Swift_Current (Central Standard Time)',
'America/Tegucigalpa' => '(GMT-6:00) America/Tegucigalpa (Central Standard Time)',
'America/Winnipeg' => '(GMT-6:00) America/Winnipeg (Central Standard Time)',
'Canada/Central' => '(GMT-6:00) Canada/Central (Central Standard Time)',
'Canada/East-Saskatchewan' => '(GMT-6:00) Canada/East-Saskatchewan (Central Standard Time)',
'Canada/Saskatchewan' => '(GMT-6:00) Canada/Saskatchewan (Central Standard Time)',
'Chile/EasterIsland' => '(GMT-6:00) Chile/EasterIsland (Easter Is. Time)',
'Mexico/General' => '(GMT-6:00) Mexico/General (Central Standard Time)',
'America/Atikokan' => '(GMT-5:00) America/Atikokan (Eastern Standard Time)',
'America/Bogota' => '(GMT-5:00) America/Bogota (Colombia Time)',
'America/Cayman' => '(GMT-5:00) America/Cayman (Eastern Standard Time)',
'America/Coral_Harbour' => '(GMT-5:00) America/Coral_Harbour (Eastern Standard Time)',
'America/Detroit' => '(GMT-5:00) America/Detroit (Eastern Standard Time)',
'America/Fort_Wayne' => '(GMT-5:00) America/Fort_Wayne (Eastern Standard Time)',
'America/Grand_Turk' => '(GMT-5:00) America/Grand_Turk (Eastern Standard Time)',
'America/Guayaquil' => '(GMT-5:00) America/Guayaquil (Ecuador Time)',
'America/Havana' => '(GMT-5:00) America/Havana (Cuba Standard Time)',
'America/Indianapolis' => '(GMT-5:00) America/Indianapolis (Eastern Standard Time)',
'America/Iqaluit' => '(GMT-5:00) America/Iqaluit (Eastern Standard Time)',
'America/Jamaica' => '(GMT-5:00) America/Jamaica (Eastern Standard Time)',
'America/Lima' => '(GMT-5:00) America/Lima (Peru Time)',
'America/Louisville' => '(GMT-5:00) America/Louisville (Eastern Standard Time)',
'America/Montreal' => '(GMT-5:00) America/Montreal (Eastern Standard Time)',
'America/Nassau' => '(GMT-5:00) America/Nassau (Eastern Standard Time)',
'America/New_York' => '(GMT-5:00) America/New_York (Eastern Standard Time)',
'America/Nipigon' => '(GMT-5:00) America/Nipigon (Eastern Standard Time)',
'America/Panama' => '(GMT-5:00) America/Panama (Eastern Standard Time)',
'America/Pangnirtung' => '(GMT-5:00) America/Pangnirtung (Eastern Standard Time)',
'America/Port-au-Prince' => '(GMT-5:00) America/Port-au-Prince (Eastern Standard Time)',
'America/Resolute' => '(GMT-5:00) America/Resolute (Eastern Standard Time)',
'America/Thunder_Bay' => '(GMT-5:00) America/Thunder_Bay (Eastern Standard Time)',
'America/Toronto' => '(GMT-5:00) America/Toronto (Eastern Standard Time)',
'Canada/Eastern' => '(GMT-5:00) Canada/Eastern (Eastern Standard Time)',
'America/Caracas' => '(GMT-4:-30) America/Caracas (Venezuela Time)',
'America/Anguilla' => '(GMT-4:00) America/Anguilla (Atlantic Standard Time)',
'America/Antigua' => '(GMT-4:00) America/Antigua (Atlantic Standard Time)',
'America/Aruba' => '(GMT-4:00) America/Aruba (Atlantic Standard Time)',
'America/Asuncion' => '(GMT-4:00) America/Asuncion (Paraguay Time)',
'America/Barbados' => '(GMT-4:00) America/Barbados (Atlantic Standard Time)',
'America/Blanc-Sablon' => '(GMT-4:00) America/Blanc-Sablon (Atlantic Standard Time)',
'America/Boa_Vista' => '(GMT-4:00) America/Boa_Vista (Amazon Time)',
'America/Campo_Grande' => '(GMT-4:00) America/Campo_Grande (Amazon Time)',
'America/Cuiaba' => '(GMT-4:00) America/Cuiaba (Amazon Time)',
'America/Curacao' => '(GMT-4:00) America/Curacao (Atlantic Standard Time)',
'America/Dominica' => '(GMT-4:00) America/Dominica (Atlantic Standard Time)',
'America/Eirunepe' => '(GMT-4:00) America/Eirunepe (Amazon Time)',
'America/Glace_Bay' => '(GMT-4:00) America/Glace_Bay (Atlantic Standard Time)',
'America/Goose_Bay' => '(GMT-4:00) America/Goose_Bay (Atlantic Standard Time)',
'America/Grenada' => '(GMT-4:00) America/Grenada (Atlantic Standard Time)',
'America/Guadeloupe' => '(GMT-4:00) America/Guadeloupe (Atlantic Standard Time)',
'America/Guyana' => '(GMT-4:00) America/Guyana (Guyana Time)',
'America/Halifax' => '(GMT-4:00) America/Halifax (Atlantic Standard Time)',
'America/La_Paz' => '(GMT-4:00) America/La_Paz (Bolivia Time)',
'America/Manaus' => '(GMT-4:00) America/Manaus (Amazon Time)',
'America/Marigot' => '(GMT-4:00) America/Marigot (Atlantic Standard Time)',
'America/Martinique' => '(GMT-4:00) America/Martinique (Atlantic Standard Time)',
'America/Moncton' => '(GMT-4:00) America/Moncton (Atlantic Standard Time)',
'America/Montserrat' => '(GMT-4:00) America/Montserrat (Atlantic Standard Time)',
'America/Port_of_Spain' => '(GMT-4:00) America/Port_of_Spain (Atlantic Standard Time)',
'America/Porto_Acre' => '(GMT-4:00) America/Porto_Acre (Amazon Time)',
'America/Porto_Velho' => '(GMT-4:00) America/Porto_Velho (Amazon Time)',
'America/Puerto_Rico' => '(GMT-4:00) America/Puerto_Rico (Atlantic Standard Time)',
'America/Rio_Branco' => '(GMT-4:00) America/Rio_Branco (Amazon Time)',
'America/Santiago' => '(GMT-4:00) America/Santiago (Chile Time)',
'America/Santo_Domingo' => '(GMT-4:00) America/Santo_Domingo (Atlantic Standard Time)',
'America/St_Barthelemy' => '(GMT-4:00) America/St_Barthelemy (Atlantic Standard Time)',
'America/St_Kitts' => '(GMT-4:00) America/St_Kitts (Atlantic Standard Time)',
'America/St_Lucia' => '(GMT-4:00) America/St_Lucia (Atlantic Standard Time)',
'America/St_Thomas' => '(GMT-4:00) America/St_Thomas (Atlantic Standard Time)',
'America/St_Vincent' => '(GMT-4:00) America/St_Vincent (Atlantic Standard Time)',
'America/Thule' => '(GMT-4:00) America/Thule (Atlantic Standard Time)',
'America/Tortola' => '(GMT-4:00) America/Tortola (Atlantic Standard Time)',
'America/Virgin' => '(GMT-4:00) America/Virgin (Atlantic Standard Time)',
'Antarctica/Palmer' => '(GMT-4:00) Antarctica/Palmer (Chile Time)',
'Atlantic/Bermuda' => '(GMT-4:00) Atlantic/Bermuda (Atlantic Standard Time)',
'Atlantic/Stanley' => '(GMT-4:00) Atlantic/Stanley (Falkland Is. Time)',
'Brazil/Acre' => '(GMT-4:00) Brazil/Acre (Amazon Time)',
'Brazil/West' => '(GMT-4:00) Brazil/West (Amazon Time)',
'Canada/Atlantic' => '(GMT-4:00) Canada/Atlantic (Atlantic Standard Time)',
'Chile/Continental' => '(GMT-4:00) Chile/Continental (Chile Time)',
'America/St_Johns' => '(GMT-3:-30) America/St_Johns (Newfoundland Standard Time)',
'Canada/Newfoundland' => '(GMT-3:-30) Canada/Newfoundland (Newfoundland Standard Time)',
'America/Araguaina' => '(GMT-3:00) America/Araguaina (Brasilia Time)',
'America/Bahia' => '(GMT-3:00) America/Bahia (Brasilia Time)',
'America/Belem' => '(GMT-3:00) America/Belem (Brasilia Time)',
'America/Buenos_Aires' => '(GMT-3:00) America/Buenos_Aires (Argentine Time)',
'America/Catamarca' => '(GMT-3:00) America/Catamarca (Argentine Time)',
'America/Cayenne' => '(GMT-3:00) America/Cayenne (French Guiana Time)',
'America/Cordoba' => '(GMT-3:00) America/Cordoba (Argentine Time)',
'America/Fortaleza' => '(GMT-3:00) America/Fortaleza (Brasilia Time)',
'America/Godthab' => '(GMT-3:00) America/Godthab (Western Greenland Time)',
'America/Jujuy' => '(GMT-3:00) America/Jujuy (Argentine Time)',
'America/Maceio' => '(GMT-3:00) America/Maceio (Brasilia Time)',
'America/Mendoza' => '(GMT-3:00) America/Mendoza (Argentine Time)',
'America/Miquelon' => '(GMT-3:00) America/Miquelon (Pierre & Miquelon Standard Time)',
'America/Montevideo' => '(GMT-3:00) America/Montevideo (Uruguay Time)',
'America/Paramaribo' => '(GMT-3:00) America/Paramaribo (Suriname Time)',
'America/Recife' => '(GMT-3:00) America/Recife (Brasilia Time)',
'America/Rosario' => '(GMT-3:00) America/Rosario (Argentine Time)',
'America/Santarem' => '(GMT-3:00) America/Santarem (Brasilia Time)',
'America/Sao_Paulo' => '(GMT-3:00) America/Sao_Paulo (Brasilia Time)',
'Antarctica/Rothera' => '(GMT-3:00) Antarctica/Rothera (Rothera Time)',
'Brazil/East' => '(GMT-3:00) Brazil/East (Brasilia Time)',
'America/Noronha' => '(GMT-2:00) America/Noronha (Fernando de Noronha Time)',
'Atlantic/South_Georgia' => '(GMT-2:00) Atlantic/South_Georgia (South Georgia Standard Time)',
'Brazil/DeNoronha' => '(GMT-2:00) Brazil/DeNoronha (Fernando de Noronha Time)',
'America/Scoresbysund' => '(GMT-1:00) America/Scoresbysund (Eastern Greenland Time)',
'Atlantic/Azores' => '(GMT-1:00) Atlantic/Azores (Azores Time)',
'Atlantic/Cape_Verde' => '(GMT-1:00) Atlantic/Cape_Verde (Cape Verde Time)',
'Africa/Abidjan' => '(GMT+0:00) Africa/Abidjan (Greenwich Mean Time)',
'Africa/Accra' => '(GMT+0:00) Africa/Accra (Ghana Mean Time)',
'Africa/Bamako' => '(GMT+0:00) Africa/Bamako (Greenwich Mean Time)',
'Africa/Banjul' => '(GMT+0:00) Africa/Banjul (Greenwich Mean Time)',
'Africa/Bissau' => '(GMT+0:00) Africa/Bissau (Greenwich Mean Time)',
'Africa/Casablanca' => '(GMT+0:00) Africa/Casablanca (Western European Time)',
'Africa/Conakry' => '(GMT+0:00) Africa/Conakry (Greenwich Mean Time)',
'Africa/Dakar' => '(GMT+0:00) Africa/Dakar (Greenwich Mean Time)',
'Africa/El_Aaiun' => '(GMT+0:00) Africa/El_Aaiun (Western European Time)',
'Africa/Freetown' => '(GMT+0:00) Africa/Freetown (Greenwich Mean Time)',
'Africa/Lome' => '(GMT+0:00) Africa/Lome (Greenwich Mean Time)',
'Africa/Monrovia' => '(GMT+0:00) Africa/Monrovia (Greenwich Mean Time)',
'Africa/Nouakchott' => '(GMT+0:00) Africa/Nouakchott (Greenwich Mean Time)',
'Africa/Ouagadougou' => '(GMT+0:00) Africa/Ouagadougou (Greenwich Mean Time)',
'Africa/Sao_Tome' => '(GMT+0:00) Africa/Sao_Tome (Greenwich Mean Time)',
'Africa/Timbuktu' => '(GMT+0:00) Africa/Timbuktu (Greenwich Mean Time)',
'America/Danmarkshavn' => '(GMT+0:00) America/Danmarkshavn (Greenwich Mean Time)',
'Atlantic/Canary' => '(GMT+0:00) Atlantic/Canary (Western European Time)',
'Atlantic/Faeroe' => '(GMT+0:00) Atlantic/Faeroe (Western European Time)',
'Atlantic/Faroe' => '(GMT+0:00) Atlantic/Faroe (Western European Time)',
'Atlantic/Madeira' => '(GMT+0:00) Atlantic/Madeira (Western European Time)',
'Atlantic/Reykjavik' => '(GMT+0:00) Atlantic/Reykjavik (Greenwich Mean Time)',
'Atlantic/St_Helena' => '(GMT+0:00) Atlantic/St_Helena (Greenwich Mean Time)',
'Europe/Belfast' => '(GMT+0:00) Europe/Belfast (Greenwich Mean Time)',
'Europe/Dublin' => '(GMT+0:00) Europe/Dublin (Greenwich Mean Time)',
'Europe/Guernsey' => '(GMT+0:00) Europe/Guernsey (Greenwich Mean Time)',
'Europe/Isle_of_Man' => '(GMT+0:00) Europe/Isle_of_Man (Greenwich Mean Time)',
'Europe/Jersey' => '(GMT+0:00) Europe/Jersey (Greenwich Mean Time)',
'Europe/Lisbon' => '(GMT+0:00) Europe/Lisbon (Western European Time)',
'Europe/London' => '(GMT+0:00) Europe/London (Greenwich Mean Time)',
'Africa/Algiers' => '(GMT+1:00) Africa/Algiers (Central European Time)',
'Africa/Bangui' => '(GMT+1:00) Africa/Bangui (Western African Time)',
'Africa/Brazzaville' => '(GMT+1:00) Africa/Brazzaville (Western African Time)',
'Africa/Ceuta' => '(GMT+1:00) Africa/Ceuta (Central European Time)',
'Africa/Douala' => '(GMT+1:00) Africa/Douala (Western African Time)',
'Africa/Kinshasa' => '(GMT+1:00) Africa/Kinshasa (Western African Time)',
'Africa/Lagos' => '(GMT+1:00) Africa/Lagos (Western African Time)',
'Africa/Libreville' => '(GMT+1:00) Africa/Libreville (Western African Time)',
'Africa/Luanda' => '(GMT+1:00) Africa/Luanda (Western African Time)',
'Africa/Malabo' => '(GMT+1:00) Africa/Malabo (Western African Time)',
'Africa/Ndjamena' => '(GMT+1:00) Africa/Ndjamena (Western African Time)',
'Africa/Niamey' => '(GMT+1:00) Africa/Niamey (Western African Time)',
'Africa/Porto-Novo' => '(GMT+1:00) Africa/Porto-Novo (Western African Time)',
'Africa/Tunis' => '(GMT+1:00) Africa/Tunis (Central European Time)',
'Africa/Windhoek' => '(GMT+1:00) Africa/Windhoek (Western African Time)',
'Arctic/Longyearbyen' => '(GMT+1:00) Arctic/Longyearbyen (Central European Time)',
'Atlantic/Jan_Mayen' => '(GMT+1:00) Atlantic/Jan_Mayen (Central European Time)',
'Europe/Amsterdam' => '(GMT+1:00) Europe/Amsterdam (Central European Time)',
'Europe/Andorra' => '(GMT+1:00) Europe/Andorra (Central European Time)',
'Europe/Belgrade' => '(GMT+1:00) Europe/Belgrade (Central European Time)',
'Europe/Berlin' => '(GMT+1:00) Europe/Berlin (Central European Time)',
'Europe/Bratislava' => '(GMT+1:00) Europe/Bratislava (Central European Time)',
'Europe/Brussels' => '(GMT+1:00) Europe/Brussels (Central European Time)',
'Europe/Budapest' => '(GMT+1:00) Europe/Budapest (Central European Time)',
'Europe/Copenhagen' => '(GMT+1:00) Europe/Copenhagen (Central European Time)',
'Europe/Gibraltar' => '(GMT+1:00) Europe/Gibraltar (Central European Time)',
'Europe/Ljubljana' => '(GMT+1:00) Europe/Ljubljana (Central European Time)',
'Europe/Luxembourg' => '(GMT+1:00) Europe/Luxembourg (Central European Time)',
'Europe/Madrid' => '(GMT+1:00) Europe/Madrid (Central European Time)',
'Europe/Malta' => '(GMT+1:00) Europe/Malta (Central European Time)',
'Europe/Monaco' => '(GMT+1:00) Europe/Monaco (Central European Time)',
'Europe/Oslo' => '(GMT+1:00) Europe/Oslo (Central European Time)',
'Europe/Paris' => '(GMT+1:00) Europe/Paris (Central European Time)',
'Europe/Podgorica' => '(GMT+1:00) Europe/Podgorica (Central European Time)',
'Europe/Prague' => '(GMT+1:00) Europe/Prague (Central European Time)',
'Europe/Rome' => '(GMT+1:00) Europe/Rome (Central European Time)',
'Europe/San_Marino' => '(GMT+1:00) Europe/San_Marino (Central European Time)',
'Europe/Sarajevo' => '(GMT+1:00) Europe/Sarajevo (Central European Time)',
'Europe/Skopje' => '(GMT+1:00) Europe/Skopje (Central European Time)',
'Europe/Stockholm' => '(GMT+1:00) Europe/Stockholm (Central European Time)',
'Europe/Tirane' => '(GMT+1:00) Europe/Tirane (Central European Time)',
'Europe/Vaduz' => '(GMT+1:00) Europe/Vaduz (Central European Time)',
'Europe/Vatican' => '(GMT+1:00) Europe/Vatican (Central European Time)',
'Europe/Vienna' => '(GMT+1:00) Europe/Vienna (Central European Time)',
'Europe/Warsaw' => '(GMT+1:00) Europe/Warsaw (Central European Time)',
'Europe/Zagreb' => '(GMT+1:00) Europe/Zagreb (Central European Time)',
'Europe/Zurich' => '(GMT+1:00) Europe/Zurich (Central European Time)',
'Africa/Blantyre' => '(GMT+2:00) Africa/Blantyre (Central African Time)',
'Africa/Bujumbura' => '(GMT+2:00) Africa/Bujumbura (Central African Time)',
'Africa/Cairo' => '(GMT+2:00) Africa/Cairo (Eastern European Time)',
'Africa/Gaborone' => '(GMT+2:00) Africa/Gaborone (Central African Time)',
'Africa/Harare' => '(GMT+2:00) Africa/Harare (Central African Time)',
'Africa/Johannesburg' => '(GMT+2:00) Africa/Johannesburg (South Africa Standard Time)',
'Africa/Kigali' => '(GMT+2:00) Africa/Kigali (Central African Time)',
'Africa/Lubumbashi' => '(GMT+2:00) Africa/Lubumbashi (Central African Time)',
'Africa/Lusaka' => '(GMT+2:00) Africa/Lusaka (Central African Time)',
'Africa/Maputo' => '(GMT+2:00) Africa/Maputo (Central African Time)',
'Africa/Maseru' => '(GMT+2:00) Africa/Maseru (South Africa Standard Time)',
'Africa/Mbabane' => '(GMT+2:00) Africa/Mbabane (South Africa Standard Time)',
'Africa/Tripoli' => '(GMT+2:00) Africa/Tripoli (Eastern European Time)',
'Asia/Amman' => '(GMT+2:00) Asia/Amman (Eastern European Time)',
'Asia/Beirut' => '(GMT+2:00) Asia/Beirut (Eastern European Time)',
'Asia/Damascus' => '(GMT+2:00) Asia/Damascus (Eastern European Time)',
'Asia/Gaza' => '(GMT+2:00) Asia/Gaza (Eastern European Time)',
'Asia/Istanbul' => '(GMT+2:00) Asia/Istanbul (Eastern European Time)',
'Asia/Jerusalem' => '(GMT+2:00) Asia/Jerusalem (Israel Standard Time)',
'Asia/Nicosia' => '(GMT+2:00) Asia/Nicosia (Eastern European Time)',
'Asia/Tel_Aviv' => '(GMT+2:00) Asia/Tel_Aviv (Israel Standard Time)',
'Europe/Athens' => '(GMT+2:00) Europe/Athens (Eastern European Time)',
'Europe/Bucharest' => '(GMT+2:00) Europe/Bucharest (Eastern European Time)',
'Europe/Chisinau' => '(GMT+2:00) Europe/Chisinau (Eastern European Time)',
'Europe/Helsinki' => '(GMT+2:00) Europe/Helsinki (Eastern European Time)',
'Europe/Istanbul' => '(GMT+2:00) Europe/Istanbul (Eastern European Time)',
'Europe/Kaliningrad' => '(GMT+2:00) Europe/Kaliningrad (Eastern European Time)',
'Europe/Kiev' => '(GMT+2:00) Europe/Kiev (Eastern European Time)',
'Europe/Mariehamn' => '(GMT+2:00) Europe/Mariehamn (Eastern European Time)',
'Europe/Minsk' => '(GMT+2:00) Europe/Minsk (Eastern European Time)',
'Europe/Nicosia' => '(GMT+2:00) Europe/Nicosia (Eastern European Time)',
'Europe/Riga' => '(GMT+2:00) Europe/Riga (Eastern European Time)',
'Europe/Simferopol' => '(GMT+2:00) Europe/Simferopol (Eastern European Time)',
'Europe/Sofia' => '(GMT+2:00) Europe/Sofia (Eastern European Time)',
'Europe/Tallinn' => '(GMT+2:00) Europe/Tallinn (Eastern European Time)',
'Europe/Tiraspol' => '(GMT+2:00) Europe/Tiraspol (Eastern European Time)',
'Europe/Uzhgorod' => '(GMT+2:00) Europe/Uzhgorod (Eastern European Time)',
'Europe/Vilnius' => '(GMT+2:00) Europe/Vilnius (Eastern European Time)',
'Europe/Zaporozhye' => '(GMT+2:00) Europe/Zaporozhye (Eastern European Time)',
'Africa/Addis_Ababa' => '(GMT+3:00) Africa/Addis_Ababa (Eastern African Time)',
'Africa/Asmara' => '(GMT+3:00) Africa/Asmara (Eastern African Time)',
'Africa/Asmera' => '(GMT+3:00) Africa/Asmera (Eastern African Time)',
'Africa/Dar_es_Salaam' => '(GMT+3:00) Africa/Dar_es_Salaam (Eastern African Time)',
'Africa/Djibouti' => '(GMT+3:00) Africa/Djibouti (Eastern African Time)',
'Africa/Kampala' => '(GMT+3:00) Africa/Kampala (Eastern African Time)',
'Africa/Khartoum' => '(GMT+3:00) Africa/Khartoum (Eastern African Time)',
'Africa/Mogadishu' => '(GMT+3:00) Africa/Mogadishu (Eastern African Time)',
'Africa/Nairobi' => '(GMT+3:00) Africa/Nairobi (Eastern African Time)',
'Antarctica/Syowa' => '(GMT+3:00) Antarctica/Syowa (Syowa Time)',
'Asia/Aden' => '(GMT+3:00) Asia/Aden (Arabia Standard Time)',
'Asia/Baghdad' => '(GMT+3:00) Asia/Baghdad (Arabia Standard Time)',
'Asia/Bahrain' => '(GMT+3:00) Asia/Bahrain (Arabia Standard Time)',
'Asia/Kuwait' => '(GMT+3:00) Asia/Kuwait (Arabia Standard Time)',
'Asia/Qatar' => '(GMT+3:00) Asia/Qatar (Arabia Standard Time)',
'Europe/Moscow' => '(GMT+3:00) Europe/Moscow (Moscow Standard Time)',
'Europe/Volgograd' => '(GMT+3:00) Europe/Volgograd (Volgograd Time)',
'Indian/Antananarivo' => '(GMT+3:00) Indian/Antananarivo (Eastern African Time)',
'Indian/Comoro' => '(GMT+3:00) Indian/Comoro (Eastern African Time)',
'Indian/Mayotte' => '(GMT+3:00) Indian/Mayotte (Eastern African Time)',
'Asia/Tehran' => '(GMT+3:30) Asia/Tehran (Iran Standard Time)',
'Asia/Baku' => '(GMT+4:00) Asia/Baku (Azerbaijan Time)',
'Asia/Dubai' => '(GMT+4:00) Asia/Dubai (Gulf Standard Time)',
'Asia/Muscat' => '(GMT+4:00) Asia/Muscat (Gulf Standard Time)',
'Asia/Tbilisi' => '(GMT+4:00) Asia/Tbilisi (Georgia Time)',
'Asia/Yerevan' => '(GMT+4:00) Asia/Yerevan (Armenia Time)',
'Europe/Samara' => '(GMT+4:00) Europe/Samara (Samara Time)',
'Indian/Mahe' => '(GMT+4:00) Indian/Mahe (Seychelles Time)',
'Indian/Mauritius' => '(GMT+4:00) Indian/Mauritius (Mauritius Time)',
'Indian/Reunion' => '(GMT+4:00) Indian/Reunion (Reunion Time)',
'Asia/Kabul' => '(GMT+4:30) Asia/Kabul (Afghanistan Time)',
'Asia/Aqtau' => '(GMT+5:00) Asia/Aqtau (Aqtau Time)',
'Asia/Aqtobe' => '(GMT+5:00) Asia/Aqtobe (Aqtobe Time)',
'Asia/Ashgabat' => '(GMT+5:00) Asia/Ashgabat (Turkmenistan Time)',
'Asia/Ashkhabad' => '(GMT+5:00) Asia/Ashkhabad (Turkmenistan Time)',
'Asia/Dushanbe' => '(GMT+5:00) Asia/Dushanbe (Tajikistan Time)',
'Asia/Karachi' => '(GMT+5:00) Asia/Karachi (Pakistan Time)',
'Asia/Oral' => '(GMT+5:00) Asia/Oral (Oral Time)',
'Asia/Samarkand' => '(GMT+5:00) Asia/Samarkand (Uzbekistan Time)',
'Asia/Tashkent' => '(GMT+5:00) Asia/Tashkent (Uzbekistan Time)',
'Asia/Yekaterinburg' => '(GMT+5:00) Asia/Yekaterinburg (Yekaterinburg Time)',
'Indian/Kerguelen' => '(GMT+5:00) Indian/Kerguelen (French Southern & Antarctic Lands Time)',
'Indian/Maldives' => '(GMT+5:00) Indian/Maldives (Maldives Time)',
'Asia/Calcutta' => '(GMT+5:30) Asia/Calcutta (India Standard Time)',
'Asia/Colombo' => '(GMT+5:30) Asia/Colombo (India Standard Time)',
'Asia/Kolkata' => '(GMT+5:30) Asia/Kolkata (India Standard Time)',
'Asia/Katmandu' => '(GMT+5:45) Asia/Katmandu (Nepal Time)',
'Antarctica/Mawson' => '(GMT+6:00) Antarctica/Mawson (Mawson Time)',
'Antarctica/Vostok' => '(GMT+6:00) Antarctica/Vostok (Vostok Time)',
'Asia/Almaty' => '(GMT+6:00) Asia/Almaty (Alma-Ata Time)',
'Asia/Bishkek' => '(GMT+6:00) Asia/Bishkek (Kirgizstan Time)',
'Asia/Dacca' => '(GMT+6:00) Asia/Dacca (Bangladesh Time)',
'Asia/Dhaka' => '(GMT+6:00) Asia/Dhaka (Bangladesh Time)',
'Asia/Novosibirsk' => '(GMT+6:00) Asia/Novosibirsk (Novosibirsk Time)',
'Asia/Omsk' => '(GMT+6:00) Asia/Omsk (Omsk Time)',
'Asia/Qyzylorda' => '(GMT+6:00) Asia/Qyzylorda (Qyzylorda Time)',
'Asia/Thimbu' => '(GMT+6:00) Asia/Thimbu (Bhutan Time)',
'Asia/Thimphu' => '(GMT+6:00) Asia/Thimphu (Bhutan Time)',
'Indian/Chagos' => '(GMT+6:00) Indian/Chagos (Indian Ocean Territory Time)',
'Asia/Rangoon' => '(GMT+6:30) Asia/Rangoon (Myanmar Time)',
'Indian/Cocos' => '(GMT+6:30) Indian/Cocos (Cocos Islands Time)',
'Antarctica/Davis' => '(GMT+7:00) Antarctica/Davis (Davis Time)',
'Asia/Bangkok' => '(GMT+7:00) Asia/Bangkok (Indochina Time)',
'Asia/Ho_Chi_Minh' => '(GMT+7:00) Asia/Ho_Chi_Minh (Indochina Time)',
'Asia/Hovd' => '(GMT+7:00) Asia/Hovd (Hovd Time)',
'Asia/Jakarta' => '(GMT+7:00) Asia/Jakarta (West Indonesia Time)',
'Asia/Krasnoyarsk' => '(GMT+7:00) Asia/Krasnoyarsk (Krasnoyarsk Time)',
'Asia/Phnom_Penh' => '(GMT+7:00) Asia/Phnom_Penh (Indochina Time)',
'Asia/Pontianak' => '(GMT+7:00) Asia/Pontianak (West Indonesia Time)',
'Asia/Saigon' => '(GMT+7:00) Asia/Saigon (Indochina Time)',
'Asia/Vientiane' => '(GMT+7:00) Asia/Vientiane (Indochina Time)',
'Indian/Christmas' => '(GMT+7:00) Indian/Christmas (Christmas Island Time)',
'Antarctica/Casey' => '(GMT+8:00) Antarctica/Casey (Western Standard Time (Australia))',
'Asia/Brunei' => '(GMT+8:00) Asia/Brunei (Brunei Time)',
'Asia/Choibalsan' => '(GMT+8:00) Asia/Choibalsan (Choibalsan Time)',
'Asia/Chongqing' => '(GMT+8:00) Asia/Chongqing (China Standard Time)',
'Asia/Chungking' => '(GMT+8:00) Asia/Chungking (China Standard Time)',
'Asia/Harbin' => '(GMT+8:00) Asia/Harbin (China Standard Time)',
'Asia/Hong_Kong' => '(GMT+8:00) Asia/Hong_Kong (Hong Kong Time)',
'Asia/Irkutsk' => '(GMT+8:00) Asia/Irkutsk (Irkutsk Time)',
'Asia/Kashgar' => '(GMT+8:00) Asia/Kashgar (China Standard Time)',
'Asia/Kuala_Lumpur' => '(GMT+8:00) Asia/Kuala_Lumpur (Malaysia Time)',
'Asia/Kuching' => '(GMT+8:00) Asia/Kuching (Malaysia Time)',
'Asia/Macao' => '(GMT+8:00) Asia/Macao (China Standard Time)',
'Asia/Macau' => '(GMT+8:00) Asia/Macau (China Standard Time)',
'Asia/Makassar' => '(GMT+8:00) Asia/Makassar (Central Indonesia Time)',
'Asia/Manila' => '(GMT+8:00) Asia/Manila (Philippines Time)',
'Asia/Shanghai' => '(GMT+8:00) Asia/Shanghai (China Standard Time)',
'Asia/Singapore' => '(GMT+8:00) Asia/Singapore (Singapore Time)',
'Asia/Taipei' => '(GMT+8:00) Asia/Taipei (China Standard Time)',
'Asia/Ujung_Pandang' => '(GMT+8:00) Asia/Ujung_Pandang (Central Indonesia Time)',
'Asia/Ulaanbaatar' => '(GMT+8:00) Asia/Ulaanbaatar (Ulaanbaatar Time)',
'Asia/Ulan_Bator' => '(GMT+8:00) Asia/Ulan_Bator (Ulaanbaatar Time)',
'Asia/Urumqi' => '(GMT+8:00) Asia/Urumqi (China Standard Time)',
'Australia/Perth' => '(GMT+8:00) Australia/Perth (Western Standard Time (Australia))',
'Australia/West' => '(GMT+8:00) Australia/West (Western Standard Time (Australia))',
'Australia/Eucla' => '(GMT+8:45) Australia/Eucla (Central Western Standard Time (Australia))',
'Asia/Dili' => '(GMT+9:00) Asia/Dili (Timor-Leste Time)',
'Asia/Jayapura' => '(GMT+9:00) Asia/Jayapura (East Indonesia Time)',
'Asia/Pyongyang' => '(GMT+9:00) Asia/Pyongyang (Korea Standard Time)',
'Asia/Seoul' => '(GMT+9:00) Asia/Seoul (Korea Standard Time)',
'Asia/Tokyo' => '(GMT+9:00) Asia/Tokyo (Japan Standard Time)',
'Asia/Yakutsk' => '(GMT+9:00) Asia/Yakutsk (Yakutsk Time)',
'Australia/Adelaide' => '(GMT+9:30) Australia/Adelaide (Central Standard Time (South Australia))',
'Australia/Broken_Hill' => '(GMT+9:30) Australia/Broken_Hill (Central Standard Time (South Australia/New South Wales))',
'Australia/Darwin' => '(GMT+9:30) Australia/Darwin (Central Standard Time (Northern Territory))',
'Australia/North' => '(GMT+9:30) Australia/North (Central Standard Time (Northern Territory))',
'Australia/South' => '(GMT+9:30) Australia/South (Central Standard Time (South Australia))',
'Australia/Yancowinna' => '(GMT+9:30) Australia/Yancowinna (Central Standard Time (South Australia/New South Wales))',
'Antarctica/DumontDUrville' => '(GMT+10:00) Antarctica/DumontDUrville (Dumont-d\'Urville Time)',
'Asia/Sakhalin' => '(GMT+10:00) Asia/Sakhalin (Sakhalin Time)',
'Asia/Vladivostok' => '(GMT+10:00) Asia/Vladivostok (Vladivostok Time)',
'Australia/ACT' => '(GMT+10:00) Australia/ACT (Eastern Standard Time (New South Wales))',
'Australia/Brisbane' => '(GMT+10:00) Australia/Brisbane (Eastern Standard Time (Queensland))',
'Australia/Canberra' => '(GMT+10:00) Australia/Canberra (Eastern Standard Time (New South Wales))',
'Australia/Currie' => '(GMT+10:00) Australia/Currie (Eastern Standard Time (New South Wales))',
'Australia/Hobart' => '(GMT+10:00) Australia/Hobart (Eastern Standard Time (Tasmania))',
'Australia/Lindeman' => '(GMT+10:00) Australia/Lindeman (Eastern Standard Time (Queensland))',
'Australia/Melbourne' => '(GMT+10:00) Australia/Melbourne (Eastern Standard Time (Victoria))',
'Australia/NSW' => '(GMT+10:00) Australia/NSW (Eastern Standard Time (New South Wales))',
'Australia/Queensland' => '(GMT+10:00) Australia/Queensland (Eastern Standard Time (Queensland))',
'Australia/Sydney' => '(GMT+10:00) Australia/Sydney (Eastern Standard Time (New South Wales))',
'Australia/Tasmania' => '(GMT+10:00) Australia/Tasmania (Eastern Standard Time (Tasmania))',
'Australia/Victoria' => '(GMT+10:00) Australia/Victoria (Eastern Standard Time (Victoria))',
'Australia/LHI' => '(GMT+10:30) Australia/LHI (Lord Howe Standard Time)',
'Australia/Lord_Howe' => '(GMT+10:30) Australia/Lord_Howe (Lord Howe Standard Time)',
'Asia/Magadan' => '(GMT+11:00) Asia/Magadan (Magadan Time)',
'Antarctica/McMurdo' => '(GMT+12:00) Antarctica/McMurdo (New Zealand Standard Time)',
'Antarctica/South_Pole' => '(GMT+12:00) Antarctica/South_Pole (New Zealand Standard Time)',
'Asia/Anadyr' => '(GMT+12:00) Asia/Anadyr (Anadyr Time)',
'Asia/Kamchatka' => '(GMT+12:00) Asia/Kamchatka (Petropavlovsk-Kamchatski Time)',
];
return $timezones;
} | DatetimeHelper::timezones()
@return array | timezones | php | dereuromark/cakephp-tools | src/View/Helper/TimeHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/TimeHelper.php | MIT |
public function encodeEmail($mail) {
$pieces = explode('@', $mail);
if (count($pieces) < 2) {
return $mail;
}
[$mail1, $mail2] = $pieces;
$encMail = $this->encodeText($mail1) . '<span>@</span>' . $this->encodeText($mail2);
return $encMail;
} | It is still believed that encoding will stop spam-bots being able to find your email address.
Nevertheless, encoded email address harvester are on the way (http://www.dreamweaverfever.com/experiments/spam/).
Helper Function to Obfuscate Email by inserting a span tag (not more! not very secure on its own...)
each part of this mail now does not make sense anymore on its own
(striptags will not work either)
@param string $mail Email, necessary (and valid - containing one @)
@return string | encodeEmail | php | dereuromark/cakephp-tools | src/View/Helper/ObfuscateHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/ObfuscateHelper.php | MIT |
public function encodeEmailUrl($mail, $text = null, array $params = [], array $attr = []) {
$defaults = [
'title' => __d('tools', 'for use in an external mail client'),
'class' => 'email',
'escape' => false,
];
if (!$text) {
$text = $this->encodeEmail($mail);
}
$encMail = 'mailto:' . $mail;
// additionally there could be a span tag in between: email<span syle="display:none"></span>@web.de
$querystring = '';
foreach ($params as $key => $val) {
if ($querystring) {
$querystring .= "&$key=" . rawurlencode($val);
} else {
$querystring = "?$key=" . rawurlencode($val);
}
}
$attr = array_merge($defaults, $attr);
$xmail = $this->Html->link('', $encMail . $querystring, $attr);
$xmail1 = mb_substr($xmail, 0, -4);
$xmail2 = mb_substr($xmail, -4, 4);
$len = mb_strlen($xmail1);
$i = 0;
$par = [];
while ($i < $len) {
$c = mt_rand(2, 6);
$par[] = (mb_substr($xmail1, $i, $c));
$i += $c;
}
$join = implode('\'+ \'', $par);
return '<script language=javascript><!--
document.write(\'' . $join . '\');
//--></script>
' . $text . '
<script language=javascript><!--
document.write(\'' . $xmail2 . '\');
//--></script>';
} | Obfuscates Email (works without JS!) to avoid spam bots to get it
@param string $mail Email to encode
@param string|null $text Text, ptional (if none is given, email will be text as well)
@param array $params ?subject=y&body=y to be attached to "mailto:xyz"
@param array<string, mixed> $attr HTML tag attributes
@return string Save string with JS generated link around email (and non JS fallback) | encodeEmailUrl | php | dereuromark/cakephp-tools | src/View/Helper/ObfuscateHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/ObfuscateHelper.php | MIT |
public function encodeText($text) {
$encmail = '';
$length = mb_strlen($text);
for ($i = 0; $i < $length; $i++) {
$encMod = mt_rand(0, 2);
switch ($encMod) {
case 0: // None
$encmail .= mb_substr($text, $i, 1);
break;
case 1: // Decimal
$encmail .= '&#' . ord(mb_substr($text, $i, 1)) . ';';
break;
case 2: // Hexadecimal
$encmail .= '&#x' . dechex(ord(mb_substr($text, $i, 1))) . ';';
break;
}
}
return $encmail;
} | Encodes Piece of Text (without usage of JS!) to avoid spam bots to get it
@param string $text Text to encode
@return string (randomly encoded) | encodeText | php | dereuromark/cakephp-tools | src/View/Helper/ObfuscateHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/ObfuscateHelper.php | MIT |
public function wordCensor(string $str, array $censored, ?string $replacement = null) {
if (!$censored) {
return $str;
}
$str = ' ' . $str . ' ';
// \w, \b and a few others do not match on a unicode character
// set for performance reasons. As a result words like ..ber
// will not match on a word boundary. Instead, we'll assume that
// a bad word will be bookended by any of these characters.
$delim = '[-_\'\"`() {}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]';
foreach ($censored as $badword) {
if ($replacement !== null) {
$str = (string)preg_replace("/({$delim})(" . str_replace('\*', '\w*?', preg_quote($badword, '/')) . ")({$delim})/i", "\\1{$replacement}\\3", $str);
} else {
$str = (string)preg_replace_callback("/({$delim})(" . str_replace('\*', '\w*?', preg_quote($badword, '/')) . ")({$delim})/i", function ($matches) {
return $matches[1] . str_repeat('#', strlen($matches[2])) . $matches[3];
}, $str);
}
}
return trim($str);
} | Word Censoring Function
Supply a string and an array of disallowed words and any
matched words will be converted to #### or to the replacement
word you've submitted.
@param string $str the text string
@param array $censored the array of censored words
@param string|null $replacement the optional replacement value
@return string | wordCensor | php | dereuromark/cakephp-tools | src/View/Helper/ObfuscateHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/ObfuscateHelper.php | MIT |
public function __construct(View $View, array $config = []) {
$defaults = (array)Configure::read('Meter') + $this->_defaults;
$config += $defaults;
parent::__construct($View, $config);
} | @param \Cake\View\View $View
@param array<string, mixed> $config | __construct | php | dereuromark/cakephp-tools | src/View/Helper/MeterHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/MeterHelper.php | MIT |
public function htmlMeterBar($value, $max, $min = null, array $options = [], array $attributes = []) {
$defaults = [
'fallbackHtml' => null,
'overflow' => false,
];
$options += $defaults;
$value = $this->prepareValue($value, $max, $min ?? 0.0, $options['overflow']);
$max = $this->prepareMax($value, $max, $options['overflow']);
$min = $this->prepareMin($value, $min ?? 0.0, $options['overflow']);
$progress = $this->calculatePercentage($max - $min, $value - $min);
$attributes += [
'value' => $value,
'min' => $min < 0 ? 0 : $min,
'max' => $max,
'title' => Number::toPercentage($progress, 0, ['multiply' => true]),
];
$fallback = '';
if ($options['fallbackHtml']) {
$fallback = $options['fallbackHtml'];
}
return $this->Html->tag('meter', $fallback, $attributes);
} | Creates HTML5 meter element.
Note: This requires a textual fallback for IE12 and below.
Options:
- fallbackHtml: Use a fallback string if the browser cannot display this type of HTML5 element
- overflow: Set to true to allow the value to move the max/min boundaries
@param float $value
@param float $max
@param float|null $min
@param array<string, mixed> $options
@param array<string, mixed> $attributes
@return string | htmlMeterBar | php | dereuromark/cakephp-tools | src/View/Helper/MeterHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/MeterHelper.php | MIT |
protected function calculatePercentage($total, $is) {
$percentage = $total ? $is / $total : 0.0;
return $percentage;
} | @param float|int $total
@param float|int $is
@return float | calculatePercentage | php | dereuromark/cakephp-tools | src/View/Helper/MeterHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/MeterHelper.php | MIT |
public function draw($complete, int $length) {
if ($length < static::LENGTH_MIN) {
throw new InvalidArgumentException('Min length for such a progress bar is ' . static::LENGTH_MIN);
}
$barLength = $this->calculateBarLength($complete, $length);
$bar = '';
if ($barLength > 0) {
$bar = str_repeat($this->getConfig('full'), $barLength);
}
$pad = $length - $barLength;
if ($pad > 0) {
$bar .= str_repeat($this->getConfig('empty'), $pad);
}
return $bar;
} | Render the progress bar based on the current state.
@param float $complete
@param int $length
@throws \InvalidArgumentException
@return string | draw | php | dereuromark/cakephp-tools | src/View/Helper/MeterHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/MeterHelper.php | MIT |
protected function prepareValue($value, $max, $min, bool $overflow) {
if ($max < $min) {
throw new InvalidArgumentException('Max needs to be larger than Min.');
}
if ($value > $max && !$overflow) {
$value = $max;
}
if ($value < $min && !$overflow) {
$value = $min;
}
return $this->roundValue($value);
} | Prepares the input value based on max/min and if
- overflow: adjust the min/max by value
- not overflow: adjust the value by min/max
Also: Rounds as per reasonable precision based on exponent
@param float $value
@param float $max
@param float $min
@param bool $overflow
@throws \InvalidArgumentException
@return float | prepareValue | php | dereuromark/cakephp-tools | src/View/Helper/MeterHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/MeterHelper.php | MIT |
protected function prepareMax($value, $max, bool $overflow) {
if ($value <= $max) {
return $max;
}
if ($overflow) {
return $value;
}
return $max;
} | Prepares the max value
- overflow: adjust the min/max by value
- not overflow: adjust the value by min/max
Also: Rounds as per reasonable precision based on exponent
@param float $value
@param float $max
@param bool $overflow
@return float | prepareMax | php | dereuromark/cakephp-tools | src/View/Helper/MeterHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/MeterHelper.php | MIT |
protected function prepareMin($value, $min, bool $overflow) {
if ($value > $min) {
return $min;
}
if ($overflow) {
return $value;
}
return $min;
} | Prepares the min value
- overflow: adjust the min/max by value
- not overflow: adjust the value by min/max
Also: Rounds as per reasonable precision based on exponent
@param float $value
@param float $min
@param bool $overflow
@return float | prepareMin | php | dereuromark/cakephp-tools | src/View/Helper/MeterHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/MeterHelper.php | MIT |
protected function roundValue($value) {
$precision = (int)$this->getConfig('precision');
$string = (string)$value;
if ($precision === -1 || strlen($string) < $precision) {
return $value;
}
$separatorIndex = strpos($string, '.');
$positive = $separatorIndex ?: 0;
$left = $precision - $positive;
return round($value, $left);
} | @param float $value
@return float | roundValue | php | dereuromark/cakephp-tools | src/View/Helper/MeterHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/MeterHelper.php | MIT |
public function __construct(View $view, array $config = []) {
$config += ['engine' => 'Tools.Text'];
parent::__construct($view, $config);
/** @psalm-var class-string<\Cake\Utility\Text>|null $engineClass */
$engineClass = App::className($config['engine'], 'Utility');
if ($engineClass === null) {
throw new CakeException(sprintf('Class for `%s` could not be found', $config['engine']));
}
/** @phpstan-ignore-next-line */
$this->_engine = new $engineClass($config);
} | ### Settings:
- `engine` Class name to use to replace Text functionality.
The class needs to be placed in the `Utility` directory.
@param \Cake\View\View $view the view object the helper is attached to.
@param array<string, mixed> $config Settings array Settings array | __construct | php | dereuromark/cakephp-tools | src/View/Helper/TextHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/TextHelper.php | MIT |
public function __construct(View $View, array $config = []) {
// Default the secure option to match the current URL.
$this->_defaultConfig['secure'] = (bool)env('HTTPS');
parent::__construct($View, $config);
} | @param \Cake\View\View $View
@param array<string, mixed> $config | __construct | php | dereuromark/cakephp-tools | src/View/Helper/GravatarHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/GravatarHelper.php | MIT |
protected function _cleanOptions($options) {
if (!isset($options['size']) || empty($options['size']) || !is_numeric($options['size'])) {
unset($options['size']);
} else {
$options['size'] = min(max($options['size'], 1), 512);
}
if (!$options['rating'] || !in_array(mb_strtolower($options['rating']), $this->_allowedRatings)) {
unset($options['rating']);
}
if (!$options['default']) {
unset($options['default']);
} else {
if (!in_array($options['default'], $this->_defaultIcons) && !Validation::url($options['default'])) {
unset($options['default']);
}
}
return $options;
} | Sanitize the options array
@param array<string, mixed> $options Array of options, keyed from default settings
@return array Clean options array | _cleanOptions | php | dereuromark/cakephp-tools | src/View/Helper/GravatarHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/GravatarHelper.php | MIT |
protected function _emailHash($email) {
return md5(mb_strtolower($email));
} | Generate email address hash
@param string $email Email address
@return string Email address hash | _emailHash | php | dereuromark/cakephp-tools | src/View/Helper/GravatarHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/GravatarHelper.php | MIT |
public function addItemAttribute($id = '', $key = '', $value = null) {
if ($value !== null) {
$this->_itemAttributes[$id][$key] = $value;
} elseif (!(isset($this->_itemAttributes[$id]) && in_array($key, $this->_itemAttributes[$id]))) {
$this->_itemAttributes[$id][] = $key;
}
} | AddItemAttribute function
Called to modify the attributes of the next <item> to be processed
Note that the content of a 'node' is processed before generating its wrapping <item> tag
@param string $id Id
@param string $key Key
@param mixed $value Value
@return void | addItemAttribute | php | dereuromark/cakephp-tools | src/View/Helper/TreeHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/TreeHelper.php | MIT |
protected function _suffix($reset = false) {
static $_splitCount = 0;
static $_splitCounter = 0;
if ($reset) {
$_splitCount = 0;
$_splitCounter = 0;
}
extract($this->_config);
if ($splitDepth || $splitCount) {
if (!$splitDepth) {
$_splitCount = $totalNodes / $splitCount;
$rounded = (int)$_splitCount;
if ($rounded < $_splitCount) {
$_splitCount = $rounded + 1;
}
} elseif ($depth == $splitDepth - 1) {
$total = $numberOfDirectChildren ?: $numberOfTotalChildren;
if ($total) {
$_splitCounter = 0;
$_splitCount = $total / $splitCount;
$rounded = (int)$_splitCount;
if ($rounded < $_splitCount) {
$_splitCount = $rounded + 1;
}
}
}
if (!$splitDepth || $depth == $splitDepth) {
$_splitCounter++;
if ($type && ($_splitCounter % $_splitCount) === 0 && !$lastChild) {
unset($this->_config['callback']);
return '</' . $type . '><' . $type . '>';
}
}
}
return '';
} | Suffix method.
Used to close and reopen a ul/ol to allow easier listings
@param bool $reset Reset
@return string | _suffix | php | dereuromark/cakephp-tools | src/View/Helper/TreeHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/TreeHelper.php | MIT |
public function nl2brExceptPre($str) {
$ex = explode('pre>', $str);
$ct = count($ex);
$newstr = '';
for ($i = 0; $i < $ct; $i++) {
if (($i % 2) == 0) {
$newstr .= nl2br($ex[$i]);
} else {
$newstr .= $ex[$i];
}
if ($ct - 1 != $i) {
$newstr .= 'pre>';
}
}
return $newstr;
} | Convert newlines to HTML line breaks except within PRE tags
@param string $str
@return string | nl2brExceptPre | php | dereuromark/cakephp-tools | src/View/Helper/TypographyHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/TypographyHelper.php | MIT |
protected function _formatNewlines($str) {
if ($str === '') {
return $str;
}
if (strpos($str, "\n") === false && !in_array($this->lastBlockElement, $this->innerBlockRequired)) {
return $str;
}
// Convert two consecutive newlines to paragraphs
$str = str_replace("\n\n", "</p>\n\n<p>", $str);
// Convert single spaces to <br /> tags
$str = (string)preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);
// Wrap the whole enchilada in enclosing paragraphs
if ($str !== "\n") {
// We trim off the right-side new line so that the closing </p> tag
// will be positioned immediately following the string, matching
// the behavior of the opening <p> tag
$str = '<p>' . rtrim($str) . '</p>';
}
// Remove empty paragraphs if they are on the first line, as this
// is a potential unintended consequence of the previous code
$str = (string)preg_replace("/<p><\/p>(.*)/", '\\1', $str, 1);
return $str;
} | Format Newlines
Converts newline characters into either <p> tags or <br />
@param string $str
@return string | _formatNewlines | php | dereuromark/cakephp-tools | src/View/Helper/TypographyHelper.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Helper/TypographyHelper.php | MIT |
public function __construct(array $config = []) {
$config += [
'template' => '<span class="{{class}}"{{attributes}}></span>',
'namespace' => 'solid',
];
parent::__construct($config);
} | @param array<string, mixed> $config | __construct | php | dereuromark/cakephp-tools | src/View/Icon/FontAwesome6Icon.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Icon/FontAwesome6Icon.php | MIT |
public function __construct(array $config = []) {
$config += [
'template' => '<span class="{{class}}"{{attributes}}>{{name}}</span>',
'namespace' => 'material-icons',
];
parent::__construct($config);
} | @param array<string, mixed> $config | __construct | php | dereuromark/cakephp-tools | src/View/Icon/MaterialIcon.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Icon/MaterialIcon.php | MIT |
public function __construct(array $config = []) {
$config += [
'template' => '<span class="{{class}}"{{attributes}}></span>',
'namespace' => 'fas',
];
parent::__construct($config);
} | @param array<string, mixed> $config | __construct | php | dereuromark/cakephp-tools | src/View/Icon/FontAwesome5Icon.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Icon/FontAwesome5Icon.php | MIT |
public function __construct(array $config = []) {
$this->template = new StringTemplate(['icon' => $config['template']]);
$this->config = $config;
} | @param array<string, mixed> $config | __construct | php | dereuromark/cakephp-tools | src/View/Icon/AbstractIcon.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Icon/AbstractIcon.php | MIT |
public function __construct(array $config = []) {
$config += [
'template' => '<span class="{{class}}"{{attributes}}></span>',
];
parent::__construct($config);
} | @param array<string, mixed> $config | __construct | php | dereuromark/cakephp-tools | src/View/Icon/BootstrapIcon.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Icon/BootstrapIcon.php | MIT |
public function __construct(array $config = []) {
$config += [
'template' => '<span class="{{class}}"{{attributes}}></span>',
];
parent::__construct($config);
} | @param array<string, mixed> $config | __construct | php | dereuromark/cakephp-tools | src/View/Icon/FontAwesome4Icon.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Icon/FontAwesome4Icon.php | MIT |
public function __construct(array $config = []) {
$config += [
'template' => '<span data-feather="{{name}}"{{attributes}}></span>',
];
parent::__construct($config);
} | @param array<string, mixed> $config | __construct | php | dereuromark/cakephp-tools | src/View/Icon/FeatherIcon.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/View/Icon/FeatherIcon.php | MIT |
public function language($language = null) {
$this->getRequest()->allowMethod(['post']);
$allowedLanguages = (array)Configure::read('Config.allowedLanguages');
if (!$language) {
$language = Configure::read('Config.defaultLanguage');
}
if (!$language && $allowedLanguages) {
$keys = array_keys($allowedLanguages);
$language = $allowedLanguages[array_shift($keys)];
}
if (!array_key_exists($language, $allowedLanguages)) {
throw new RuntimeException('Invalid Language');
}
$language = $allowedLanguages[$language];
$this->getRequest()->getSession()->write('Config.language', $language['locale']);
I18n::setLocale($language['locale']);
$this->Flash->success(__d('tools', 'Language switched to {0}', $language['name']));
/** @var \Cake\Http\Response */
return $this->redirect($this->referer());
} | Switch language as post link.
@param string|null $language
@throws \RuntimeException
@return \Cake\Http\Response | language | php | dereuromark/cakephp-tools | src/Controller/ShuntRequestController.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/ShuntRequestController.php | MIT |
public function beforeRedirect(EventInterface $event, $url, Response $response) {
$actions = $this->getConfig('actions');
$currentAction = $this->getController()->getRequest()->getParam('action');
if ($currentAction && $actions && !in_array($currentAction, $actions, true)) {
return null;
}
$referer = $this->referer();
if (!$referer) {
return null;
}
return $response->withLocation($referer);
} | @param \Cake\Event\EventInterface $event
@param array|string $url A string or array containing the redirect location
@param \Cake\Http\Response $response The response object.
@return \Cake\Http\Response|null | beforeRedirect | php | dereuromark/cakephp-tools | src/Controller/Component/RefererRedirectComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/RefererRedirectComponent.php | MIT |
public function startup(EventInterface $event) {
if ($this->getConfig('notrim') || Configure::read('DataPreparation.notrim')) {
return;
}
$request = $this->controller->getRequest();
if ($this->controller->getRequest()->getData()) {
$newData = Utility::trimDeep($request->getData());
foreach ($newData as $k => $v) {
if ($request->getData($k) !== $v) {
$request = $request->withData($k, $v);
}
}
}
if ($request->getQuery()) {
$queryData = Utility::trimDeep($request->getQuery());
if ($queryData !== $request->getQuery()) {
$request = $request->withQueryParams($queryData);
}
}
if ($request->getParam('pass')) {
$passData = Utility::trimDeep($request->getParam('pass'));
if ($passData !== $request->getParam('pass')) {
$request = $request->withParam('pass', $passData);
}
}
if ($request === $this->controller->getRequest()) {
return;
}
$this->controller->setRequest($request);
} | Trim data from the request to ensure trustworthy input regarding
emptiness. This needs to happen in communication layer to ensure
this for all other layers.
Can be skipped for edge cases using
- locally: beforeFilter() inside the specific controller
- globally: `DataPreparation.notrim` Configure setting.
@param \Cake\Event\EventInterface $event
@return void | startup | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public function getSafeRedirectUrl($default, $data = null, $key = 'redirect') {
$redirectUrl = $data ?: ($this->controller->getRequest()->getData($key) ?: $this->controller->getRequest()->getQuery($key));
if ($redirectUrl && (mb_substr($redirectUrl, 0, 1) !== '/' || mb_substr($redirectUrl, 0, 2) === '//')) {
$redirectUrl = null;
}
return $redirectUrl ?: $default;
} | Returns internal redirect only, otherwise falls back to default.
Lookup order:
- POST data
- query string
- provided default
@param array|string $default
@param array|string|null $data
@param string $key
@return array|string | getSafeRedirectUrl | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public function listActions() {
$parentClass = get_parent_class($this->controller);
if (!$parentClass) {
return [];
}
$parentClassMethods = get_class_methods($parentClass);
$subClassMethods = get_class_methods($this->controller);
$classMethods = array_diff($subClassMethods, $parentClassMethods);
foreach ($classMethods as $key => $classMethod) {
if (mb_substr($classMethod, 0, 1) === '_') {
unset($classMethods[$key]);
}
}
return $classMethods;
} | List all direct actions of a controller
@return array<string> Actions | listActions | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public function isPosted() {
return $this->controller->getRequest()->is(['post', 'put', 'patch']);
} | Convenience method to check on POSTED data.
Doesn't matter if it's POST, PUT or PATCH.
Note that you can also use request->is(array('post', 'put', 'patch') directly.
@return bool If it is of type POST/PUT/PATCH | isPosted | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public function getPassedParam($var, $default = null) {
$passed = $this->controller->getRequest()->getParam('pass');
return $passed[$var] ?? $default;
} | Used to get the value of a passed param.
@param mixed $var
@param mixed $default
@return mixed | getPassedParam | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public static function defaultUrlParams() {
$defaults = [
'plugin' => false,
'prefix' => false,
];
return $defaults;
} | Returns defaultUrlParams including configured prefixes.
Deprecated: Routing.prefixes config is not needed anymore as it is always
just "prefix" now.
@return array URL params | defaultUrlParams | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public function currentUrl($asString = false) {
$action = $this->controller->getRequest()->getParam('action');
$passed = (array)$this->controller->getRequest()->getParam('pass');
$url = [
'prefix' => $this->controller->getRequest()->getParam('prefix'),
'plugin' => $this->controller->getRequest()->getParam('plugin'),
'action' => $action,
'controller' => $this->controller->getRequest()->getParam('controller'),
];
$url = array_merge($passed, $url);
if ($asString === true) {
return Router::url($url);
}
return $url;
} | Returns current url (with all missing params automatically added).
Necessary for Router::url() and comparison of urls to work.
@param bool $asString Defaults to false = array
@return mixed URL | currentUrl | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public function autoRedirect($whereTo, $allowSelf = false, $status = 302) {
if ($allowSelf || $this->controller->referer(null) !== $this->controller->getRequest()->getRequestTarget()) {
return $this->controller->redirect($this->controller->referer($whereTo), $status);
}
return $this->controller->redirect($whereTo, $status);
} | Smart Referer Redirect - will try to use an existing referer first
otherwise it will use the default url
@param mixed $whereTo URL
@param bool $allowSelf if redirect to the same controller/action (url) is allowed
@param int $status
@return \Cake\Http\Response|null | autoRedirect | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public function postRedirect($whereTo, $status = 302) {
return $this->controller->redirect($whereTo, $status);
} | Should be a 303, but:
Note: Many pre-HTTP/1.1 user agents do not understand the 303 status. When interoperability with such clients is a concern, the 302 status code may be used instead, since most user agents react to a 302 response as described here for 303.
TODO: change to 303 with backwards-compatibility for older browsers...
@see http://en.wikipedia.org/wiki/Post/Redirect/Get
@param mixed $whereTo URL
@param int $status
@return \Cake\Http\Response|null | postRedirect | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public function completeRedirect($url = null, int $status = 302) {
if ($url === null) {
$url = [
'plugin' => $this->controller->getRequest()->getParam('plugin'),
'controller' => $this->controller->getRequest()->getParam('controller'),
'action' => $this->controller->getRequest()->getParam('action'),
'_ext' => $this->controller->getRequest()->getParam('_ext'),
];
}
if (is_array($url)) {
$url += $this->controller->getRequest()->getParam('pass');
}
return $this->controller->redirect($url, $status);
} | Automatically add missing URL parts of the current URL including
- querystring (especially for 3.x then)
- passed params
@param mixed|null $url
@param int $status
@return \Cake\Http\Response|null | completeRedirect | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public function forceCache($seconds = HOUR) {
$response = $this->controller->getResponse();
$response = $response->withHeader('Cache-Control', 'public, max-age=' . $seconds)
->withHeader('Last-modified', gmdate('D, j M Y H:i:s', time()) . ' GMT')
->withHeader('Expires', gmdate('D, j M Y H:i:s', time() + $seconds) . ' GMT');
$this->controller->setResponse($response);
} | Set headers to cache this request.
Opposite of Controller::disableCache()
@param int $seconds
@return void | forceCache | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public function isForeignReferer($ref = null) {
if ($ref === null) {
/** @var string|null $ref */
$ref = env('HTTP_REFERER');
}
if (!$ref) {
return false;
}
$base = Configure::read('App.fullBaseUrl') . '/';
if (mb_strpos($ref, $base) === 0) {
return false;
}
return true;
} | Referrer checking (where does the user come from)
Only returns true for a valid external referrer.
@param string|null $ref Referer
@return bool Success | isForeignReferer | php | dereuromark/cakephp-tools | src/Controller/Component/CommonComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/CommonComponent.php | MIT |
public function beforeFilter(EventInterface $event) {
if ($this->_config['on'] !== 'beforeFilter') {
return;
}
$this->_init();
} | @param \Cake\Event\EventInterface $event
@return void | beforeFilter | php | dereuromark/cakephp-tools | src/Controller/Component/MobileComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/MobileComponent.php | MIT |
protected function _init() {
$controller = $this->getController();
$mobileOverwrite = $controller->getRequest()->getQuery('mobile');
if ($mobileOverwrite !== null) {
if ($mobileOverwrite === '-1') {
$controller->getRequest()->getSession()->delete('User.mobile');
} else {
$wantsMobile = (bool)$mobileOverwrite;
$controller->getRequest()->getSession()->write('User.mobile', (int)$wantsMobile);
}
}
$this->isMobile();
if (!$this->_config['auto']) {
return;
}
$this->setMobile();
} | Main auto-detection logic including session based storage to avoid
multiple lookups.
Uses "mobile" query string to overwrite the auto-detection.
-1 clears the fixation
1 forces mobile
0 forces no-mobile
@return void | _init | php | dereuromark/cakephp-tools | src/Controller/Component/MobileComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/MobileComponent.php | MIT |
public function setMobile() {
if ($this->isMobile === null) {
$this->isMobile();
}
$forceMobile = $this->getController()->getRequest()->getSession()->read('User.mobile');
if ($forceMobile !== null && !$forceMobile) {
$this->setMobile = false;
} elseif ($forceMobile !== null || $this->isMobile()) {
$this->setMobile = true;
} else {
$this->setMobile = false;
}
$urlParams = $this->getController()->getRequest()->getAttribute('params');
if (!isset($urlParams['pass'])) {
$urlParams['pass'] = [];
}
$urlParams = array_merge($urlParams, $urlParams['pass']);
unset($urlParams['pass']);
if (isset($urlParams['prefix'])) {
unset($urlParams['prefix']);
}
if ($this->setMobile) {
$urlParams['?']['mobile'] = 0;
$url = Router::url($urlParams);
$this->getController()->set('desktopUrl', $url);
} else {
$urlParams['?']['mobile'] = 1;
$url = Router::url($urlParams);
$this->getController()->set('mobileUrl', $url);
}
Configure::write('User.setMobile', (int)$this->setMobile);
if (!$this->setMobile) {
return;
}
$this->getController()->viewBuilder()->setClassName('Theme');
$this->getController()->viewBuilder()->setTheme('Mobile');
} | Sets mobile views as `Mobile` theme.
Only needs to be called if auto is set to false.
Then you probably want to call this from your AppController::beforeRender().
@return void | setMobile | php | dereuromark/cakephp-tools | src/Controller/Component/MobileComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/MobileComponent.php | MIT |
public function isMobile() {
if ($this->isMobile !== null) {
return $this->isMobile;
}
$this->isMobile = Configure::read('User.isMobile');
if ($this->isMobile !== null) {
return $this->isMobile;
}
$this->isMobile = (bool)$this->detect();
Configure::write('User.isMobile', (int)$this->isMobile);
return $this->isMobile;
} | Determines if we need to so serve mobile views based on session preference
and browser headers.
@return bool Success | isMobile | php | dereuromark/cakephp-tools | src/Controller/Component/MobileComponent.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Component/MobileComponent.php | MIT |
public function index() {
$this->viewBuilder()->addHelper('Tools.Format');
} | @return \Cake\Http\Response|null|void | index | php | dereuromark/cakephp-tools | src/Controller/Admin/ToolsController.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Admin/ToolsController.php | MIT |
public function index() {
} | @return \Cake\Http\Response|null|void | index | php | dereuromark/cakephp-tools | src/Controller/Admin/IconsController.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Admin/IconsController.php | MIT |
protected function _bitmaskUpdateSnippet($from, $to, $modelClass, $fieldName) {
//[$class, $modelName] = pluginSplit($modelClass);
$Model = TableRegistry::getTableLocator()->get($modelClass);
$tableName = $Model->getTable(); // $dbo->fullTableName($Model);
$fieldName = '`' . $fieldName . '`';
$res = $fieldName;
$conditions = [];
$sql = [];
foreach ($from as $value) {
$conditions[] = $fieldName . ' & ' . $value . ' = ' . $value;
if (in_array($value, $to)) {
continue;
}
$res .= ' & ~' . $value;
}
$conditions = implode(' OR ', $conditions);
foreach ($to as $value) {
$res .= ' | ' . $value;
}
$sql[] = 'UPDATE ' . $tableName . ' SET ' . $fieldName . ' = ' . $res . ' WHERE ' . $conditions . ';';
return implode(PHP_EOL, $sql);
} | @param mixed $from
@param mixed $to
@param mixed $modelClass
@param mixed $fieldName
@return string | _bitmaskUpdateSnippet | php | dereuromark/cakephp-tools | src/Controller/Admin/HelperController.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Controller/Admin/HelperController.php | MIT |
public function __construct(array $config = []) {
$this->setConfig($config);
} | Constructor
@param array<string, mixed> $config Array of config. | __construct | php | dereuromark/cakephp-tools | src/Auth/AbstractPasswordHasher.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Auth/AbstractPasswordHasher.php | MIT |
public function getMailer($name, $config = null) {
$className = App::className($name, 'Mailer', 'Mailer');
if (!$className) {
throw new MissingMailerException(compact('name'));
}
return new $className($config);
} | Returns a mailer instance.
@param string $name Mailer's name.
@param array|null $config
@throws \Cake\Mailer\Exception\MissingMailerException if undefined mailer class.
@return \Cake\Mailer\Mailer | getMailer | php | dereuromark/cakephp-tools | src/Mailer/MailerAwareTrait.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/MailerAwareTrait.php | MIT |
public function __construct(?array $config = null) {
parent::__construct($config);
$xMailer = Configure::read('Config.xMailer');
if ($xMailer) {
$this->addHeaders(['X-Mailer' => $xMailer]);
}
$this->setDefaults();
} | @param array|null $config Array of configs, or string to load configs from app.php | __construct | php | dereuromark/cakephp-tools | src/Mailer/Message.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Message.php | MIT |
protected function _isEmbeddedAttachment($file, $name) {
foreach ($this->getAttachments() as $filename => $fileInfo) {
if ($filename !== $name) {
continue;
}
return $fileInfo['contentId'];
}
return false;
} | Returns if this particular file has already been attached as embedded file with this exact name
to prevent the same image to overwrite each other and also to only send this image once.
Allows multiple usage of the same embedded image (using the same cid)
@param string $file
@param string $name
@return string|false CID of the found file or false if no such attachment can be found | _isEmbeddedAttachment | php | dereuromark/cakephp-tools | src/Mailer/Message.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Message.php | MIT |
protected function _isEmbeddedBlobAttachment($content, $name) {
foreach ($this->getAttachments() as $filename => $fileInfo) {
if ($filename !== $name) {
continue;
}
return $fileInfo['contentId'];
}
return false;
} | Returns if this particular file has already been attached as embedded file with this exact name
to prevent the same image to overwrite each other and also to only send this image once.
Allows multiple usage of the same embedded image (using the same cid)
@param string $content
@param string $name
@return string|false CID of the found file or false if no such attachment can be found | _isEmbeddedBlobAttachment | php | dereuromark/cakephp-tools | src/Mailer/Message.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Message.php | MIT |
protected function _getMime($filename, $default = 'application/octet-stream') {
if ($this->_Mime === null) {
$this->_Mime = new Mime();
}
$mime = $this->_Mime->detectMimeType($filename);
// Some environments falsely return the default too fast, better fallback to extension here
if (!$mime || $mime === $default) {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
/** @var string|null $mime */
$mime = $this->_Mime->getMimeTypeByAlias($ext);
if ($mime === null) {
$mime = (string)$mime;
}
}
return $mime;
} | Try to find mimetype by file extension
@param string $filename File name
@param string $default default MimeType
@return string Mimetype (falls back to `application/octet-stream`) | _getMime | php | dereuromark/cakephp-tools | src/Mailer/Message.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Message.php | MIT |
public function __construct(array|string|null $config = null) {
if ($config === null && Configure::read('Config.live') === false) {
$config = 'test';
}
parent::__construct($config);
} | @param array|string|null $config Array of configs, or string to load configs from app.php | __construct | php | dereuromark/cakephp-tools | src/Mailer/Mailer.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Mailer.php | MIT |
public function __call(string $method, array $args) {
$result = $this->message->$method(...$args);
if (str_starts_with($method, 'get') || str_starts_with($method, 'add')) {
return $result;
}
return $this;
} | Magic method to forward method class to Message instance.
@param string $method Method name.
@param array $args Method arguments
@return \Cake\Mailer\Mailer|mixed | __call | php | dereuromark/cakephp-tools | src/Mailer/Mailer.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Mailer.php | MIT |
public function setLocale(string $locale) {
$this->locale = $locale;
return $this;
} | @param string $locale
@return $this | setLocale | php | dereuromark/cakephp-tools | src/Mailer/Mailer.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Mailer.php | MIT |
public function validates() {
if ($this->getMessage()->getSubject() && $this->getMessage()->getTo()) {
return true;
}
return false;
} | Validate if the email has the required fields necessary to make send() work.
Assumes layouting (does not check on content to be present or if view/layout files are missing).
@return bool Success | validates | php | dereuromark/cakephp-tools | src/Mailer/Mailer.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Mailer.php | MIT |
protected function fixateLocale() {
$this->localeBefore = I18n::getLocale();
if ($this->locale) {
I18n::setLocale($this->locale);
return;
}
$primaryLocale = $this->detectPrimaryLocale();
if ($primaryLocale) {
I18n::setLocale($primaryLocale);
}
} | Switch to primary locale if applicable.
@return void | fixateLocale | php | dereuromark/cakephp-tools | src/Mailer/Mailer.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Mailer.php | MIT |
protected function restoreLocale() {
assert($this->localeBefore !== null);
I18n::setLocale($this->localeBefore);
} | Restore to current locale if applicable.
@return void | restoreLocale | php | dereuromark/cakephp-tools | src/Mailer/Mailer.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Mailer.php | MIT |
public function reset() {
$this->locale = null;
$this->debug = [];
return parent::reset();
} | @return $this | reset | php | dereuromark/cakephp-tools | src/Mailer/Mailer.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Mailer.php | MIT |
public function execute(Arguments $args, ConsoleIo $io) {
if ($args->getArguments()) {
$arguments = $this->_parseArguments($args->getArguments(), $io);
} else {
$arguments = $this->_interactive($io);
}
if (!$arguments['action'] || !$arguments['word']) {
return static::CODE_SUCCESS;
}
$this->_inflect($arguments['action'], $arguments['word'], $io);
} | Implement this action 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 | execute | php | dereuromark/cakephp-tools | src/Command/InflectCommand.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Command/InflectCommand.php | MIT |
protected function _getAction(ConsoleIo $io) {
$validCharacters = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'a', 'q'];
$validCommands = array_merge($validCharacters, $this->validCommands);
$command = null;
while (empty($command)) {
$io->out('Please type the number or name of the inflection you would like to use');
$io->hr();
$io->out('[1] Pluralize');
$io->out('[2] Singularize');
$io->out('[3] Camelize');
$io->out('[4] Underscore');
$io->out('[5] Humanize');
$io->out('[6] Tableize');
$io->out('[7] Classify');
$io->out('[8] Variable');
$io->out('[9] Dasherize');
$io->out('[a] All');
$io->out('[q] Quit');
$answer = $io->ask('What action would you like to perform?', 'q');
if (in_array(strtolower($answer), $validCommands, true)) {
$command = strtolower($answer);
} else {
$io->out('Try again.');
}
}
switch ($command) {
case '1':
case 'pluralize':
return 'pluralize';
case '2':
case 'singularize':
return 'singularize';
case '3':
case 'camelize':
return 'camelize';
case '4':
case 'underscore':
return 'underscore';
case '5':
case 'humanize':
return 'humanize';
case '6':
case 'tableize':
return 'tableize';
case '7':
case 'classify':
return 'classify';
case '8':
case 'variable':
return 'variable';
case '9':
case 'dasherize':
return 'dasherize';
case 'a':
case 'all':
return 'all';
case 'q':
case 'quit':
default:
$this->abort(static::CODE_SUCCESS);
}
} | Requests a valid inflection action
@param \Cake\Console\ConsoleIo $io
@return string | _getAction | php | dereuromark/cakephp-tools | src/Command/InflectCommand.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Command/InflectCommand.php | MIT |
protected function _getWord(ConsoleIo $io) {
$word = null;
while (empty($word)) {
$temp = $io->ask('What word would you like to inflect?');
if (!empty($temp)) {
$word = $temp;
} else {
$io->out('Try again.');
}
}
return $word;
} | Requests word to inflect
@param \Cake\Console\ConsoleIo $io
@return string|null | _getWord | php | dereuromark/cakephp-tools | src/Command/InflectCommand.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Command/InflectCommand.php | MIT |
protected function _getMessage($function) {
$messages = [
'camelize' => 'CamelCase form ',
'camelBacked' => 'camelBacked form ',
'classify' => 'Cake Model Class form ',
'humanize' => 'Human Readable Group form ',
'singularize' => 'Singular form ',
'dasherize' => 'Dasherized-form ',
'pluralize' => 'Pluralized form ',
'tableize' => 'table_names form ',
'underscore' => 'under_scored_form ',
'variable' => 'variableForm ',
];
return $messages[$function] ?? null;
} | Returns the appropriate message for a given function
@param string $function
@return string|null | _getMessage | php | dereuromark/cakephp-tools | src/Command/InflectCommand.php | https://github.com/dereuromark/cakephp-tools/blob/master/src/Command/InflectCommand.php | MIT |
public function _customSluggerMethod($name) {
return mb_strtolower($name);
} | @param string $name
@return string | _customSluggerMethod | php | dereuromark/cakephp-tools | tests/TestCase/Model/Behavior/SluggedBehaviorTest.php | https://github.com/dereuromark/cakephp-tools/blob/master/tests/TestCase/Model/Behavior/SluggedBehaviorTest.php | MIT |
protected function _getEntity($title = null, $field = null, array $data = [], array $options = []) {
$options += ['validate' => false];
if ($title === null) {
$title = 'test 123';
}
if ($field === null) {
$field = 'title';
}
$data = [
$field => $title,
] + $data;
return new Entity($data, $options);
} | Get a new Entity
@param string|null $title
@param string|null $field
@param array $data
@param array<string, mixed> $options
@return \Cake\ORM\Entity | _getEntity | php | dereuromark/cakephp-tools | tests/TestCase/Model/Behavior/SluggedBehaviorTest.php | https://github.com/dereuromark/cakephp-tools/blob/master/tests/TestCase/Model/Behavior/SluggedBehaviorTest.php | MIT |
public function _testSlugger($name) {
return mb_strtolower($name);
} | @param string $name
@return string | _testSlugger | php | dereuromark/cakephp-tools | tests/TestCase/View/Helper/FormatHelperTest.php | https://github.com/dereuromark/cakephp-tools/blob/master/tests/TestCase/View/Helper/FormatHelperTest.php | MIT |
public static function char(array $characterSets = ['basic-latin'], $encoding = 'utf-8')
{
return CharacterGenerator::ascii();
} | Generates character in the ASCII 0-127 range.
@param array $characterSets Only supported charset: "basic-latin"
@param string $encoding Only supported encoding: "utf-8"
@return Generator\CharacterGenerator | char | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function charPrintableAscii()
{
return CharacterGenerator::printableAscii();
} | Generates character in the ASCII 32-127 range, excluding non-printable ones
or modifiers such as CR, LF and Tab.
@return Generator\CharacterGenerator | charPrintableAscii | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function choose($lowerLimit, $upperLimit)
{
return new ChooseGenerator($lowerLimit, $upperLimit);
} | Generates a number in the range from the lower bound to the upper bound,
inclusive. The result shrinks towards smaller absolute values.
The order of the parameters does not care since they are re-ordered by the
generator itself.
@param $x int One of the 2 boundaries of the range
@param $y int The other boundary of the range
@return Generator\ChooseGenerator | choose | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function constant($value)
{
return ConstantGenerator::box($value);
} | @param mixed $value the only value to generate
@return ConstantGenerator | constant | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function frequency(/*$frequencyAndGenerator, $frequencyAndGenerator, ...*/)
{
return new FrequencyGenerator(func_get_args());
} | @return FrequencyGenerator | frequency | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function int()
{
return new IntegerGenerator();
} | Generates a positive or negative integer (with absolute value bounded by
the generation size). | int | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function pos()
{
$mustBeStrictlyPositive = function ($n) {
return abs($n) + 1;
};
return new IntegerGenerator($mustBeStrictlyPositive);
} | Generates a positive integer (bounded by the generation size). | pos | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function neg()
{
$mustBeStrictlyNegative = function ($n) {
return (-1) * (abs($n) + 1);
};
return new IntegerGenerator($mustBeStrictlyNegative);
} | Generates a negative integer (bounded by the generation size). | neg | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function oneOf(...$_generators)
{
return new OneOfGenerator(func_get_args());
} | @return OneOfGenerator | oneOf | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function regex($expression)
{
return new RegexGenerator($expression);
} | Note * and + modifiers cause an unbounded number of character to be generated
(up to plus infinity) and as such they are not supported.
Please use {1,N} and {0,N} instead of + and *.
@param string $expression
@return Generator\RegexGenerator | regex | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function set($singleElementGenerator)
{
return new SetGenerator($singleElementGenerator);
} | @param Generator $singleElementGenerator
@return SetGenerator | set | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function subset($input)
{
return new SubsetGenerator($input);
} | @param array $input
@return SubsetGenerator | subset | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function filter($filter, Generator $generator, $maximumAttempts = 100)
{
return self::suchThat($filter, $generator, $maximumAttempts);
} | @param callable|Constraint $filter
@return SuchThatGenerator | filter | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function suchThat($filter, Generator $generator, $maximumAttempts = 100)
{
return new SuchThatGenerator($filter, $generator, $maximumAttempts);
} | @param callable|Constraint $filter
@return SuchThatGenerator | suchThat | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
public static function tuple()
{
$arguments = func_get_args();
if (is_array($arguments[0])) {
$generators = $arguments[0];
} else {
$generators = $arguments;
}
return new TupleGenerator($generators);
} | One Generator for each member of the Tuple:
tuple(Generator, Generator, Generator...)
Or an array of generators:
tuple(array $generators)
@return Generator\TupleGenerator | tuple | php | giorgiosironi/eris | src/Generators.php | https://github.com/giorgiosironi/eris/blob/master/src/Generators.php | MIT |
protected function getTestCaseAttributes()
{
return array();
} | sadly this facade has no option to retrieve annotations of testcases
@return array | getTestCaseAttributes | php | giorgiosironi/eris | src/Facade.php | https://github.com/giorgiosironi/eris/blob/master/src/Facade.php | MIT |
public function erisSetup()
{
$this->seedingRandomNumberGeneration();
$this->listeners = array_filter(
$this->listeners,
function ($listener) {
return !($listener instanceof MinimumEvaluations);
}
);
$tags = $this->getTestCaseAttributes();
$this->withRand($this->getAttributeValue($tags, ErisMethod::class, 'rand', 'strval'));
$this->iterations = $this->getAttributeValue($tags, ErisRepeat::class, 100, 'intval');
$this->shrinkingTimeLimit = $this->getAttributeValue($tags, ErisShrink::class, null, 'intval');
$this->listeners[] = MinimumEvaluations::ratio($this->getAttributeValue($tags, ErisRatio::class, 50, 'floatval')/100);
$duration = $this->getAttributeValue($tags, ErisDuration::class, false, 'strval');
if ($duration) {
$this->limitTo(new DateInterval($duration));
}
} | [Before] | erisSetup | php | giorgiosironi/eris | src/TestTrait.php | https://github.com/giorgiosironi/eris/blob/master/src/TestTrait.php | MIT |
private function seedingRandomNumberGeneration()
{
$seed = intval(getenv('ERIS_SEED') ?: (microtime(true)*1000000));
if ($seed < 0) {
$seed *= -1;
}
$this->seed = $seed;
} | @internal
@return void | seedingRandomNumberGeneration | php | giorgiosironi/eris | src/TestTrait.php | https://github.com/giorgiosironi/eris/blob/master/src/TestTrait.php | MIT |
private function getAttributeValue(array $attributes, $key, $default, $cast)
{
$attribute = $this->getAttribute($attributes, $key);
return $attribute !== null ? $cast($attribute) : $default;
} | @param array $attributes
@param string $key
@param mixed $default
@return mixed | getAttributeValue | php | giorgiosironi/eris | src/TestTrait.php | https://github.com/giorgiosironi/eris/blob/master/src/TestTrait.php | MIT |
private function getAttribute(array $attributes, $key)
{
if (isset($attributes['method'][$key])) {
return ($attributes['method'][$key])->getValue();
}
return isset($attributes['class'][$key]) ? ($attributes['class'][$key])->getValue() : null;
} | @param array $attributes
@param string $key
@return int|string|null | getAttribute | php | giorgiosironi/eris | src/TestTrait.php | https://github.com/giorgiosironi/eris/blob/master/src/TestTrait.php | MIT |
protected function minimumEvaluationRatio($ratio)
{
$this->filterOutListenersOfClass('Eris\\Listener\\MinimumEvaluations');
$this->listeners[] = MinimumEvaluations::ratio($ratio);
return $this;
} | @param float from 0.0 to 1.0
@return self | minimumEvaluationRatio | php | giorgiosironi/eris | src/TestTrait.php | https://github.com/giorgiosironi/eris/blob/master/src/TestTrait.php | MIT |
protected function limitTo($limit)
{
if ($limit instanceof DateInterval) {
$interval = $limit;
$terminationCondition = new TimeBasedTerminationCondition('time', $interval);
$this->listeners[] = $terminationCondition;
$this->terminationConditions[] = $terminationCondition;
} elseif (is_integer($limit)) {
$this->iterations = $limit;
} else {
throw new \InvalidArgumentException("The limit " . var_export($limit, true) . " is not valid. Please pass an integer or DateInterval.");
}
return $this;
} | @param integer|DateInterval $limit
@return self | limitTo | php | giorgiosironi/eris | src/TestTrait.php | https://github.com/giorgiosironi/eris/blob/master/src/TestTrait.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.