id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
211,200
cakephp/cakephp
src/Validation/Validation.php
Validation.fileSize
public static function fileSize($check, $operator = null, $size = null) { $file = static::getFilename($check); if ($file === false) { return false; } if (is_string($size)) { $size = Text::parseFileSize($size); } $filesize = filesize($file); return static::comparison($filesize, $operator, $size); }
php
public static function fileSize($check, $operator = null, $size = null) { $file = static::getFilename($check); if ($file === false) { return false; } if (is_string($size)) { $size = Text::parseFileSize($size); } $filesize = filesize($file); return static::comparison($filesize, $operator, $size); }
[ "public", "static", "function", "fileSize", "(", "$", "check", ",", "$", "operator", "=", "null", ",", "$", "size", "=", "null", ")", "{", "$", "file", "=", "static", "::", "getFilename", "(", "$", "check", ")", ";", "if", "(", "$", "file", "===", "false", ")", "{", "return", "false", ";", "}", "if", "(", "is_string", "(", "$", "size", ")", ")", "{", "$", "size", "=", "Text", "::", "parseFileSize", "(", "$", "size", ")", ";", "}", "$", "filesize", "=", "filesize", "(", "$", "file", ")", ";", "return", "static", "::", "comparison", "(", "$", "filesize", ",", "$", "operator", ",", "$", "size", ")", ";", "}" ]
Checks the filesize Will check the filesize of files/UploadedFileInterface instances by checking the filesize() on disk and not relying on the length reported by the client. @param string|array|\Psr\Http\Message\UploadedFileInterface $check Value to check. @param string|null $operator See `Validation::comparison()`. @param int|string|null $size Size in bytes or human readable string like '5MB'. @return bool Success
[ "Checks", "the", "filesize" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1232-L1245
211,201
cakephp/cakephp
src/Validation/Validation.php
Validation.uploadError
public static function uploadError($check, $allowNoFile = false) { if ($check instanceof UploadedFileInterface) { $code = $check->getError(); } elseif (is_array($check) && isset($check['error'])) { $code = $check['error']; } else { $code = $check; } if ($allowNoFile) { return in_array((int)$code, [UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE], true); } return (int)$code === UPLOAD_ERR_OK; }
php
public static function uploadError($check, $allowNoFile = false) { if ($check instanceof UploadedFileInterface) { $code = $check->getError(); } elseif (is_array($check) && isset($check['error'])) { $code = $check['error']; } else { $code = $check; } if ($allowNoFile) { return in_array((int)$code, [UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE], true); } return (int)$code === UPLOAD_ERR_OK; }
[ "public", "static", "function", "uploadError", "(", "$", "check", ",", "$", "allowNoFile", "=", "false", ")", "{", "if", "(", "$", "check", "instanceof", "UploadedFileInterface", ")", "{", "$", "code", "=", "$", "check", "->", "getError", "(", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "check", ")", "&&", "isset", "(", "$", "check", "[", "'error'", "]", ")", ")", "{", "$", "code", "=", "$", "check", "[", "'error'", "]", ";", "}", "else", "{", "$", "code", "=", "$", "check", ";", "}", "if", "(", "$", "allowNoFile", ")", "{", "return", "in_array", "(", "(", "int", ")", "$", "code", ",", "[", "UPLOAD_ERR_OK", ",", "UPLOAD_ERR_NO_FILE", "]", ",", "true", ")", ";", "}", "return", "(", "int", ")", "$", "code", "===", "UPLOAD_ERR_OK", ";", "}" ]
Checking for upload errors @param string|array|\Psr\Http\Message\UploadedFileInterface $check Value to check. @param bool $allowNoFile Set to true to allow UPLOAD_ERR_NO_FILE as a pass. @return bool @see https://secure.php.net/manual/en/features.file-upload.errors.php
[ "Checking", "for", "upload", "errors" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1255-L1269
211,202
cakephp/cakephp
src/Validation/Validation.php
Validation.uploadedFile
public static function uploadedFile($file, array $options = []) { $options += [ 'minSize' => null, 'maxSize' => null, 'types' => null, 'optional' => false, ]; if (!is_array($file) && !($file instanceof UploadedFileInterface)) { return false; } $error = $isUploaded = false; if ($file instanceof UploadedFileInterface) { $error = $file->getError(); $isUploaded = true; } if (is_array($file)) { $keys = ['error', 'name', 'size', 'tmp_name', 'type']; ksort($file); if (array_keys($file) != $keys) { return false; } $error = (int)$file['error']; $isUploaded = is_uploaded_file($file['tmp_name']); } if (!static::uploadError($file, $options['optional'])) { return false; } if ($options['optional'] && $error === UPLOAD_ERR_NO_FILE) { return true; } if (isset($options['minSize']) && !static::fileSize($file, static::COMPARE_GREATER_OR_EQUAL, $options['minSize'])) { return false; } if (isset($options['maxSize']) && !static::fileSize($file, static::COMPARE_LESS_OR_EQUAL, $options['maxSize'])) { return false; } if (isset($options['types']) && !static::mimeType($file, $options['types'])) { return false; } return $isUploaded; }
php
public static function uploadedFile($file, array $options = []) { $options += [ 'minSize' => null, 'maxSize' => null, 'types' => null, 'optional' => false, ]; if (!is_array($file) && !($file instanceof UploadedFileInterface)) { return false; } $error = $isUploaded = false; if ($file instanceof UploadedFileInterface) { $error = $file->getError(); $isUploaded = true; } if (is_array($file)) { $keys = ['error', 'name', 'size', 'tmp_name', 'type']; ksort($file); if (array_keys($file) != $keys) { return false; } $error = (int)$file['error']; $isUploaded = is_uploaded_file($file['tmp_name']); } if (!static::uploadError($file, $options['optional'])) { return false; } if ($options['optional'] && $error === UPLOAD_ERR_NO_FILE) { return true; } if (isset($options['minSize']) && !static::fileSize($file, static::COMPARE_GREATER_OR_EQUAL, $options['minSize'])) { return false; } if (isset($options['maxSize']) && !static::fileSize($file, static::COMPARE_LESS_OR_EQUAL, $options['maxSize'])) { return false; } if (isset($options['types']) && !static::mimeType($file, $options['types'])) { return false; } return $isUploaded; }
[ "public", "static", "function", "uploadedFile", "(", "$", "file", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "+=", "[", "'minSize'", "=>", "null", ",", "'maxSize'", "=>", "null", ",", "'types'", "=>", "null", ",", "'optional'", "=>", "false", ",", "]", ";", "if", "(", "!", "is_array", "(", "$", "file", ")", "&&", "!", "(", "$", "file", "instanceof", "UploadedFileInterface", ")", ")", "{", "return", "false", ";", "}", "$", "error", "=", "$", "isUploaded", "=", "false", ";", "if", "(", "$", "file", "instanceof", "UploadedFileInterface", ")", "{", "$", "error", "=", "$", "file", "->", "getError", "(", ")", ";", "$", "isUploaded", "=", "true", ";", "}", "if", "(", "is_array", "(", "$", "file", ")", ")", "{", "$", "keys", "=", "[", "'error'", ",", "'name'", ",", "'size'", ",", "'tmp_name'", ",", "'type'", "]", ";", "ksort", "(", "$", "file", ")", ";", "if", "(", "array_keys", "(", "$", "file", ")", "!=", "$", "keys", ")", "{", "return", "false", ";", "}", "$", "error", "=", "(", "int", ")", "$", "file", "[", "'error'", "]", ";", "$", "isUploaded", "=", "is_uploaded_file", "(", "$", "file", "[", "'tmp_name'", "]", ")", ";", "}", "if", "(", "!", "static", "::", "uploadError", "(", "$", "file", ",", "$", "options", "[", "'optional'", "]", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "options", "[", "'optional'", "]", "&&", "$", "error", "===", "UPLOAD_ERR_NO_FILE", ")", "{", "return", "true", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'minSize'", "]", ")", "&&", "!", "static", "::", "fileSize", "(", "$", "file", ",", "static", "::", "COMPARE_GREATER_OR_EQUAL", ",", "$", "options", "[", "'minSize'", "]", ")", ")", "{", "return", "false", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'maxSize'", "]", ")", "&&", "!", "static", "::", "fileSize", "(", "$", "file", ",", "static", "::", "COMPARE_LESS_OR_EQUAL", ",", "$", "options", "[", "'maxSize'", "]", ")", ")", "{", "return", "false", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'types'", "]", ")", "&&", "!", "static", "::", "mimeType", "(", "$", "file", ",", "$", "options", "[", "'types'", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", "isUploaded", ";", "}" ]
Validate an uploaded file. Helps join `uploadError`, `fileSize` and `mimeType` into one higher level validation method. ### Options - `types` - An array of valid mime types. If empty all types will be accepted. The `type` will not be looked at, instead the file type will be checked with ext/finfo. - `minSize` - The minimum file size in bytes. Defaults to not checking. - `maxSize` - The maximum file size in bytes. Defaults to not checking. - `optional` - Whether or not this file is optional. Defaults to false. If true a missing file will pass the validator regardless of other constraints. @param array|\Psr\Http\Message\UploadedFileInterface $file The uploaded file data from PHP. @param array $options An array of options for the validation. @return bool
[ "Validate", "an", "uploaded", "file", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1291-L1334
211,203
cakephp/cakephp
src/Validation/Validation.php
Validation.imageSize
public static function imageSize($file, $options) { if (!isset($options['height']) && !isset($options['width'])) { throw new InvalidArgumentException('Invalid image size validation parameters! Missing `width` and / or `height`.'); } $filename = static::getFilename($file); list($width, $height) = getimagesize($filename); $validHeight = $validWidth = null; if (isset($options['height'])) { $validHeight = self::comparison($height, $options['height'][0], $options['height'][1]); } if (isset($options['width'])) { $validWidth = self::comparison($width, $options['width'][0], $options['width'][1]); } if ($validHeight !== null && $validWidth !== null) { return ($validHeight && $validWidth); } if ($validHeight !== null) { return $validHeight; } if ($validWidth !== null) { return $validWidth; } throw new InvalidArgumentException('The 2nd argument is missing the `width` and / or `height` options.'); }
php
public static function imageSize($file, $options) { if (!isset($options['height']) && !isset($options['width'])) { throw new InvalidArgumentException('Invalid image size validation parameters! Missing `width` and / or `height`.'); } $filename = static::getFilename($file); list($width, $height) = getimagesize($filename); $validHeight = $validWidth = null; if (isset($options['height'])) { $validHeight = self::comparison($height, $options['height'][0], $options['height'][1]); } if (isset($options['width'])) { $validWidth = self::comparison($width, $options['width'][0], $options['width'][1]); } if ($validHeight !== null && $validWidth !== null) { return ($validHeight && $validWidth); } if ($validHeight !== null) { return $validHeight; } if ($validWidth !== null) { return $validWidth; } throw new InvalidArgumentException('The 2nd argument is missing the `width` and / or `height` options.'); }
[ "public", "static", "function", "imageSize", "(", "$", "file", ",", "$", "options", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'height'", "]", ")", "&&", "!", "isset", "(", "$", "options", "[", "'width'", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid image size validation parameters! Missing `width` and / or `height`.'", ")", ";", "}", "$", "filename", "=", "static", "::", "getFilename", "(", "$", "file", ")", ";", "list", "(", "$", "width", ",", "$", "height", ")", "=", "getimagesize", "(", "$", "filename", ")", ";", "$", "validHeight", "=", "$", "validWidth", "=", "null", ";", "if", "(", "isset", "(", "$", "options", "[", "'height'", "]", ")", ")", "{", "$", "validHeight", "=", "self", "::", "comparison", "(", "$", "height", ",", "$", "options", "[", "'height'", "]", "[", "0", "]", ",", "$", "options", "[", "'height'", "]", "[", "1", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'width'", "]", ")", ")", "{", "$", "validWidth", "=", "self", "::", "comparison", "(", "$", "width", ",", "$", "options", "[", "'width'", "]", "[", "0", "]", ",", "$", "options", "[", "'width'", "]", "[", "1", "]", ")", ";", "}", "if", "(", "$", "validHeight", "!==", "null", "&&", "$", "validWidth", "!==", "null", ")", "{", "return", "(", "$", "validHeight", "&&", "$", "validWidth", ")", ";", "}", "if", "(", "$", "validHeight", "!==", "null", ")", "{", "return", "$", "validHeight", ";", "}", "if", "(", "$", "validWidth", "!==", "null", ")", "{", "return", "$", "validWidth", ";", "}", "throw", "new", "InvalidArgumentException", "(", "'The 2nd argument is missing the `width` and / or `height` options.'", ")", ";", "}" ]
Validates the size of an uploaded image. @param array|\Psr\Http\Message\UploadedFileInterface $file The uploaded file data from PHP. @param array $options Options to validate width and height. @return bool @throws \InvalidArgumentException
[ "Validates", "the", "size", "of", "an", "uploaded", "image", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1344-L1373
211,204
cakephp/cakephp
src/Validation/Validation.php
Validation.geoCoordinate
public static function geoCoordinate($value, array $options = []) { $options += [ 'format' => 'both', 'type' => 'latLong' ]; if ($options['type'] !== 'latLong') { throw new RuntimeException(sprintf( 'Unsupported coordinate type "%s". Use "latLong" instead.', $options['type'] )); } $pattern = '/^' . self::$_pattern['latitude'] . ',\s*' . self::$_pattern['longitude'] . '$/'; if ($options['format'] === 'long') { $pattern = '/^' . self::$_pattern['longitude'] . '$/'; } if ($options['format'] === 'lat') { $pattern = '/^' . self::$_pattern['latitude'] . '$/'; } return (bool)preg_match($pattern, $value); }
php
public static function geoCoordinate($value, array $options = []) { $options += [ 'format' => 'both', 'type' => 'latLong' ]; if ($options['type'] !== 'latLong') { throw new RuntimeException(sprintf( 'Unsupported coordinate type "%s". Use "latLong" instead.', $options['type'] )); } $pattern = '/^' . self::$_pattern['latitude'] . ',\s*' . self::$_pattern['longitude'] . '$/'; if ($options['format'] === 'long') { $pattern = '/^' . self::$_pattern['longitude'] . '$/'; } if ($options['format'] === 'lat') { $pattern = '/^' . self::$_pattern['latitude'] . '$/'; } return (bool)preg_match($pattern, $value); }
[ "public", "static", "function", "geoCoordinate", "(", "$", "value", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "+=", "[", "'format'", "=>", "'both'", ",", "'type'", "=>", "'latLong'", "]", ";", "if", "(", "$", "options", "[", "'type'", "]", "!==", "'latLong'", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Unsupported coordinate type \"%s\". Use \"latLong\" instead.'", ",", "$", "options", "[", "'type'", "]", ")", ")", ";", "}", "$", "pattern", "=", "'/^'", ".", "self", "::", "$", "_pattern", "[", "'latitude'", "]", ".", "',\\s*'", ".", "self", "::", "$", "_pattern", "[", "'longitude'", "]", ".", "'$/'", ";", "if", "(", "$", "options", "[", "'format'", "]", "===", "'long'", ")", "{", "$", "pattern", "=", "'/^'", ".", "self", "::", "$", "_pattern", "[", "'longitude'", "]", ".", "'$/'", ";", "}", "if", "(", "$", "options", "[", "'format'", "]", "===", "'lat'", ")", "{", "$", "pattern", "=", "'/^'", ".", "self", "::", "$", "_pattern", "[", "'latitude'", "]", ".", "'$/'", ";", "}", "return", "(", "bool", ")", "preg_match", "(", "$", "pattern", ",", "$", "value", ")", ";", "}" ]
Validates a geographic coordinate. Supported formats: - `<latitude>, <longitude>` Example: `-25.274398, 133.775136` ### Options - `type` - A string of the coordinate format, right now only `latLong`. - `format` - By default `both`, can be `long` and `lat` as well to validate only a part of the coordinate. @param string $value Geographic location as string @param array $options Options for the validation logic. @return bool
[ "Validates", "a", "geographic", "coordinate", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1428-L1449
211,205
cakephp/cakephp
src/Validation/Validation.php
Validation.utf8
public static function utf8($value, array $options = []) { if (!is_string($value)) { return false; } $options += ['extended' => false]; if ($options['extended']) { return true; } return preg_match('/[\x{10000}-\x{10FFFF}]/u', $value) === 0; }
php
public static function utf8($value, array $options = []) { if (!is_string($value)) { return false; } $options += ['extended' => false]; if ($options['extended']) { return true; } return preg_match('/[\x{10000}-\x{10FFFF}]/u', $value) === 0; }
[ "public", "static", "function", "utf8", "(", "$", "value", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "$", "options", "+=", "[", "'extended'", "=>", "false", "]", ";", "if", "(", "$", "options", "[", "'extended'", "]", ")", "{", "return", "true", ";", "}", "return", "preg_match", "(", "'/[\\x{10000}-\\x{10FFFF}]/u'", ",", "$", "value", ")", "===", "0", ";", "}" ]
Check that the input value is a utf8 string. This method will reject all non-string values. # Options - `extended` - Disallow bytes higher within the basic multilingual plane. MySQL's older utf8 encoding type does not allow characters above the basic multilingual plane. Defaults to false. @param string $value The value to check @param array $options An array of options. See above for the supported options. @return bool
[ "Check", "that", "the", "input", "value", "is", "a", "utf8", "string", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1515-L1526
211,206
cakephp/cakephp
src/Validation/Validation.php
Validation.isInteger
public static function isInteger($value) { if (!is_scalar($value) || is_float($value)) { return false; } if (is_int($value)) { return true; } return (bool)preg_match('/^-?[0-9]+$/', $value); }
php
public static function isInteger($value) { if (!is_scalar($value) || is_float($value)) { return false; } if (is_int($value)) { return true; } return (bool)preg_match('/^-?[0-9]+$/', $value); }
[ "public", "static", "function", "isInteger", "(", "$", "value", ")", "{", "if", "(", "!", "is_scalar", "(", "$", "value", ")", "||", "is_float", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "if", "(", "is_int", "(", "$", "value", ")", ")", "{", "return", "true", ";", "}", "return", "(", "bool", ")", "preg_match", "(", "'/^-?[0-9]+$/'", ",", "$", "value", ")", ";", "}" ]
Check that the input value is an integer This method will accept strings that contain only integer data as well. @param string $value The value to check @return bool
[ "Check", "that", "the", "input", "value", "is", "an", "integer" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1537-L1547
211,207
cakephp/cakephp
src/Validation/Validation.php
Validation.iban
public static function iban($check) { if (!preg_match('/^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$/', $check)) { return false; } $country = substr($check, 0, 2); $checkInt = intval(substr($check, 2, 2)); $account = substr($check, 4); $search = range('A', 'Z'); $replace = []; foreach (range(10, 35) as $tmp) { $replace[] = strval($tmp); } $numStr = str_replace($search, $replace, $account . $country . '00'); $checksum = intval(substr($numStr, 0, 1)); $numStrLength = strlen($numStr); for ($pos = 1; $pos < $numStrLength; $pos++) { $checksum *= 10; $checksum += intval(substr($numStr, $pos, 1)); $checksum %= 97; } return ((98 - $checksum) === $checkInt); }
php
public static function iban($check) { if (!preg_match('/^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$/', $check)) { return false; } $country = substr($check, 0, 2); $checkInt = intval(substr($check, 2, 2)); $account = substr($check, 4); $search = range('A', 'Z'); $replace = []; foreach (range(10, 35) as $tmp) { $replace[] = strval($tmp); } $numStr = str_replace($search, $replace, $account . $country . '00'); $checksum = intval(substr($numStr, 0, 1)); $numStrLength = strlen($numStr); for ($pos = 1; $pos < $numStrLength; $pos++) { $checksum *= 10; $checksum += intval(substr($numStr, $pos, 1)); $checksum %= 97; } return ((98 - $checksum) === $checkInt); }
[ "public", "static", "function", "iban", "(", "$", "check", ")", "{", "if", "(", "!", "preg_match", "(", "'/^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$/'", ",", "$", "check", ")", ")", "{", "return", "false", ";", "}", "$", "country", "=", "substr", "(", "$", "check", ",", "0", ",", "2", ")", ";", "$", "checkInt", "=", "intval", "(", "substr", "(", "$", "check", ",", "2", ",", "2", ")", ")", ";", "$", "account", "=", "substr", "(", "$", "check", ",", "4", ")", ";", "$", "search", "=", "range", "(", "'A'", ",", "'Z'", ")", ";", "$", "replace", "=", "[", "]", ";", "foreach", "(", "range", "(", "10", ",", "35", ")", "as", "$", "tmp", ")", "{", "$", "replace", "[", "]", "=", "strval", "(", "$", "tmp", ")", ";", "}", "$", "numStr", "=", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "account", ".", "$", "country", ".", "'00'", ")", ";", "$", "checksum", "=", "intval", "(", "substr", "(", "$", "numStr", ",", "0", ",", "1", ")", ")", ";", "$", "numStrLength", "=", "strlen", "(", "$", "numStr", ")", ";", "for", "(", "$", "pos", "=", "1", ";", "$", "pos", "<", "$", "numStrLength", ";", "$", "pos", "++", ")", "{", "$", "checksum", "*=", "10", ";", "$", "checksum", "+=", "intval", "(", "substr", "(", "$", "numStr", ",", "$", "pos", ",", "1", ")", ")", ";", "$", "checksum", "%=", "97", ";", "}", "return", "(", "(", "98", "-", "$", "checksum", ")", "===", "$", "checkInt", ")", ";", "}" ]
Check that the input value has a valid International Bank Account Number IBAN syntax Requirements are uppercase, no whitespaces, max length 34, country code and checksum exist at right spots, body matches against checksum via Mod97-10 algorithm @param string $check The value to check @return bool Success
[ "Check", "that", "the", "input", "value", "has", "a", "valid", "International", "Bank", "Account", "Number", "IBAN", "syntax", "Requirements", "are", "uppercase", "no", "whitespaces", "max", "length", "34", "country", "code", "and", "checksum", "exist", "at", "right", "spots", "body", "matches", "against", "checksum", "via", "Mod97", "-", "10", "algorithm" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1594-L1618
211,208
cakephp/cakephp
src/Validation/Validation.php
Validation._getDateString
protected static function _getDateString($value) { $formatted = ''; if (isset($value['year'], $value['month'], $value['day']) && (is_numeric($value['year']) && is_numeric($value['month']) && is_numeric($value['day'])) ) { $formatted .= sprintf('%d-%02d-%02d ', $value['year'], $value['month'], $value['day']); } if (isset($value['hour'])) { if (isset($value['meridian']) && (int)$value['hour'] === 12) { $value['hour'] = 0; } if (isset($value['meridian'])) { $value['hour'] = strtolower($value['meridian']) === 'am' ? $value['hour'] : $value['hour'] + 12; } $value += ['minute' => 0, 'second' => 0]; if (is_numeric($value['hour']) && is_numeric($value['minute']) && is_numeric($value['second'])) { $formatted .= sprintf('%02d:%02d:%02d', $value['hour'], $value['minute'], $value['second']); } } return trim($formatted); }
php
protected static function _getDateString($value) { $formatted = ''; if (isset($value['year'], $value['month'], $value['day']) && (is_numeric($value['year']) && is_numeric($value['month']) && is_numeric($value['day'])) ) { $formatted .= sprintf('%d-%02d-%02d ', $value['year'], $value['month'], $value['day']); } if (isset($value['hour'])) { if (isset($value['meridian']) && (int)$value['hour'] === 12) { $value['hour'] = 0; } if (isset($value['meridian'])) { $value['hour'] = strtolower($value['meridian']) === 'am' ? $value['hour'] : $value['hour'] + 12; } $value += ['minute' => 0, 'second' => 0]; if (is_numeric($value['hour']) && is_numeric($value['minute']) && is_numeric($value['second'])) { $formatted .= sprintf('%02d:%02d:%02d', $value['hour'], $value['minute'], $value['second']); } } return trim($formatted); }
[ "protected", "static", "function", "_getDateString", "(", "$", "value", ")", "{", "$", "formatted", "=", "''", ";", "if", "(", "isset", "(", "$", "value", "[", "'year'", "]", ",", "$", "value", "[", "'month'", "]", ",", "$", "value", "[", "'day'", "]", ")", "&&", "(", "is_numeric", "(", "$", "value", "[", "'year'", "]", ")", "&&", "is_numeric", "(", "$", "value", "[", "'month'", "]", ")", "&&", "is_numeric", "(", "$", "value", "[", "'day'", "]", ")", ")", ")", "{", "$", "formatted", ".=", "sprintf", "(", "'%d-%02d-%02d '", ",", "$", "value", "[", "'year'", "]", ",", "$", "value", "[", "'month'", "]", ",", "$", "value", "[", "'day'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "value", "[", "'hour'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "value", "[", "'meridian'", "]", ")", "&&", "(", "int", ")", "$", "value", "[", "'hour'", "]", "===", "12", ")", "{", "$", "value", "[", "'hour'", "]", "=", "0", ";", "}", "if", "(", "isset", "(", "$", "value", "[", "'meridian'", "]", ")", ")", "{", "$", "value", "[", "'hour'", "]", "=", "strtolower", "(", "$", "value", "[", "'meridian'", "]", ")", "===", "'am'", "?", "$", "value", "[", "'hour'", "]", ":", "$", "value", "[", "'hour'", "]", "+", "12", ";", "}", "$", "value", "+=", "[", "'minute'", "=>", "0", ",", "'second'", "=>", "0", "]", ";", "if", "(", "is_numeric", "(", "$", "value", "[", "'hour'", "]", ")", "&&", "is_numeric", "(", "$", "value", "[", "'minute'", "]", ")", "&&", "is_numeric", "(", "$", "value", "[", "'second'", "]", ")", ")", "{", "$", "formatted", ".=", "sprintf", "(", "'%02d:%02d:%02d'", ",", "$", "value", "[", "'hour'", "]", ",", "$", "value", "[", "'minute'", "]", ",", "$", "value", "[", "'second'", "]", ")", ";", "}", "}", "return", "trim", "(", "$", "formatted", ")", ";", "}" ]
Converts an array representing a date or datetime into a ISO string. The arrays are typically sent for validation from a form generated by the CakePHP FormHelper. @param array $value The array representing a date or datetime. @return string
[ "Converts", "an", "array", "representing", "a", "date", "or", "datetime", "into", "a", "ISO", "string", ".", "The", "arrays", "are", "typically", "sent", "for", "validation", "from", "a", "form", "generated", "by", "the", "CakePHP", "FormHelper", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1628-L1651
211,209
cakephp/cakephp
src/Validation/Validation.php
Validation._populateIp
protected static function _populateIp() { if (!isset(static::$_pattern['IPv6'])) { $pattern = '((([0-9A-Fa-f]{1,4}:){7}(([0-9A-Fa-f]{1,4})|:))|(([0-9A-Fa-f]{1,4}:){6}'; $pattern .= '(:|((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})'; $pattern .= '|(:[0-9A-Fa-f]{1,4})))|(([0-9A-Fa-f]{1,4}:){5}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})'; $pattern .= '(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:)'; $pattern .= '{4}(:[0-9A-Fa-f]{1,4}){0,1}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2}))'; $pattern .= '{3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){3}(:[0-9A-Fa-f]{1,4}){0,2}'; $pattern .= '((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|'; $pattern .= '((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){2}(:[0-9A-Fa-f]{1,4}){0,3}'; $pattern .= '((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2}))'; $pattern .= '{3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:)(:[0-9A-Fa-f]{1,4})'; $pattern .= '{0,4}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)'; $pattern .= '|((:[0-9A-Fa-f]{1,4}){1,2})))|(:(:[0-9A-Fa-f]{1,4}){0,5}((:((25[0-5]|2[0-4]'; $pattern .= '\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4})'; $pattern .= '{1,2})))|(((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})))(%.+)?'; static::$_pattern['IPv6'] = $pattern; } if (!isset(static::$_pattern['IPv4'])) { $pattern = '(?:(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])'; static::$_pattern['IPv4'] = $pattern; } }
php
protected static function _populateIp() { if (!isset(static::$_pattern['IPv6'])) { $pattern = '((([0-9A-Fa-f]{1,4}:){7}(([0-9A-Fa-f]{1,4})|:))|(([0-9A-Fa-f]{1,4}:){6}'; $pattern .= '(:|((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})'; $pattern .= '|(:[0-9A-Fa-f]{1,4})))|(([0-9A-Fa-f]{1,4}:){5}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})'; $pattern .= '(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:)'; $pattern .= '{4}(:[0-9A-Fa-f]{1,4}){0,1}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2}))'; $pattern .= '{3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){3}(:[0-9A-Fa-f]{1,4}){0,2}'; $pattern .= '((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|'; $pattern .= '((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){2}(:[0-9A-Fa-f]{1,4}){0,3}'; $pattern .= '((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2}))'; $pattern .= '{3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:)(:[0-9A-Fa-f]{1,4})'; $pattern .= '{0,4}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)'; $pattern .= '|((:[0-9A-Fa-f]{1,4}){1,2})))|(:(:[0-9A-Fa-f]{1,4}){0,5}((:((25[0-5]|2[0-4]'; $pattern .= '\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4})'; $pattern .= '{1,2})))|(((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})))(%.+)?'; static::$_pattern['IPv6'] = $pattern; } if (!isset(static::$_pattern['IPv4'])) { $pattern = '(?:(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])'; static::$_pattern['IPv4'] = $pattern; } }
[ "protected", "static", "function", "_populateIp", "(", ")", "{", "if", "(", "!", "isset", "(", "static", "::", "$", "_pattern", "[", "'IPv6'", "]", ")", ")", "{", "$", "pattern", "=", "'((([0-9A-Fa-f]{1,4}:){7}(([0-9A-Fa-f]{1,4})|:))|(([0-9A-Fa-f]{1,4}:){6}'", ";", "$", "pattern", ".=", "'(:|((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})'", ";", "$", "pattern", ".=", "'|(:[0-9A-Fa-f]{1,4})))|(([0-9A-Fa-f]{1,4}:){5}((:((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})'", ";", "$", "pattern", ".=", "'(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:)'", ";", "$", "pattern", ".=", "'{4}(:[0-9A-Fa-f]{1,4}){0,1}((:((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2}))'", ";", "$", "pattern", ".=", "'{3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){3}(:[0-9A-Fa-f]{1,4}){0,2}'", ";", "$", "pattern", ".=", "'((:((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})?)|'", ";", "$", "pattern", ".=", "'((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){2}(:[0-9A-Fa-f]{1,4}){0,3}'", ";", "$", "pattern", ".=", "'((:((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2}))'", ";", "$", "pattern", ".=", "'{3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:)(:[0-9A-Fa-f]{1,4})'", ";", "$", "pattern", ".=", "'{0,4}((:((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})?)'", ";", "$", "pattern", ".=", "'|((:[0-9A-Fa-f]{1,4}){1,2})))|(:(:[0-9A-Fa-f]{1,4}){0,5}((:((25[0-5]|2[0-4]'", ";", "$", "pattern", ".=", "'\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4})'", ";", "$", "pattern", ".=", "'{1,2})))|(((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})))(%.+)?'", ";", "static", "::", "$", "_pattern", "[", "'IPv6'", "]", "=", "$", "pattern", ";", "}", "if", "(", "!", "isset", "(", "static", "::", "$", "_pattern", "[", "'IPv4'", "]", ")", ")", "{", "$", "pattern", "=", "'(?:(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])'", ";", "static", "::", "$", "_pattern", "[", "'IPv4'", "]", "=", "$", "pattern", ";", "}", "}" ]
Lazily populate the IP address patterns used for validations @return void
[ "Lazily", "populate", "the", "IP", "address", "patterns", "used", "for", "validations" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1658-L1682
211,210
cakephp/cakephp
src/Http/Client.php
Client.addCookie
public function addCookie(CookieInterface $cookie) { if (!$cookie->getDomain() || !$cookie->getPath()) { throw new InvalidArgumentException('Cookie must have a domain and a path set.'); } $this->_cookies = $this->_cookies->add($cookie); return $this; }
php
public function addCookie(CookieInterface $cookie) { if (!$cookie->getDomain() || !$cookie->getPath()) { throw new InvalidArgumentException('Cookie must have a domain and a path set.'); } $this->_cookies = $this->_cookies->add($cookie); return $this; }
[ "public", "function", "addCookie", "(", "CookieInterface", "$", "cookie", ")", "{", "if", "(", "!", "$", "cookie", "->", "getDomain", "(", ")", "||", "!", "$", "cookie", "->", "getPath", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Cookie must have a domain and a path set.'", ")", ";", "}", "$", "this", "->", "_cookies", "=", "$", "this", "->", "_cookies", "->", "add", "(", "$", "cookie", ")", ";", "return", "$", "this", ";", "}" ]
Adds a cookie to the Client collection. @param \Cake\Http\Cookie\CookieInterface $cookie Cookie object. @return $this
[ "Adds", "a", "cookie", "to", "the", "Client", "collection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L210-L218
211,211
cakephp/cakephp
src/Http/Client.php
Client.get
public function get($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $body = null; if (isset($data['_content'])) { $body = $data['_content']; unset($data['_content']); } $url = $this->buildUrl($url, $data, $options); return $this->_doRequest( Request::METHOD_GET, $url, $body, $options ); }
php
public function get($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $body = null; if (isset($data['_content'])) { $body = $data['_content']; unset($data['_content']); } $url = $this->buildUrl($url, $data, $options); return $this->_doRequest( Request::METHOD_GET, $url, $body, $options ); }
[ "public", "function", "get", "(", "$", "url", ",", "$", "data", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "_mergeOptions", "(", "$", "options", ")", ";", "$", "body", "=", "null", ";", "if", "(", "isset", "(", "$", "data", "[", "'_content'", "]", ")", ")", "{", "$", "body", "=", "$", "data", "[", "'_content'", "]", ";", "unset", "(", "$", "data", "[", "'_content'", "]", ")", ";", "}", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "$", "url", ",", "$", "data", ",", "$", "options", ")", ";", "return", "$", "this", "->", "_doRequest", "(", "Request", "::", "METHOD_GET", ",", "$", "url", ",", "$", "body", ",", "$", "options", ")", ";", "}" ]
Do a GET request. The $data argument supports a special `_content` key for providing a request body in a GET request. This is generally not used, but services like ElasticSearch use this feature. @param string $url The url or path you want to request. @param array $data The query data you want to send. @param array $options Additional options for the request. @return \Cake\Http\Client\Response
[ "Do", "a", "GET", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L233-L249
211,212
cakephp/cakephp
src/Http/Client.php
Client.post
public function post($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_POST, $url, $data, $options); }
php
public function post($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_POST, $url, $data, $options); }
[ "public", "function", "post", "(", "$", "url", ",", "$", "data", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "_mergeOptions", "(", "$", "options", ")", ";", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "$", "url", ",", "[", "]", ",", "$", "options", ")", ";", "return", "$", "this", "->", "_doRequest", "(", "Request", "::", "METHOD_POST", ",", "$", "url", ",", "$", "data", ",", "$", "options", ")", ";", "}" ]
Do a POST request. @param string $url The url or path you want to request. @param mixed $data The post data you want to send. @param array $options Additional options for the request. @return \Cake\Http\Client\Response
[ "Do", "a", "POST", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L259-L265
211,213
cakephp/cakephp
src/Http/Client.php
Client.put
public function put($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_PUT, $url, $data, $options); }
php
public function put($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_PUT, $url, $data, $options); }
[ "public", "function", "put", "(", "$", "url", ",", "$", "data", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "_mergeOptions", "(", "$", "options", ")", ";", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "$", "url", ",", "[", "]", ",", "$", "options", ")", ";", "return", "$", "this", "->", "_doRequest", "(", "Request", "::", "METHOD_PUT", ",", "$", "url", ",", "$", "data", ",", "$", "options", ")", ";", "}" ]
Do a PUT request. @param string $url The url or path you want to request. @param mixed $data The request data you want to send. @param array $options Additional options for the request. @return \Cake\Http\Client\Response
[ "Do", "a", "PUT", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L275-L281
211,214
cakephp/cakephp
src/Http/Client.php
Client.patch
public function patch($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_PATCH, $url, $data, $options); }
php
public function patch($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_PATCH, $url, $data, $options); }
[ "public", "function", "patch", "(", "$", "url", ",", "$", "data", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "_mergeOptions", "(", "$", "options", ")", ";", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "$", "url", ",", "[", "]", ",", "$", "options", ")", ";", "return", "$", "this", "->", "_doRequest", "(", "Request", "::", "METHOD_PATCH", ",", "$", "url", ",", "$", "data", ",", "$", "options", ")", ";", "}" ]
Do a PATCH request. @param string $url The url or path you want to request. @param mixed $data The request data you want to send. @param array $options Additional options for the request. @return \Cake\Http\Client\Response
[ "Do", "a", "PATCH", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L291-L297
211,215
cakephp/cakephp
src/Http/Client.php
Client.options
public function options($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_OPTIONS, $url, $data, $options); }
php
public function options($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_OPTIONS, $url, $data, $options); }
[ "public", "function", "options", "(", "$", "url", ",", "$", "data", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "_mergeOptions", "(", "$", "options", ")", ";", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "$", "url", ",", "[", "]", ",", "$", "options", ")", ";", "return", "$", "this", "->", "_doRequest", "(", "Request", "::", "METHOD_OPTIONS", ",", "$", "url", ",", "$", "data", ",", "$", "options", ")", ";", "}" ]
Do an OPTIONS request. @param string $url The url or path you want to request. @param mixed $data The request data you want to send. @param array $options Additional options for the request. @return \Cake\Http\Client\Response
[ "Do", "an", "OPTIONS", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L307-L313
211,216
cakephp/cakephp
src/Http/Client.php
Client.trace
public function trace($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_TRACE, $url, $data, $options); }
php
public function trace($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_TRACE, $url, $data, $options); }
[ "public", "function", "trace", "(", "$", "url", ",", "$", "data", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "_mergeOptions", "(", "$", "options", ")", ";", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "$", "url", ",", "[", "]", ",", "$", "options", ")", ";", "return", "$", "this", "->", "_doRequest", "(", "Request", "::", "METHOD_TRACE", ",", "$", "url", ",", "$", "data", ",", "$", "options", ")", ";", "}" ]
Do a TRACE request. @param string $url The url or path you want to request. @param mixed $data The request data you want to send. @param array $options Additional options for the request. @return \Cake\Http\Client\Response
[ "Do", "a", "TRACE", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L323-L329
211,217
cakephp/cakephp
src/Http/Client.php
Client.delete
public function delete($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_DELETE, $url, $data, $options); }
php
public function delete($url, $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, [], $options); return $this->_doRequest(Request::METHOD_DELETE, $url, $data, $options); }
[ "public", "function", "delete", "(", "$", "url", ",", "$", "data", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "_mergeOptions", "(", "$", "options", ")", ";", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "$", "url", ",", "[", "]", ",", "$", "options", ")", ";", "return", "$", "this", "->", "_doRequest", "(", "Request", "::", "METHOD_DELETE", ",", "$", "url", ",", "$", "data", ",", "$", "options", ")", ";", "}" ]
Do a DELETE request. @param string $url The url or path you want to request. @param mixed $data The request data you want to send. @param array $options Additional options for the request. @return \Cake\Http\Client\Response
[ "Do", "a", "DELETE", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L339-L345
211,218
cakephp/cakephp
src/Http/Client.php
Client.head
public function head($url, array $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, $data, $options); return $this->_doRequest(Request::METHOD_HEAD, $url, '', $options); }
php
public function head($url, array $data = [], array $options = []) { $options = $this->_mergeOptions($options); $url = $this->buildUrl($url, $data, $options); return $this->_doRequest(Request::METHOD_HEAD, $url, '', $options); }
[ "public", "function", "head", "(", "$", "url", ",", "array", "$", "data", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "_mergeOptions", "(", "$", "options", ")", ";", "$", "url", "=", "$", "this", "->", "buildUrl", "(", "$", "url", ",", "$", "data", ",", "$", "options", ")", ";", "return", "$", "this", "->", "_doRequest", "(", "Request", "::", "METHOD_HEAD", ",", "$", "url", ",", "''", ",", "$", "options", ")", ";", "}" ]
Do a HEAD request. @param string $url The url or path you want to request. @param array $data The query string data you want to send. @param array $options Additional options for the request. @return \Cake\Http\Client\Response
[ "Do", "a", "HEAD", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L355-L361
211,219
cakephp/cakephp
src/Http/Client.php
Client._doRequest
protected function _doRequest($method, $url, $data, $options) { $request = $this->_createRequest( $method, $url, $data, $options ); return $this->send($request, $options); }
php
protected function _doRequest($method, $url, $data, $options) { $request = $this->_createRequest( $method, $url, $data, $options ); return $this->send($request, $options); }
[ "protected", "function", "_doRequest", "(", "$", "method", ",", "$", "url", ",", "$", "data", ",", "$", "options", ")", "{", "$", "request", "=", "$", "this", "->", "_createRequest", "(", "$", "method", ",", "$", "url", ",", "$", "data", ",", "$", "options", ")", ";", "return", "$", "this", "->", "send", "(", "$", "request", ",", "$", "options", ")", ";", "}" ]
Helper method for doing non-GET requests. @param string $method HTTP method. @param string $url URL to request. @param mixed $data The request body. @param array $options The options to use. Contains auth, proxy, etc. @return \Cake\Http\Client\Response
[ "Helper", "method", "for", "doing", "non", "-", "GET", "requests", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L372-L382
211,220
cakephp/cakephp
src/Http/Client.php
Client._sendRequest
protected function _sendRequest(Request $request, $options) { $responses = $this->_adapter->send($request, $options); $url = $request->getUri(); foreach ($responses as $response) { $this->_cookies = $this->_cookies->addFromResponse($response, $request); } return array_pop($responses); }
php
protected function _sendRequest(Request $request, $options) { $responses = $this->_adapter->send($request, $options); $url = $request->getUri(); foreach ($responses as $response) { $this->_cookies = $this->_cookies->addFromResponse($response, $request); } return array_pop($responses); }
[ "protected", "function", "_sendRequest", "(", "Request", "$", "request", ",", "$", "options", ")", "{", "$", "responses", "=", "$", "this", "->", "_adapter", "->", "send", "(", "$", "request", ",", "$", "options", ")", ";", "$", "url", "=", "$", "request", "->", "getUri", "(", ")", ";", "foreach", "(", "$", "responses", "as", "$", "response", ")", "{", "$", "this", "->", "_cookies", "=", "$", "this", "->", "_cookies", "->", "addFromResponse", "(", "$", "response", ",", "$", "request", ")", ";", "}", "return", "array_pop", "(", "$", "responses", ")", ";", "}" ]
Send a request without redirection. @param \Cake\Http\Client\Request $request The request to send. @param array $options Additional options to use. @return \Cake\Http\Client\Response
[ "Send", "a", "request", "without", "redirection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L443-L452
211,221
cakephp/cakephp
src/Http/Client.php
Client.buildUrl
public function buildUrl($url, $query = [], $options = []) { if (empty($options) && empty($query)) { return $url; } if ($query) { $q = (strpos($url, '?') === false) ? '?' : '&'; $url .= $q; $url .= is_string($query) ? $query : http_build_query($query); } $defaults = [ 'host' => null, 'port' => null, 'scheme' => 'http', 'protocolRelative' => false ]; $options += $defaults; if ($options['protocolRelative'] && preg_match('#^//#', $url)) { $url = $options['scheme'] . ':' . $url; } if (preg_match('#^https?://#', $url)) { return $url; } $defaultPorts = [ 'http' => 80, 'https' => 443 ]; $out = $options['scheme'] . '://' . $options['host']; if ($options['port'] && $options['port'] != $defaultPorts[$options['scheme']]) { $out .= ':' . $options['port']; } $out .= '/' . ltrim($url, '/'); return $out; }
php
public function buildUrl($url, $query = [], $options = []) { if (empty($options) && empty($query)) { return $url; } if ($query) { $q = (strpos($url, '?') === false) ? '?' : '&'; $url .= $q; $url .= is_string($query) ? $query : http_build_query($query); } $defaults = [ 'host' => null, 'port' => null, 'scheme' => 'http', 'protocolRelative' => false ]; $options += $defaults; if ($options['protocolRelative'] && preg_match('#^//#', $url)) { $url = $options['scheme'] . ':' . $url; } if (preg_match('#^https?://#', $url)) { return $url; } $defaultPorts = [ 'http' => 80, 'https' => 443 ]; $out = $options['scheme'] . '://' . $options['host']; if ($options['port'] && $options['port'] != $defaultPorts[$options['scheme']]) { $out .= ':' . $options['port']; } $out .= '/' . ltrim($url, '/'); return $out; }
[ "public", "function", "buildUrl", "(", "$", "url", ",", "$", "query", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "options", ")", "&&", "empty", "(", "$", "query", ")", ")", "{", "return", "$", "url", ";", "}", "if", "(", "$", "query", ")", "{", "$", "q", "=", "(", "strpos", "(", "$", "url", ",", "'?'", ")", "===", "false", ")", "?", "'?'", ":", "'&'", ";", "$", "url", ".=", "$", "q", ";", "$", "url", ".=", "is_string", "(", "$", "query", ")", "?", "$", "query", ":", "http_build_query", "(", "$", "query", ")", ";", "}", "$", "defaults", "=", "[", "'host'", "=>", "null", ",", "'port'", "=>", "null", ",", "'scheme'", "=>", "'http'", ",", "'protocolRelative'", "=>", "false", "]", ";", "$", "options", "+=", "$", "defaults", ";", "if", "(", "$", "options", "[", "'protocolRelative'", "]", "&&", "preg_match", "(", "'#^//#'", ",", "$", "url", ")", ")", "{", "$", "url", "=", "$", "options", "[", "'scheme'", "]", ".", "':'", ".", "$", "url", ";", "}", "if", "(", "preg_match", "(", "'#^https?://#'", ",", "$", "url", ")", ")", "{", "return", "$", "url", ";", "}", "$", "defaultPorts", "=", "[", "'http'", "=>", "80", ",", "'https'", "=>", "443", "]", ";", "$", "out", "=", "$", "options", "[", "'scheme'", "]", ".", "'://'", ".", "$", "options", "[", "'host'", "]", ";", "if", "(", "$", "options", "[", "'port'", "]", "&&", "$", "options", "[", "'port'", "]", "!=", "$", "defaultPorts", "[", "$", "options", "[", "'scheme'", "]", "]", ")", "{", "$", "out", ".=", "':'", ".", "$", "options", "[", "'port'", "]", ";", "}", "$", "out", ".=", "'/'", ".", "ltrim", "(", "$", "url", ",", "'/'", ")", ";", "return", "$", "out", ";", "}" ]
Generate a URL based on the scoped client options. @param string $url Either a full URL or just the path. @param string|array $query The query data for the URL. @param array $options The config options stored with Client::config() @return string A complete url with scheme, port, host, and path.
[ "Generate", "a", "URL", "based", "on", "the", "scoped", "client", "options", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L462-L498
211,222
cakephp/cakephp
src/Http/Client.php
Client._createRequest
protected function _createRequest($method, $url, $data, $options) { $headers = isset($options['headers']) ? (array)$options['headers'] : []; if (isset($options['type'])) { $headers = array_merge($headers, $this->_typeHeaders($options['type'])); } if (is_string($data) && !isset($headers['Content-Type']) && !isset($headers['content-type'])) { $headers['Content-Type'] = 'application/x-www-form-urlencoded'; } $request = new Request($url, $method, $headers, $data); $cookies = isset($options['cookies']) ? $options['cookies'] : []; /** @var \Cake\Http\Client\Request $request */ $request = $this->_cookies->addToRequest($request, $cookies); if (isset($options['auth'])) { $request = $this->_addAuthentication($request, $options); } if (isset($options['proxy'])) { $request = $this->_addProxy($request, $options); } return $request; }
php
protected function _createRequest($method, $url, $data, $options) { $headers = isset($options['headers']) ? (array)$options['headers'] : []; if (isset($options['type'])) { $headers = array_merge($headers, $this->_typeHeaders($options['type'])); } if (is_string($data) && !isset($headers['Content-Type']) && !isset($headers['content-type'])) { $headers['Content-Type'] = 'application/x-www-form-urlencoded'; } $request = new Request($url, $method, $headers, $data); $cookies = isset($options['cookies']) ? $options['cookies'] : []; /** @var \Cake\Http\Client\Request $request */ $request = $this->_cookies->addToRequest($request, $cookies); if (isset($options['auth'])) { $request = $this->_addAuthentication($request, $options); } if (isset($options['proxy'])) { $request = $this->_addProxy($request, $options); } return $request; }
[ "protected", "function", "_createRequest", "(", "$", "method", ",", "$", "url", ",", "$", "data", ",", "$", "options", ")", "{", "$", "headers", "=", "isset", "(", "$", "options", "[", "'headers'", "]", ")", "?", "(", "array", ")", "$", "options", "[", "'headers'", "]", ":", "[", "]", ";", "if", "(", "isset", "(", "$", "options", "[", "'type'", "]", ")", ")", "{", "$", "headers", "=", "array_merge", "(", "$", "headers", ",", "$", "this", "->", "_typeHeaders", "(", "$", "options", "[", "'type'", "]", ")", ")", ";", "}", "if", "(", "is_string", "(", "$", "data", ")", "&&", "!", "isset", "(", "$", "headers", "[", "'Content-Type'", "]", ")", "&&", "!", "isset", "(", "$", "headers", "[", "'content-type'", "]", ")", ")", "{", "$", "headers", "[", "'Content-Type'", "]", "=", "'application/x-www-form-urlencoded'", ";", "}", "$", "request", "=", "new", "Request", "(", "$", "url", ",", "$", "method", ",", "$", "headers", ",", "$", "data", ")", ";", "$", "cookies", "=", "isset", "(", "$", "options", "[", "'cookies'", "]", ")", "?", "$", "options", "[", "'cookies'", "]", ":", "[", "]", ";", "/** @var \\Cake\\Http\\Client\\Request $request */", "$", "request", "=", "$", "this", "->", "_cookies", "->", "addToRequest", "(", "$", "request", ",", "$", "cookies", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'auth'", "]", ")", ")", "{", "$", "request", "=", "$", "this", "->", "_addAuthentication", "(", "$", "request", ",", "$", "options", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'proxy'", "]", ")", ")", "{", "$", "request", "=", "$", "this", "->", "_addProxy", "(", "$", "request", ",", "$", "options", ")", ";", "}", "return", "$", "request", ";", "}" ]
Creates a new request object based on the parameters. @param string $method HTTP method name. @param string $url The url including query string. @param mixed $data The request body. @param array $options The options to use. Contains auth, proxy, etc. @return \Cake\Http\Client\Request
[ "Creates", "a", "new", "request", "object", "based", "on", "the", "parameters", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L509-L531
211,223
cakephp/cakephp
src/Http/Client.php
Client._addAuthentication
protected function _addAuthentication(Request $request, $options) { $auth = $options['auth']; $adapter = $this->_createAuth($auth, $options); $result = $adapter->authentication($request, $options['auth']); return $result ?: $request; }
php
protected function _addAuthentication(Request $request, $options) { $auth = $options['auth']; $adapter = $this->_createAuth($auth, $options); $result = $adapter->authentication($request, $options['auth']); return $result ?: $request; }
[ "protected", "function", "_addAuthentication", "(", "Request", "$", "request", ",", "$", "options", ")", "{", "$", "auth", "=", "$", "options", "[", "'auth'", "]", ";", "$", "adapter", "=", "$", "this", "->", "_createAuth", "(", "$", "auth", ",", "$", "options", ")", ";", "$", "result", "=", "$", "adapter", "->", "authentication", "(", "$", "request", ",", "$", "options", "[", "'auth'", "]", ")", ";", "return", "$", "result", "?", ":", "$", "request", ";", "}" ]
Add authentication headers to the request. Uses the authentication type to choose the correct strategy and use its methods to add headers. @param \Cake\Http\Client\Request $request The request to modify. @param array $options Array of options containing the 'auth' key. @return \Cake\Http\Client\Request The updated request object.
[ "Add", "authentication", "headers", "to", "the", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L573-L580
211,224
cakephp/cakephp
src/Http/Client.php
Client._addProxy
protected function _addProxy(Request $request, $options) { $auth = $options['proxy']; $adapter = $this->_createAuth($auth, $options); $result = $adapter->proxyAuthentication($request, $options['proxy']); return $result ?: $request; }
php
protected function _addProxy(Request $request, $options) { $auth = $options['proxy']; $adapter = $this->_createAuth($auth, $options); $result = $adapter->proxyAuthentication($request, $options['proxy']); return $result ?: $request; }
[ "protected", "function", "_addProxy", "(", "Request", "$", "request", ",", "$", "options", ")", "{", "$", "auth", "=", "$", "options", "[", "'proxy'", "]", ";", "$", "adapter", "=", "$", "this", "->", "_createAuth", "(", "$", "auth", ",", "$", "options", ")", ";", "$", "result", "=", "$", "adapter", "->", "proxyAuthentication", "(", "$", "request", ",", "$", "options", "[", "'proxy'", "]", ")", ";", "return", "$", "result", "?", ":", "$", "request", ";", "}" ]
Add proxy authentication headers. Uses the authentication type to choose the correct strategy and use its methods to add headers. @param \Cake\Http\Client\Request $request The request to modify. @param array $options Array of options containing the 'proxy' key. @return \Cake\Http\Client\Request The updated request object.
[ "Add", "proxy", "authentication", "headers", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L592-L599
211,225
cakephp/cakephp
src/Http/Client.php
Client._createAuth
protected function _createAuth($auth, $options) { if (empty($auth['type'])) { $auth['type'] = 'basic'; } $name = ucfirst($auth['type']); $class = App::className($name, 'Http/Client/Auth'); if (!$class) { throw new Exception( sprintf('Invalid authentication type %s', $name) ); } return new $class($this, $options); }
php
protected function _createAuth($auth, $options) { if (empty($auth['type'])) { $auth['type'] = 'basic'; } $name = ucfirst($auth['type']); $class = App::className($name, 'Http/Client/Auth'); if (!$class) { throw new Exception( sprintf('Invalid authentication type %s', $name) ); } return new $class($this, $options); }
[ "protected", "function", "_createAuth", "(", "$", "auth", ",", "$", "options", ")", "{", "if", "(", "empty", "(", "$", "auth", "[", "'type'", "]", ")", ")", "{", "$", "auth", "[", "'type'", "]", "=", "'basic'", ";", "}", "$", "name", "=", "ucfirst", "(", "$", "auth", "[", "'type'", "]", ")", ";", "$", "class", "=", "App", "::", "className", "(", "$", "name", ",", "'Http/Client/Auth'", ")", ";", "if", "(", "!", "$", "class", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "'Invalid authentication type %s'", ",", "$", "name", ")", ")", ";", "}", "return", "new", "$", "class", "(", "$", "this", ",", "$", "options", ")", ";", "}" ]
Create the authentication strategy. Use the configuration options to create the correct authentication strategy handler. @param array $auth The authentication options to use. @param array $options The overall request options to use. @return mixed Authentication strategy instance. @throws \Cake\Core\Exception\Exception when an invalid strategy is chosen.
[ "Create", "the", "authentication", "strategy", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client.php#L612-L626
211,226
cakephp/cakephp
src/Controller/Component/PaginatorComponent.php
PaginatorComponent._setPagingParams
protected function _setPagingParams() { $controller = $this->getController(); $request = $controller->getRequest(); $paging = $this->_paginator->getPagingParams() + (array)$request->getParam('paging', []); $controller->setRequest($request->withParam('paging', $paging)); }
php
protected function _setPagingParams() { $controller = $this->getController(); $request = $controller->getRequest(); $paging = $this->_paginator->getPagingParams() + (array)$request->getParam('paging', []); $controller->setRequest($request->withParam('paging', $paging)); }
[ "protected", "function", "_setPagingParams", "(", ")", "{", "$", "controller", "=", "$", "this", "->", "getController", "(", ")", ";", "$", "request", "=", "$", "controller", "->", "getRequest", "(", ")", ";", "$", "paging", "=", "$", "this", "->", "_paginator", "->", "getPagingParams", "(", ")", "+", "(", "array", ")", "$", "request", "->", "getParam", "(", "'paging'", ",", "[", "]", ")", ";", "$", "controller", "->", "setRequest", "(", "$", "request", "->", "withParam", "(", "'paging'", ",", "$", "paging", ")", ")", ";", "}" ]
Set paging params to request instance. @return void
[ "Set", "paging", "params", "to", "request", "instance", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/PaginatorComponent.php#L268-L275
211,227
cakephp/cakephp
src/ORM/BehaviorRegistry.php
BehaviorRegistry.setTable
public function setTable(Table $table) { $this->_table = $table; $eventManager = $table->getEventManager(); if ($eventManager !== null) { $this->setEventManager($eventManager); } }
php
public function setTable(Table $table) { $this->_table = $table; $eventManager = $table->getEventManager(); if ($eventManager !== null) { $this->setEventManager($eventManager); } }
[ "public", "function", "setTable", "(", "Table", "$", "table", ")", "{", "$", "this", "->", "_table", "=", "$", "table", ";", "$", "eventManager", "=", "$", "table", "->", "getEventManager", "(", ")", ";", "if", "(", "$", "eventManager", "!==", "null", ")", "{", "$", "this", "->", "setEventManager", "(", "$", "eventManager", ")", ";", "}", "}" ]
Attaches a table instance to this registry. @param \Cake\ORM\Table $table The table this registry is attached to. @return void
[ "Attaches", "a", "table", "instance", "to", "this", "registry", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/BehaviorRegistry.php#L75-L82
211,228
cakephp/cakephp
src/ORM/BehaviorRegistry.php
BehaviorRegistry.className
public static function className($class) { $result = App::className($class, 'Model/Behavior', 'Behavior'); if (!$result) { $result = App::className($class, 'ORM/Behavior', 'Behavior'); } return $result ?: null; }
php
public static function className($class) { $result = App::className($class, 'Model/Behavior', 'Behavior'); if (!$result) { $result = App::className($class, 'ORM/Behavior', 'Behavior'); } return $result ?: null; }
[ "public", "static", "function", "className", "(", "$", "class", ")", "{", "$", "result", "=", "App", "::", "className", "(", "$", "class", ",", "'Model/Behavior'", ",", "'Behavior'", ")", ";", "if", "(", "!", "$", "result", ")", "{", "$", "result", "=", "App", "::", "className", "(", "$", "class", ",", "'ORM/Behavior'", ",", "'Behavior'", ")", ";", "}", "return", "$", "result", "?", ":", "null", ";", "}" ]
Resolve a behavior classname. @param string $class Partial classname to resolve. @return string|null Either the correct classname or null. @since 3.5.7
[ "Resolve", "a", "behavior", "classname", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/BehaviorRegistry.php#L91-L99
211,229
cakephp/cakephp
src/ORM/BehaviorRegistry.php
BehaviorRegistry._create
protected function _create($class, $alias, $config) { $instance = new $class($this->_table, $config); $enable = isset($config['enabled']) ? $config['enabled'] : true; if ($enable) { $this->getEventManager()->on($instance); } $methods = $this->_getMethods($instance, $class, $alias); $this->_methodMap += $methods['methods']; $this->_finderMap += $methods['finders']; return $instance; }
php
protected function _create($class, $alias, $config) { $instance = new $class($this->_table, $config); $enable = isset($config['enabled']) ? $config['enabled'] : true; if ($enable) { $this->getEventManager()->on($instance); } $methods = $this->_getMethods($instance, $class, $alias); $this->_methodMap += $methods['methods']; $this->_finderMap += $methods['finders']; return $instance; }
[ "protected", "function", "_create", "(", "$", "class", ",", "$", "alias", ",", "$", "config", ")", "{", "$", "instance", "=", "new", "$", "class", "(", "$", "this", "->", "_table", ",", "$", "config", ")", ";", "$", "enable", "=", "isset", "(", "$", "config", "[", "'enabled'", "]", ")", "?", "$", "config", "[", "'enabled'", "]", ":", "true", ";", "if", "(", "$", "enable", ")", "{", "$", "this", "->", "getEventManager", "(", ")", "->", "on", "(", "$", "instance", ")", ";", "}", "$", "methods", "=", "$", "this", "->", "_getMethods", "(", "$", "instance", ",", "$", "class", ",", "$", "alias", ")", ";", "$", "this", "->", "_methodMap", "+=", "$", "methods", "[", "'methods'", "]", ";", "$", "this", "->", "_finderMap", "+=", "$", "methods", "[", "'finders'", "]", ";", "return", "$", "instance", ";", "}" ]
Create the behavior instance. Part of the template method for Cake\Core\ObjectRegistry::load() Enabled behaviors will be registered with the event manager. @param string $class The classname that is missing. @param string $alias The alias of the object. @param array $config An array of config to use for the behavior. @return \Cake\ORM\Behavior The constructed behavior class.
[ "Create", "the", "behavior", "instance", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/BehaviorRegistry.php#L144-L156
211,230
cakephp/cakephp
src/ORM/BehaviorRegistry.php
BehaviorRegistry._getMethods
protected function _getMethods(Behavior $instance, $class, $alias) { $finders = array_change_key_case($instance->implementedFinders()); $methods = array_change_key_case($instance->implementedMethods()); foreach ($finders as $finder => $methodName) { if (isset($this->_finderMap[$finder]) && $this->has($this->_finderMap[$finder][0])) { $duplicate = $this->_finderMap[$finder]; $error = sprintf( '%s contains duplicate finder "%s" which is already provided by "%s"', $class, $finder, $duplicate[0] ); throw new LogicException($error); } $finders[$finder] = [$alias, $methodName]; } foreach ($methods as $method => $methodName) { if (isset($this->_methodMap[$method]) && $this->has($this->_methodMap[$method][0])) { $duplicate = $this->_methodMap[$method]; $error = sprintf( '%s contains duplicate method "%s" which is already provided by "%s"', $class, $method, $duplicate[0] ); throw new LogicException($error); } $methods[$method] = [$alias, $methodName]; } return compact('methods', 'finders'); }
php
protected function _getMethods(Behavior $instance, $class, $alias) { $finders = array_change_key_case($instance->implementedFinders()); $methods = array_change_key_case($instance->implementedMethods()); foreach ($finders as $finder => $methodName) { if (isset($this->_finderMap[$finder]) && $this->has($this->_finderMap[$finder][0])) { $duplicate = $this->_finderMap[$finder]; $error = sprintf( '%s contains duplicate finder "%s" which is already provided by "%s"', $class, $finder, $duplicate[0] ); throw new LogicException($error); } $finders[$finder] = [$alias, $methodName]; } foreach ($methods as $method => $methodName) { if (isset($this->_methodMap[$method]) && $this->has($this->_methodMap[$method][0])) { $duplicate = $this->_methodMap[$method]; $error = sprintf( '%s contains duplicate method "%s" which is already provided by "%s"', $class, $method, $duplicate[0] ); throw new LogicException($error); } $methods[$method] = [$alias, $methodName]; } return compact('methods', 'finders'); }
[ "protected", "function", "_getMethods", "(", "Behavior", "$", "instance", ",", "$", "class", ",", "$", "alias", ")", "{", "$", "finders", "=", "array_change_key_case", "(", "$", "instance", "->", "implementedFinders", "(", ")", ")", ";", "$", "methods", "=", "array_change_key_case", "(", "$", "instance", "->", "implementedMethods", "(", ")", ")", ";", "foreach", "(", "$", "finders", "as", "$", "finder", "=>", "$", "methodName", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_finderMap", "[", "$", "finder", "]", ")", "&&", "$", "this", "->", "has", "(", "$", "this", "->", "_finderMap", "[", "$", "finder", "]", "[", "0", "]", ")", ")", "{", "$", "duplicate", "=", "$", "this", "->", "_finderMap", "[", "$", "finder", "]", ";", "$", "error", "=", "sprintf", "(", "'%s contains duplicate finder \"%s\" which is already provided by \"%s\"'", ",", "$", "class", ",", "$", "finder", ",", "$", "duplicate", "[", "0", "]", ")", ";", "throw", "new", "LogicException", "(", "$", "error", ")", ";", "}", "$", "finders", "[", "$", "finder", "]", "=", "[", "$", "alias", ",", "$", "methodName", "]", ";", "}", "foreach", "(", "$", "methods", "as", "$", "method", "=>", "$", "methodName", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_methodMap", "[", "$", "method", "]", ")", "&&", "$", "this", "->", "has", "(", "$", "this", "->", "_methodMap", "[", "$", "method", "]", "[", "0", "]", ")", ")", "{", "$", "duplicate", "=", "$", "this", "->", "_methodMap", "[", "$", "method", "]", ";", "$", "error", "=", "sprintf", "(", "'%s contains duplicate method \"%s\" which is already provided by \"%s\"'", ",", "$", "class", ",", "$", "method", ",", "$", "duplicate", "[", "0", "]", ")", ";", "throw", "new", "LogicException", "(", "$", "error", ")", ";", "}", "$", "methods", "[", "$", "method", "]", "=", "[", "$", "alias", ",", "$", "methodName", "]", ";", "}", "return", "compact", "(", "'methods'", ",", "'finders'", ")", ";", "}" ]
Get the behavior methods and ensure there are no duplicates. Use the implementedEvents() method to exclude callback methods. Methods starting with `_` will be ignored, as will methods declared on Cake\ORM\Behavior @param \Cake\ORM\Behavior $instance The behavior to get methods from. @param string $class The classname that is missing. @param string $alias The alias of the object. @return array A list of implemented finders and methods. @throws \LogicException when duplicate methods are connected.
[ "Get", "the", "behavior", "methods", "and", "ensure", "there", "are", "no", "duplicates", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/BehaviorRegistry.php#L171-L205
211,231
cakephp/cakephp
src/ORM/BehaviorRegistry.php
BehaviorRegistry.call
public function call($method, array $args = []) { $method = strtolower($method); if ($this->hasMethod($method) && $this->has($this->_methodMap[$method][0])) { list($behavior, $callMethod) = $this->_methodMap[$method]; return call_user_func_array([$this->_loaded[$behavior], $callMethod], $args); } throw new BadMethodCallException( sprintf('Cannot call "%s" it does not belong to any attached behavior.', $method) ); }
php
public function call($method, array $args = []) { $method = strtolower($method); if ($this->hasMethod($method) && $this->has($this->_methodMap[$method][0])) { list($behavior, $callMethod) = $this->_methodMap[$method]; return call_user_func_array([$this->_loaded[$behavior], $callMethod], $args); } throw new BadMethodCallException( sprintf('Cannot call "%s" it does not belong to any attached behavior.', $method) ); }
[ "public", "function", "call", "(", "$", "method", ",", "array", "$", "args", "=", "[", "]", ")", "{", "$", "method", "=", "strtolower", "(", "$", "method", ")", ";", "if", "(", "$", "this", "->", "hasMethod", "(", "$", "method", ")", "&&", "$", "this", "->", "has", "(", "$", "this", "->", "_methodMap", "[", "$", "method", "]", "[", "0", "]", ")", ")", "{", "list", "(", "$", "behavior", ",", "$", "callMethod", ")", "=", "$", "this", "->", "_methodMap", "[", "$", "method", "]", ";", "return", "call_user_func_array", "(", "[", "$", "this", "->", "_loaded", "[", "$", "behavior", "]", ",", "$", "callMethod", "]", ",", "$", "args", ")", ";", "}", "throw", "new", "BadMethodCallException", "(", "sprintf", "(", "'Cannot call \"%s\" it does not belong to any attached behavior.'", ",", "$", "method", ")", ")", ";", "}" ]
Invoke a method on a behavior. @param string $method The method to invoke. @param array $args The arguments you want to invoke the method with. @return mixed The return value depends on the underlying behavior method. @throws \BadMethodCallException When the method is unknown.
[ "Invoke", "a", "method", "on", "a", "behavior", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/BehaviorRegistry.php#L247-L259
211,232
cakephp/cakephp
src/ORM/BehaviorRegistry.php
BehaviorRegistry.callFinder
public function callFinder($type, array $args = []) { $type = strtolower($type); if ($this->hasFinder($type) && $this->has($this->_finderMap[$type][0])) { list($behavior, $callMethod) = $this->_finderMap[$type]; return call_user_func_array([$this->_loaded[$behavior], $callMethod], $args); } throw new BadMethodCallException( sprintf('Cannot call finder "%s" it does not belong to any attached behavior.', $type) ); }
php
public function callFinder($type, array $args = []) { $type = strtolower($type); if ($this->hasFinder($type) && $this->has($this->_finderMap[$type][0])) { list($behavior, $callMethod) = $this->_finderMap[$type]; return call_user_func_array([$this->_loaded[$behavior], $callMethod], $args); } throw new BadMethodCallException( sprintf('Cannot call finder "%s" it does not belong to any attached behavior.', $type) ); }
[ "public", "function", "callFinder", "(", "$", "type", ",", "array", "$", "args", "=", "[", "]", ")", "{", "$", "type", "=", "strtolower", "(", "$", "type", ")", ";", "if", "(", "$", "this", "->", "hasFinder", "(", "$", "type", ")", "&&", "$", "this", "->", "has", "(", "$", "this", "->", "_finderMap", "[", "$", "type", "]", "[", "0", "]", ")", ")", "{", "list", "(", "$", "behavior", ",", "$", "callMethod", ")", "=", "$", "this", "->", "_finderMap", "[", "$", "type", "]", ";", "return", "call_user_func_array", "(", "[", "$", "this", "->", "_loaded", "[", "$", "behavior", "]", ",", "$", "callMethod", "]", ",", "$", "args", ")", ";", "}", "throw", "new", "BadMethodCallException", "(", "sprintf", "(", "'Cannot call finder \"%s\" it does not belong to any attached behavior.'", ",", "$", "type", ")", ")", ";", "}" ]
Invoke a finder on a behavior. @param string $type The finder type to invoke. @param array $args The arguments you want to invoke the method with. @return mixed The return value depends on the underlying behavior method. @throws \BadMethodCallException When the method is unknown.
[ "Invoke", "a", "finder", "on", "a", "behavior", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/BehaviorRegistry.php#L269-L282
211,233
cakephp/cakephp
src/Collection/Iterator/MapReduce.php
MapReduce.emit
public function emit($val, $key = null) { $this->_result[$key === null ? $this->_counter : $key] = $val; $this->_counter++; }
php
public function emit($val, $key = null) { $this->_result[$key === null ? $this->_counter : $key] = $val; $this->_counter++; }
[ "public", "function", "emit", "(", "$", "val", ",", "$", "key", "=", "null", ")", "{", "$", "this", "->", "_result", "[", "$", "key", "===", "null", "?", "$", "this", "->", "_counter", ":", "$", "key", "]", "=", "$", "val", ";", "$", "this", "->", "_counter", "++", ";", "}" ]
Appends a new record to the final list of results and optionally assign a key for this record. @param mixed $val The value to be appended to the final list of results @param string|null $key and optional key to assign to the value @return void
[ "Appends", "a", "new", "record", "to", "the", "final", "list", "of", "results", "and", "optionally", "assign", "a", "key", "for", "this", "record", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/MapReduce.php#L159-L163
211,234
cakephp/cakephp
src/Collection/Iterator/MapReduce.php
MapReduce._execute
protected function _execute() { $mapper = $this->_mapper; foreach ($this->_data as $key => $val) { $mapper($val, $key, $this); } $this->_data = null; if (!empty($this->_intermediate) && empty($this->_reducer)) { throw new LogicException('No reducer function was provided'); } $reducer = $this->_reducer; foreach ($this->_intermediate as $key => $list) { $reducer($list, $key, $this); } $this->_intermediate = []; $this->_executed = true; }
php
protected function _execute() { $mapper = $this->_mapper; foreach ($this->_data as $key => $val) { $mapper($val, $key, $this); } $this->_data = null; if (!empty($this->_intermediate) && empty($this->_reducer)) { throw new LogicException('No reducer function was provided'); } $reducer = $this->_reducer; foreach ($this->_intermediate as $key => $list) { $reducer($list, $key, $this); } $this->_intermediate = []; $this->_executed = true; }
[ "protected", "function", "_execute", "(", ")", "{", "$", "mapper", "=", "$", "this", "->", "_mapper", ";", "foreach", "(", "$", "this", "->", "_data", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "mapper", "(", "$", "val", ",", "$", "key", ",", "$", "this", ")", ";", "}", "$", "this", "->", "_data", "=", "null", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_intermediate", ")", "&&", "empty", "(", "$", "this", "->", "_reducer", ")", ")", "{", "throw", "new", "LogicException", "(", "'No reducer function was provided'", ")", ";", "}", "$", "reducer", "=", "$", "this", "->", "_reducer", ";", "foreach", "(", "$", "this", "->", "_intermediate", "as", "$", "key", "=>", "$", "list", ")", "{", "$", "reducer", "(", "$", "list", ",", "$", "key", ",", "$", "this", ")", ";", "}", "$", "this", "->", "_intermediate", "=", "[", "]", ";", "$", "this", "->", "_executed", "=", "true", ";", "}" ]
Runs the actual Map-Reduce algorithm. This is iterate the original data and call the mapper function for each , then for each intermediate bucket created during the Map phase call the reduce function. @return void @throws \LogicException if emitIntermediate was called but no reducer function was provided
[ "Runs", "the", "actual", "Map", "-", "Reduce", "algorithm", ".", "This", "is", "iterate", "the", "original", "data", "and", "call", "the", "mapper", "function", "for", "each", "then", "for", "each", "intermediate", "bucket", "created", "during", "the", "Map", "phase", "call", "the", "reduce", "function", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/MapReduce.php#L174-L192
211,235
cakephp/cakephp
src/Auth/BasicAuthenticate.php
BasicAuthenticate.unauthenticated
public function unauthenticated(ServerRequest $request, Response $response) { $Exception = new UnauthorizedException(); $Exception->responseHeader($this->loginHeaders($request)); throw $Exception; }
php
public function unauthenticated(ServerRequest $request, Response $response) { $Exception = new UnauthorizedException(); $Exception->responseHeader($this->loginHeaders($request)); throw $Exception; }
[ "public", "function", "unauthenticated", "(", "ServerRequest", "$", "request", ",", "Response", "$", "response", ")", "{", "$", "Exception", "=", "new", "UnauthorizedException", "(", ")", ";", "$", "Exception", "->", "responseHeader", "(", "$", "this", "->", "loginHeaders", "(", "$", "request", ")", ")", ";", "throw", "$", "Exception", ";", "}" ]
Handles an unauthenticated access attempt by sending appropriate login headers @param \Cake\Http\ServerRequest $request A request object. @param \Cake\Http\Response $response A response object. @return void @throws \Cake\Http\Exception\UnauthorizedException
[ "Handles", "an", "unauthenticated", "access", "attempt", "by", "sending", "appropriate", "login", "headers" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Auth/BasicAuthenticate.php#L94-L99
211,236
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany.targetForeignKey
public function targetForeignKey($key = null) { deprecationWarning( 'BelongToMany::targetForeignKey() is deprecated. ' . 'Use setTargetForeignKey()/getTargetForeignKey() instead.' ); if ($key !== null) { $this->setTargetForeignKey($key); } return $this->getTargetForeignKey(); }
php
public function targetForeignKey($key = null) { deprecationWarning( 'BelongToMany::targetForeignKey() is deprecated. ' . 'Use setTargetForeignKey()/getTargetForeignKey() instead.' ); if ($key !== null) { $this->setTargetForeignKey($key); } return $this->getTargetForeignKey(); }
[ "public", "function", "targetForeignKey", "(", "$", "key", "=", "null", ")", "{", "deprecationWarning", "(", "'BelongToMany::targetForeignKey() is deprecated. '", ".", "'Use setTargetForeignKey()/getTargetForeignKey() instead.'", ")", ";", "if", "(", "$", "key", "!==", "null", ")", "{", "$", "this", "->", "setTargetForeignKey", "(", "$", "key", ")", ";", "}", "return", "$", "this", "->", "getTargetForeignKey", "(", ")", ";", "}" ]
Sets the name of the field representing the foreign key to the target table. If no parameters are passed current field is returned @deprecated 3.4.0 Use setTargetForeignKey()/getTargetForeignKey() instead. @param string|null $key the key to be used to link both tables together @return string
[ "Sets", "the", "name", "of", "the", "field", "representing", "the", "foreign", "key", "to", "the", "target", "table", ".", "If", "no", "parameters", "are", "passed", "current", "field", "is", "returned" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L195-L206
211,237
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany.getForeignKey
public function getForeignKey() { if ($this->_foreignKey === null) { $this->_foreignKey = $this->_modelKey($this->getSource()->getTable()); } return $this->_foreignKey; }
php
public function getForeignKey() { if ($this->_foreignKey === null) { $this->_foreignKey = $this->_modelKey($this->getSource()->getTable()); } return $this->_foreignKey; }
[ "public", "function", "getForeignKey", "(", ")", "{", "if", "(", "$", "this", "->", "_foreignKey", "===", "null", ")", "{", "$", "this", "->", "_foreignKey", "=", "$", "this", "->", "_modelKey", "(", "$", "this", "->", "getSource", "(", ")", "->", "getTable", "(", ")", ")", ";", "}", "return", "$", "this", "->", "_foreignKey", ";", "}" ]
Gets the name of the field representing the foreign key to the source table. @return string
[ "Gets", "the", "name", "of", "the", "field", "representing", "the", "foreign", "key", "to", "the", "source", "table", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L225-L232
211,238
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany.sort
public function sort($sort = null) { deprecationWarning( 'BelongToMany::sort() is deprecated. ' . 'Use setSort()/getSort() instead.' ); if ($sort !== null) { $this->setSort($sort); } return $this->getSort(); }
php
public function sort($sort = null) { deprecationWarning( 'BelongToMany::sort() is deprecated. ' . 'Use setSort()/getSort() instead.' ); if ($sort !== null) { $this->setSort($sort); } return $this->getSort(); }
[ "public", "function", "sort", "(", "$", "sort", "=", "null", ")", "{", "deprecationWarning", "(", "'BelongToMany::sort() is deprecated. '", ".", "'Use setSort()/getSort() instead.'", ")", ";", "if", "(", "$", "sort", "!==", "null", ")", "{", "$", "this", "->", "setSort", "(", "$", "sort", ")", ";", "}", "return", "$", "this", "->", "getSort", "(", ")", ";", "}" ]
Sets the sort order in which target records should be returned. If no arguments are passed the currently configured value is returned @deprecated 3.5.0 Use setSort()/getSort() instead. @param mixed $sort A find() compatible order clause @return mixed
[ "Sets", "the", "sort", "order", "in", "which", "target", "records", "should", "be", "returned", ".", "If", "no", "arguments", "are", "passed", "the", "currently", "configured", "value", "is", "returned" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L265-L276
211,239
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany.junction
public function junction($table = null) { if ($table === null && $this->_junctionTable) { return $this->_junctionTable; } $tableLocator = $this->getTableLocator(); if ($table === null && $this->_through) { $table = $this->_through; } elseif ($table === null) { $tableName = $this->_junctionTableName(); $tableAlias = Inflector::camelize($tableName); $config = []; if (!$tableLocator->exists($tableAlias)) { $config = ['table' => $tableName]; // Propagate the connection if we'll get an auto-model if (!App::className($tableAlias, 'Model/Table', 'Table')) { $config['connection'] = $this->getSource()->getConnection(); } } $table = $tableLocator->get($tableAlias, $config); } if (is_string($table)) { $table = $tableLocator->get($table); } $source = $this->getSource(); $target = $this->getTarget(); $this->_generateSourceAssociations($table, $source); $this->_generateTargetAssociations($table, $source, $target); $this->_generateJunctionAssociations($table, $source, $target); return $this->_junctionTable = $table; }
php
public function junction($table = null) { if ($table === null && $this->_junctionTable) { return $this->_junctionTable; } $tableLocator = $this->getTableLocator(); if ($table === null && $this->_through) { $table = $this->_through; } elseif ($table === null) { $tableName = $this->_junctionTableName(); $tableAlias = Inflector::camelize($tableName); $config = []; if (!$tableLocator->exists($tableAlias)) { $config = ['table' => $tableName]; // Propagate the connection if we'll get an auto-model if (!App::className($tableAlias, 'Model/Table', 'Table')) { $config['connection'] = $this->getSource()->getConnection(); } } $table = $tableLocator->get($tableAlias, $config); } if (is_string($table)) { $table = $tableLocator->get($table); } $source = $this->getSource(); $target = $this->getTarget(); $this->_generateSourceAssociations($table, $source); $this->_generateTargetAssociations($table, $source, $target); $this->_generateJunctionAssociations($table, $source, $target); return $this->_junctionTable = $table; }
[ "public", "function", "junction", "(", "$", "table", "=", "null", ")", "{", "if", "(", "$", "table", "===", "null", "&&", "$", "this", "->", "_junctionTable", ")", "{", "return", "$", "this", "->", "_junctionTable", ";", "}", "$", "tableLocator", "=", "$", "this", "->", "getTableLocator", "(", ")", ";", "if", "(", "$", "table", "===", "null", "&&", "$", "this", "->", "_through", ")", "{", "$", "table", "=", "$", "this", "->", "_through", ";", "}", "elseif", "(", "$", "table", "===", "null", ")", "{", "$", "tableName", "=", "$", "this", "->", "_junctionTableName", "(", ")", ";", "$", "tableAlias", "=", "Inflector", "::", "camelize", "(", "$", "tableName", ")", ";", "$", "config", "=", "[", "]", ";", "if", "(", "!", "$", "tableLocator", "->", "exists", "(", "$", "tableAlias", ")", ")", "{", "$", "config", "=", "[", "'table'", "=>", "$", "tableName", "]", ";", "// Propagate the connection if we'll get an auto-model", "if", "(", "!", "App", "::", "className", "(", "$", "tableAlias", ",", "'Model/Table'", ",", "'Table'", ")", ")", "{", "$", "config", "[", "'connection'", "]", "=", "$", "this", "->", "getSource", "(", ")", "->", "getConnection", "(", ")", ";", "}", "}", "$", "table", "=", "$", "tableLocator", "->", "get", "(", "$", "tableAlias", ",", "$", "config", ")", ";", "}", "if", "(", "is_string", "(", "$", "table", ")", ")", "{", "$", "table", "=", "$", "tableLocator", "->", "get", "(", "$", "table", ")", ";", "}", "$", "source", "=", "$", "this", "->", "getSource", "(", ")", ";", "$", "target", "=", "$", "this", "->", "getTarget", "(", ")", ";", "$", "this", "->", "_generateSourceAssociations", "(", "$", "table", ",", "$", "source", ")", ";", "$", "this", "->", "_generateTargetAssociations", "(", "$", "table", ",", "$", "source", ",", "$", "target", ")", ";", "$", "this", "->", "_generateJunctionAssociations", "(", "$", "table", ",", "$", "source", ",", "$", "target", ")", ";", "return", "$", "this", "->", "_junctionTable", "=", "$", "table", ";", "}" ]
Sets the table instance for the junction relation. If no arguments are passed, the current configured table instance is returned @param string|\Cake\ORM\Table|null $table Name or instance for the join table @return \Cake\ORM\Table
[ "Sets", "the", "table", "instance", "for", "the", "junction", "relation", ".", "If", "no", "arguments", "are", "passed", "the", "current", "configured", "table", "instance", "is", "returned" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L298-L334
211,240
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany._generateTargetAssociations
protected function _generateTargetAssociations($junction, $source, $target) { $junctionAlias = $junction->getAlias(); $sAlias = $source->getAlias(); if (!$target->hasAssociation($junctionAlias)) { $target->hasMany($junctionAlias, [ 'targetTable' => $junction, 'foreignKey' => $this->getTargetForeignKey(), 'strategy' => $this->_strategy, ]); } if (!$target->hasAssociation($sAlias)) { $target->belongsToMany($sAlias, [ 'sourceTable' => $target, 'targetTable' => $source, 'foreignKey' => $this->getTargetForeignKey(), 'targetForeignKey' => $this->getForeignKey(), 'through' => $junction, 'conditions' => $this->getConditions(), 'strategy' => $this->_strategy, ]); } }
php
protected function _generateTargetAssociations($junction, $source, $target) { $junctionAlias = $junction->getAlias(); $sAlias = $source->getAlias(); if (!$target->hasAssociation($junctionAlias)) { $target->hasMany($junctionAlias, [ 'targetTable' => $junction, 'foreignKey' => $this->getTargetForeignKey(), 'strategy' => $this->_strategy, ]); } if (!$target->hasAssociation($sAlias)) { $target->belongsToMany($sAlias, [ 'sourceTable' => $target, 'targetTable' => $source, 'foreignKey' => $this->getTargetForeignKey(), 'targetForeignKey' => $this->getForeignKey(), 'through' => $junction, 'conditions' => $this->getConditions(), 'strategy' => $this->_strategy, ]); } }
[ "protected", "function", "_generateTargetAssociations", "(", "$", "junction", ",", "$", "source", ",", "$", "target", ")", "{", "$", "junctionAlias", "=", "$", "junction", "->", "getAlias", "(", ")", ";", "$", "sAlias", "=", "$", "source", "->", "getAlias", "(", ")", ";", "if", "(", "!", "$", "target", "->", "hasAssociation", "(", "$", "junctionAlias", ")", ")", "{", "$", "target", "->", "hasMany", "(", "$", "junctionAlias", ",", "[", "'targetTable'", "=>", "$", "junction", ",", "'foreignKey'", "=>", "$", "this", "->", "getTargetForeignKey", "(", ")", ",", "'strategy'", "=>", "$", "this", "->", "_strategy", ",", "]", ")", ";", "}", "if", "(", "!", "$", "target", "->", "hasAssociation", "(", "$", "sAlias", ")", ")", "{", "$", "target", "->", "belongsToMany", "(", "$", "sAlias", ",", "[", "'sourceTable'", "=>", "$", "target", ",", "'targetTable'", "=>", "$", "source", ",", "'foreignKey'", "=>", "$", "this", "->", "getTargetForeignKey", "(", ")", ",", "'targetForeignKey'", "=>", "$", "this", "->", "getForeignKey", "(", ")", ",", "'through'", "=>", "$", "junction", ",", "'conditions'", "=>", "$", "this", "->", "getConditions", "(", ")", ",", "'strategy'", "=>", "$", "this", "->", "_strategy", ",", "]", ")", ";", "}", "}" ]
Generate reciprocal associations as necessary. Generates the following associations: - target hasMany junction e.g. Articles hasMany ArticlesTags - target belongsToMany source e.g Articles belongsToMany Tags. You can override these generated associations by defining associations with the correct aliases. @param \Cake\ORM\Table $junction The junction table. @param \Cake\ORM\Table $source The source table. @param \Cake\ORM\Table $target The target table. @return void
[ "Generate", "reciprocal", "associations", "as", "necessary", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L352-L375
211,241
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany._generateSourceAssociations
protected function _generateSourceAssociations($junction, $source) { $junctionAlias = $junction->getAlias(); if (!$source->hasAssociation($junctionAlias)) { $source->hasMany($junctionAlias, [ 'targetTable' => $junction, 'foreignKey' => $this->getForeignKey(), 'strategy' => $this->_strategy, ]); } }
php
protected function _generateSourceAssociations($junction, $source) { $junctionAlias = $junction->getAlias(); if (!$source->hasAssociation($junctionAlias)) { $source->hasMany($junctionAlias, [ 'targetTable' => $junction, 'foreignKey' => $this->getForeignKey(), 'strategy' => $this->_strategy, ]); } }
[ "protected", "function", "_generateSourceAssociations", "(", "$", "junction", ",", "$", "source", ")", "{", "$", "junctionAlias", "=", "$", "junction", "->", "getAlias", "(", ")", ";", "if", "(", "!", "$", "source", "->", "hasAssociation", "(", "$", "junctionAlias", ")", ")", "{", "$", "source", "->", "hasMany", "(", "$", "junctionAlias", ",", "[", "'targetTable'", "=>", "$", "junction", ",", "'foreignKey'", "=>", "$", "this", "->", "getForeignKey", "(", ")", ",", "'strategy'", "=>", "$", "this", "->", "_strategy", ",", "]", ")", ";", "}", "}" ]
Generate additional source table associations as necessary. Generates the following associations: - source hasMany junction e.g. Tags hasMany ArticlesTags You can override these generated associations by defining associations with the correct aliases. @param \Cake\ORM\Table $junction The junction table. @param \Cake\ORM\Table $source The source table. @return void
[ "Generate", "additional", "source", "table", "associations", "as", "necessary", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L391-L401
211,242
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany._generateJunctionAssociations
protected function _generateJunctionAssociations($junction, $source, $target) { $tAlias = $target->getAlias(); $sAlias = $source->getAlias(); if (!$junction->hasAssociation($tAlias)) { $junction->belongsTo($tAlias, [ 'foreignKey' => $this->getTargetForeignKey(), 'targetTable' => $target ]); } if (!$junction->hasAssociation($sAlias)) { $junction->belongsTo($sAlias, [ 'foreignKey' => $this->getForeignKey(), 'targetTable' => $source ]); } }
php
protected function _generateJunctionAssociations($junction, $source, $target) { $tAlias = $target->getAlias(); $sAlias = $source->getAlias(); if (!$junction->hasAssociation($tAlias)) { $junction->belongsTo($tAlias, [ 'foreignKey' => $this->getTargetForeignKey(), 'targetTable' => $target ]); } if (!$junction->hasAssociation($sAlias)) { $junction->belongsTo($sAlias, [ 'foreignKey' => $this->getForeignKey(), 'targetTable' => $source ]); } }
[ "protected", "function", "_generateJunctionAssociations", "(", "$", "junction", ",", "$", "source", ",", "$", "target", ")", "{", "$", "tAlias", "=", "$", "target", "->", "getAlias", "(", ")", ";", "$", "sAlias", "=", "$", "source", "->", "getAlias", "(", ")", ";", "if", "(", "!", "$", "junction", "->", "hasAssociation", "(", "$", "tAlias", ")", ")", "{", "$", "junction", "->", "belongsTo", "(", "$", "tAlias", ",", "[", "'foreignKey'", "=>", "$", "this", "->", "getTargetForeignKey", "(", ")", ",", "'targetTable'", "=>", "$", "target", "]", ")", ";", "}", "if", "(", "!", "$", "junction", "->", "hasAssociation", "(", "$", "sAlias", ")", ")", "{", "$", "junction", "->", "belongsTo", "(", "$", "sAlias", ",", "[", "'foreignKey'", "=>", "$", "this", "->", "getForeignKey", "(", ")", ",", "'targetTable'", "=>", "$", "source", "]", ")", ";", "}", "}" ]
Generate associations on the junction table as necessary Generates the following associations: - junction belongsTo source e.g. ArticlesTags belongsTo Tags - junction belongsTo target e.g. ArticlesTags belongsTo Articles You can override these generated associations by defining associations with the correct aliases. @param \Cake\ORM\Table $junction The junction table. @param \Cake\ORM\Table $source The source table. @param \Cake\ORM\Table $target The target table. @return void
[ "Generate", "associations", "on", "the", "junction", "table", "as", "necessary" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L419-L436
211,243
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany.cascadeDelete
public function cascadeDelete(EntityInterface $entity, array $options = []) { if (!$this->getDependent()) { return true; } $foreignKey = (array)$this->getForeignKey(); $bindingKey = (array)$this->getBindingKey(); $conditions = []; if (!empty($bindingKey)) { $conditions = array_combine($foreignKey, $entity->extract($bindingKey)); } $table = $this->junction(); $hasMany = $this->getSource()->getAssociation($table->getAlias()); if ($this->_cascadeCallbacks) { foreach ($hasMany->find('all')->where($conditions)->all()->toList() as $related) { $table->delete($related, $options); } return true; } $conditions = array_merge($conditions, $hasMany->getConditions()); $table->deleteAll($conditions); return true; }
php
public function cascadeDelete(EntityInterface $entity, array $options = []) { if (!$this->getDependent()) { return true; } $foreignKey = (array)$this->getForeignKey(); $bindingKey = (array)$this->getBindingKey(); $conditions = []; if (!empty($bindingKey)) { $conditions = array_combine($foreignKey, $entity->extract($bindingKey)); } $table = $this->junction(); $hasMany = $this->getSource()->getAssociation($table->getAlias()); if ($this->_cascadeCallbacks) { foreach ($hasMany->find('all')->where($conditions)->all()->toList() as $related) { $table->delete($related, $options); } return true; } $conditions = array_merge($conditions, $hasMany->getConditions()); $table->deleteAll($conditions); return true; }
[ "public", "function", "cascadeDelete", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "getDependent", "(", ")", ")", "{", "return", "true", ";", "}", "$", "foreignKey", "=", "(", "array", ")", "$", "this", "->", "getForeignKey", "(", ")", ";", "$", "bindingKey", "=", "(", "array", ")", "$", "this", "->", "getBindingKey", "(", ")", ";", "$", "conditions", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "bindingKey", ")", ")", "{", "$", "conditions", "=", "array_combine", "(", "$", "foreignKey", ",", "$", "entity", "->", "extract", "(", "$", "bindingKey", ")", ")", ";", "}", "$", "table", "=", "$", "this", "->", "junction", "(", ")", ";", "$", "hasMany", "=", "$", "this", "->", "getSource", "(", ")", "->", "getAssociation", "(", "$", "table", "->", "getAlias", "(", ")", ")", ";", "if", "(", "$", "this", "->", "_cascadeCallbacks", ")", "{", "foreach", "(", "$", "hasMany", "->", "find", "(", "'all'", ")", "->", "where", "(", "$", "conditions", ")", "->", "all", "(", ")", "->", "toList", "(", ")", "as", "$", "related", ")", "{", "$", "table", "->", "delete", "(", "$", "related", ",", "$", "options", ")", ";", "}", "return", "true", ";", "}", "$", "conditions", "=", "array_merge", "(", "$", "conditions", ",", "$", "hasMany", "->", "getConditions", "(", ")", ")", ";", "$", "table", "->", "deleteAll", "(", "$", "conditions", ")", ";", "return", "true", ";", "}" ]
Clear out the data in the junction table for a given entity. @param \Cake\Datasource\EntityInterface $entity The entity that started the cascading delete. @param array $options The options for the original delete. @return bool Success.
[ "Clear", "out", "the", "data", "in", "the", "junction", "table", "for", "a", "given", "entity", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L595-L623
211,244
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany.setSaveStrategy
public function setSaveStrategy($strategy) { if (!in_array($strategy, [self::SAVE_APPEND, self::SAVE_REPLACE])) { $msg = sprintf('Invalid save strategy "%s"', $strategy); throw new InvalidArgumentException($msg); } $this->_saveStrategy = $strategy; return $this; }
php
public function setSaveStrategy($strategy) { if (!in_array($strategy, [self::SAVE_APPEND, self::SAVE_REPLACE])) { $msg = sprintf('Invalid save strategy "%s"', $strategy); throw new InvalidArgumentException($msg); } $this->_saveStrategy = $strategy; return $this; }
[ "public", "function", "setSaveStrategy", "(", "$", "strategy", ")", "{", "if", "(", "!", "in_array", "(", "$", "strategy", ",", "[", "self", "::", "SAVE_APPEND", ",", "self", "::", "SAVE_REPLACE", "]", ")", ")", "{", "$", "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
[ "Sets", "the", "strategy", "that", "should", "be", "used", "for", "saving", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L644-L654
211,245
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany.saveStrategy
public function saveStrategy($strategy = null) { deprecationWarning( 'BelongsToMany::saveStrategy() is deprecated. ' . 'Use setSaveStrategy()/getSaveStrategy() instead.' ); if ($strategy !== null) { $this->setSaveStrategy($strategy); } return $this->getSaveStrategy(); }
php
public function saveStrategy($strategy = null) { deprecationWarning( 'BelongsToMany::saveStrategy() is deprecated. ' . 'Use setSaveStrategy()/getSaveStrategy() instead.' ); if ($strategy !== null) { $this->setSaveStrategy($strategy); } return $this->getSaveStrategy(); }
[ "public", "function", "saveStrategy", "(", "$", "strategy", "=", "null", ")", "{", "deprecationWarning", "(", "'BelongsToMany::saveStrategy() is deprecated. '", ".", "'Use setSaveStrategy()/getSaveStrategy() instead.'", ")", ";", "if", "(", "$", "strategy", "!==", "null", ")", "{", "$", "this", "->", "setSaveStrategy", "(", "$", "strategy", ")", ";", "}", "return", "$", "this", "->", "getSaveStrategy", "(", ")", ";", "}" ]
Sets the strategy that should be used for saving. If called with no arguments, it will return the currently configured strategy @deprecated 3.4.0 Use setSaveStrategy()/getSaveStrategy() instead. @param string|null $strategy the strategy name to be used @throws \InvalidArgumentException if an invalid strategy name is passed @return string the strategy to be used for saving
[ "Sets", "the", "strategy", "that", "should", "be", "used", "for", "saving", ".", "If", "called", "with", "no", "arguments", "it", "will", "return", "the", "currently", "configured", "strategy" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L675-L686
211,246
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany._saveLinks
protected function _saveLinks(EntityInterface $sourceEntity, $targetEntities, $options) { $target = $this->getTarget(); $junction = $this->junction(); $entityClass = $junction->getEntityClass(); $belongsTo = $junction->getAssociation($target->getAlias()); $foreignKey = (array)$this->getForeignKey(); $assocForeignKey = (array)$belongsTo->getForeignKey(); $targetPrimaryKey = (array)$target->getPrimaryKey(); $bindingKey = (array)$this->getBindingKey(); $jointProperty = $this->_junctionProperty; $junctionRegistryAlias = $junction->getRegistryAlias(); foreach ($targetEntities as $e) { $joint = $e->get($jointProperty); if (!$joint || !($joint instanceof EntityInterface)) { $joint = new $entityClass([], ['markNew' => true, 'source' => $junctionRegistryAlias]); } $sourceKeys = array_combine($foreignKey, $sourceEntity->extract($bindingKey)); $targetKeys = array_combine($assocForeignKey, $e->extract($targetPrimaryKey)); $changedKeys = ( $sourceKeys !== $joint->extract($foreignKey) || $targetKeys !== $joint->extract($assocForeignKey) ); // Keys were changed, the junction table record _could_ be // new. By clearing the primary key values, and marking the entity // as new, we let save() sort out whether or not we have a new link // or if we are updating an existing link. if ($changedKeys) { $joint->isNew(true); $joint->unsetProperty($junction->getPrimaryKey()) ->set(array_merge($sourceKeys, $targetKeys), ['guard' => false]); } $saved = $junction->save($joint, $options); if (!$saved && !empty($options['atomic'])) { return false; } $e->set($jointProperty, $joint); $e->setDirty($jointProperty, false); } return true; }
php
protected function _saveLinks(EntityInterface $sourceEntity, $targetEntities, $options) { $target = $this->getTarget(); $junction = $this->junction(); $entityClass = $junction->getEntityClass(); $belongsTo = $junction->getAssociation($target->getAlias()); $foreignKey = (array)$this->getForeignKey(); $assocForeignKey = (array)$belongsTo->getForeignKey(); $targetPrimaryKey = (array)$target->getPrimaryKey(); $bindingKey = (array)$this->getBindingKey(); $jointProperty = $this->_junctionProperty; $junctionRegistryAlias = $junction->getRegistryAlias(); foreach ($targetEntities as $e) { $joint = $e->get($jointProperty); if (!$joint || !($joint instanceof EntityInterface)) { $joint = new $entityClass([], ['markNew' => true, 'source' => $junctionRegistryAlias]); } $sourceKeys = array_combine($foreignKey, $sourceEntity->extract($bindingKey)); $targetKeys = array_combine($assocForeignKey, $e->extract($targetPrimaryKey)); $changedKeys = ( $sourceKeys !== $joint->extract($foreignKey) || $targetKeys !== $joint->extract($assocForeignKey) ); // Keys were changed, the junction table record _could_ be // new. By clearing the primary key values, and marking the entity // as new, we let save() sort out whether or not we have a new link // or if we are updating an existing link. if ($changedKeys) { $joint->isNew(true); $joint->unsetProperty($junction->getPrimaryKey()) ->set(array_merge($sourceKeys, $targetKeys), ['guard' => false]); } $saved = $junction->save($joint, $options); if (!$saved && !empty($options['atomic'])) { return false; } $e->set($jointProperty, $joint); $e->setDirty($jointProperty, false); } return true; }
[ "protected", "function", "_saveLinks", "(", "EntityInterface", "$", "sourceEntity", ",", "$", "targetEntities", ",", "$", "options", ")", "{", "$", "target", "=", "$", "this", "->", "getTarget", "(", ")", ";", "$", "junction", "=", "$", "this", "->", "junction", "(", ")", ";", "$", "entityClass", "=", "$", "junction", "->", "getEntityClass", "(", ")", ";", "$", "belongsTo", "=", "$", "junction", "->", "getAssociation", "(", "$", "target", "->", "getAlias", "(", ")", ")", ";", "$", "foreignKey", "=", "(", "array", ")", "$", "this", "->", "getForeignKey", "(", ")", ";", "$", "assocForeignKey", "=", "(", "array", ")", "$", "belongsTo", "->", "getForeignKey", "(", ")", ";", "$", "targetPrimaryKey", "=", "(", "array", ")", "$", "target", "->", "getPrimaryKey", "(", ")", ";", "$", "bindingKey", "=", "(", "array", ")", "$", "this", "->", "getBindingKey", "(", ")", ";", "$", "jointProperty", "=", "$", "this", "->", "_junctionProperty", ";", "$", "junctionRegistryAlias", "=", "$", "junction", "->", "getRegistryAlias", "(", ")", ";", "foreach", "(", "$", "targetEntities", "as", "$", "e", ")", "{", "$", "joint", "=", "$", "e", "->", "get", "(", "$", "jointProperty", ")", ";", "if", "(", "!", "$", "joint", "||", "!", "(", "$", "joint", "instanceof", "EntityInterface", ")", ")", "{", "$", "joint", "=", "new", "$", "entityClass", "(", "[", "]", ",", "[", "'markNew'", "=>", "true", ",", "'source'", "=>", "$", "junctionRegistryAlias", "]", ")", ";", "}", "$", "sourceKeys", "=", "array_combine", "(", "$", "foreignKey", ",", "$", "sourceEntity", "->", "extract", "(", "$", "bindingKey", ")", ")", ";", "$", "targetKeys", "=", "array_combine", "(", "$", "assocForeignKey", ",", "$", "e", "->", "extract", "(", "$", "targetPrimaryKey", ")", ")", ";", "$", "changedKeys", "=", "(", "$", "sourceKeys", "!==", "$", "joint", "->", "extract", "(", "$", "foreignKey", ")", "||", "$", "targetKeys", "!==", "$", "joint", "->", "extract", "(", "$", "assocForeignKey", ")", ")", ";", "// Keys were changed, the junction table record _could_ be", "// new. By clearing the primary key values, and marking the entity", "// as new, we let save() sort out whether or not we have a new link", "// or if we are updating an existing link.", "if", "(", "$", "changedKeys", ")", "{", "$", "joint", "->", "isNew", "(", "true", ")", ";", "$", "joint", "->", "unsetProperty", "(", "$", "junction", "->", "getPrimaryKey", "(", ")", ")", "->", "set", "(", "array_merge", "(", "$", "sourceKeys", ",", "$", "targetKeys", ")", ",", "[", "'guard'", "=>", "false", "]", ")", ";", "}", "$", "saved", "=", "$", "junction", "->", "save", "(", "$", "joint", ",", "$", "options", ")", ";", "if", "(", "!", "$", "saved", "&&", "!", "empty", "(", "$", "options", "[", "'atomic'", "]", ")", ")", "{", "return", "false", ";", "}", "$", "e", "->", "set", "(", "$", "jointProperty", ",", "$", "joint", ")", ";", "$", "e", "->", "setDirty", "(", "$", "jointProperty", ",", "false", ")", ";", "}", "return", "true", ";", "}" ]
Creates links between the source entity and each of the passed target entities @param \Cake\Datasource\EntityInterface $sourceEntity the entity from source table in this association @param array $targetEntities list of entities to link to link to the source entity using the junction table @param array $options list of options accepted by `Table::save()` @return bool success
[ "Creates", "links", "between", "the", "source", "entity", "and", "each", "of", "the", "passed", "target", "entities" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L817-L862
211,247
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany.link
public function link(EntityInterface $sourceEntity, array $targetEntities, array $options = []) { $this->_checkPersistenceStatus($sourceEntity, $targetEntities); $property = $this->getProperty(); $links = $sourceEntity->get($property) ?: []; $links = array_merge($links, $targetEntities); $sourceEntity->set($property, $links); return $this->junction()->getConnection()->transactional( function () use ($sourceEntity, $targetEntities, $options) { return $this->_saveLinks($sourceEntity, $targetEntities, $options); } ); }
php
public function link(EntityInterface $sourceEntity, array $targetEntities, array $options = []) { $this->_checkPersistenceStatus($sourceEntity, $targetEntities); $property = $this->getProperty(); $links = $sourceEntity->get($property) ?: []; $links = array_merge($links, $targetEntities); $sourceEntity->set($property, $links); return $this->junction()->getConnection()->transactional( function () use ($sourceEntity, $targetEntities, $options) { return $this->_saveLinks($sourceEntity, $targetEntities, $options); } ); }
[ "public", "function", "link", "(", "EntityInterface", "$", "sourceEntity", ",", "array", "$", "targetEntities", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "_checkPersistenceStatus", "(", "$", "sourceEntity", ",", "$", "targetEntities", ")", ";", "$", "property", "=", "$", "this", "->", "getProperty", "(", ")", ";", "$", "links", "=", "$", "sourceEntity", "->", "get", "(", "$", "property", ")", "?", ":", "[", "]", ";", "$", "links", "=", "array_merge", "(", "$", "links", ",", "$", "targetEntities", ")", ";", "$", "sourceEntity", "->", "set", "(", "$", "property", ",", "$", "links", ")", ";", "return", "$", "this", "->", "junction", "(", ")", "->", "getConnection", "(", ")", "->", "transactional", "(", "function", "(", ")", "use", "(", "$", "sourceEntity", ",", "$", "targetEntities", ",", "$", "options", ")", "{", "return", "$", "this", "->", "_saveLinks", "(", "$", "sourceEntity", ",", "$", "targetEntities", ",", "$", "options", ")", ";", "}", ")", ";", "}" ]
Associates the source entity to each of the target entities provided by creating links in the junction table. Both the source entity and each of the target entities are assumed to be already persisted, if they are marked as new or their status is unknown then an exception will be thrown. When using this method, all entities in `$targetEntities` will be appended to the source entity's property corresponding to this association object. This method does not check link uniqueness. ### Example: ``` $newTags = $tags->find('relevant')->toArray(); $articles->getAssociation('tags')->link($article, $newTags); ``` `$article->get('tags')` will contain all tags in `$newTags` after liking @param \Cake\Datasource\EntityInterface $sourceEntity the row belonging to the `source` side of this association @param array $targetEntities list of entities belonging to the `target` side of this association @param array $options list of options to be passed to the internal `save` call @throws \InvalidArgumentException when any of the values in $targetEntities is detected to not be already persisted @return bool true on success, false otherwise
[ "Associates", "the", "source", "entity", "to", "each", "of", "the", "target", "entities", "provided", "by", "creating", "links", "in", "the", "junction", "table", ".", "Both", "the", "source", "entity", "and", "each", "of", "the", "target", "entities", "are", "assumed", "to", "be", "already", "persisted", "if", "they", "are", "marked", "as", "new", "or", "their", "status", "is", "unknown", "then", "an", "exception", "will", "be", "thrown", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L893-L906
211,248
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany.targetConditions
protected function targetConditions() { if ($this->_targetConditions !== null) { return $this->_targetConditions; } $conditions = $this->getConditions(); if (!is_array($conditions)) { return $conditions; } $matching = []; $alias = $this->getAlias() . '.'; foreach ($conditions as $field => $value) { if (is_string($field) && strpos($field, $alias) === 0) { $matching[$field] = $value; } elseif (is_int($field) || $value instanceof ExpressionInterface) { $matching[$field] = $value; } } return $this->_targetConditions = $matching; }
php
protected function targetConditions() { if ($this->_targetConditions !== null) { return $this->_targetConditions; } $conditions = $this->getConditions(); if (!is_array($conditions)) { return $conditions; } $matching = []; $alias = $this->getAlias() . '.'; foreach ($conditions as $field => $value) { if (is_string($field) && strpos($field, $alias) === 0) { $matching[$field] = $value; } elseif (is_int($field) || $value instanceof ExpressionInterface) { $matching[$field] = $value; } } return $this->_targetConditions = $matching; }
[ "protected", "function", "targetConditions", "(", ")", "{", "if", "(", "$", "this", "->", "_targetConditions", "!==", "null", ")", "{", "return", "$", "this", "->", "_targetConditions", ";", "}", "$", "conditions", "=", "$", "this", "->", "getConditions", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "conditions", ")", ")", "{", "return", "$", "conditions", ";", "}", "$", "matching", "=", "[", "]", ";", "$", "alias", "=", "$", "this", "->", "getAlias", "(", ")", ".", "'.'", ";", "foreach", "(", "$", "conditions", "as", "$", "field", "=>", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "field", ")", "&&", "strpos", "(", "$", "field", ",", "$", "alias", ")", "===", "0", ")", "{", "$", "matching", "[", "$", "field", "]", "=", "$", "value", ";", "}", "elseif", "(", "is_int", "(", "$", "field", ")", "||", "$", "value", "instanceof", "ExpressionInterface", ")", "{", "$", "matching", "[", "$", "field", "]", "=", "$", "value", ";", "}", "}", "return", "$", "this", "->", "_targetConditions", "=", "$", "matching", ";", "}" ]
Returns filtered conditions that reference the target table. Any string expressions, or expression objects will also be returned in this list. @return mixed Generally an array. If the conditions are not an array, the association conditions will be returned unmodified.
[ "Returns", "filtered", "conditions", "that", "reference", "the", "target", "table", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L1032-L1052
211,249
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany.junctionConditions
protected function junctionConditions() { if ($this->_junctionConditions !== null) { return $this->_junctionConditions; } $matching = []; $conditions = $this->getConditions(); if (!is_array($conditions)) { return $matching; } $alias = $this->_junctionAssociationName() . '.'; foreach ($conditions as $field => $value) { $isString = is_string($field); if ($isString && strpos($field, $alias) === 0) { $matching[$field] = $value; } // Assume that operators contain junction conditions. // Trying to manage complex conditions could result in incorrect queries. if ($isString && in_array(strtoupper($field), ['OR', 'NOT', 'AND', 'XOR'])) { $matching[$field] = $value; } } return $this->_junctionConditions = $matching; }
php
protected function junctionConditions() { if ($this->_junctionConditions !== null) { return $this->_junctionConditions; } $matching = []; $conditions = $this->getConditions(); if (!is_array($conditions)) { return $matching; } $alias = $this->_junctionAssociationName() . '.'; foreach ($conditions as $field => $value) { $isString = is_string($field); if ($isString && strpos($field, $alias) === 0) { $matching[$field] = $value; } // Assume that operators contain junction conditions. // Trying to manage complex conditions could result in incorrect queries. if ($isString && in_array(strtoupper($field), ['OR', 'NOT', 'AND', 'XOR'])) { $matching[$field] = $value; } } return $this->_junctionConditions = $matching; }
[ "protected", "function", "junctionConditions", "(", ")", "{", "if", "(", "$", "this", "->", "_junctionConditions", "!==", "null", ")", "{", "return", "$", "this", "->", "_junctionConditions", ";", "}", "$", "matching", "=", "[", "]", ";", "$", "conditions", "=", "$", "this", "->", "getConditions", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "conditions", ")", ")", "{", "return", "$", "matching", ";", "}", "$", "alias", "=", "$", "this", "->", "_junctionAssociationName", "(", ")", ".", "'.'", ";", "foreach", "(", "$", "conditions", "as", "$", "field", "=>", "$", "value", ")", "{", "$", "isString", "=", "is_string", "(", "$", "field", ")", ";", "if", "(", "$", "isString", "&&", "strpos", "(", "$", "field", ",", "$", "alias", ")", "===", "0", ")", "{", "$", "matching", "[", "$", "field", "]", "=", "$", "value", ";", "}", "// Assume that operators contain junction conditions.", "// Trying to manage complex conditions could result in incorrect queries.", "if", "(", "$", "isString", "&&", "in_array", "(", "strtoupper", "(", "$", "field", ")", ",", "[", "'OR'", ",", "'NOT'", ",", "'AND'", ",", "'XOR'", "]", ")", ")", "{", "$", "matching", "[", "$", "field", "]", "=", "$", "value", ";", "}", "}", "return", "$", "this", "->", "_junctionConditions", "=", "$", "matching", ";", "}" ]
Returns filtered conditions that specifically reference the junction table. @return array
[ "Returns", "filtered", "conditions", "that", "specifically", "reference", "the", "junction", "table", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L1060-L1084
211,250
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany.find
public function find($type = null, array $options = []) { $type = $type ?: $this->getFinder(); list($type, $opts) = $this->_extractFinder($type); $query = $this->getTarget() ->find($type, $options + $opts) ->where($this->targetConditions()) ->addDefaultTypes($this->getTarget()); if (!$this->junctionConditions()) { return $query; } $belongsTo = $this->junction()->getAssociation($this->getTarget()->getAlias()); $conditions = $belongsTo->_joinCondition([ 'foreignKey' => $this->getTargetForeignKey() ]); $conditions += $this->junctionConditions(); return $this->_appendJunctionJoin($query, $conditions); }
php
public function find($type = null, array $options = []) { $type = $type ?: $this->getFinder(); list($type, $opts) = $this->_extractFinder($type); $query = $this->getTarget() ->find($type, $options + $opts) ->where($this->targetConditions()) ->addDefaultTypes($this->getTarget()); if (!$this->junctionConditions()) { return $query; } $belongsTo = $this->junction()->getAssociation($this->getTarget()->getAlias()); $conditions = $belongsTo->_joinCondition([ 'foreignKey' => $this->getTargetForeignKey() ]); $conditions += $this->junctionConditions(); return $this->_appendJunctionJoin($query, $conditions); }
[ "public", "function", "find", "(", "$", "type", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "type", "=", "$", "type", "?", ":", "$", "this", "->", "getFinder", "(", ")", ";", "list", "(", "$", "type", ",", "$", "opts", ")", "=", "$", "this", "->", "_extractFinder", "(", "$", "type", ")", ";", "$", "query", "=", "$", "this", "->", "getTarget", "(", ")", "->", "find", "(", "$", "type", ",", "$", "options", "+", "$", "opts", ")", "->", "where", "(", "$", "this", "->", "targetConditions", "(", ")", ")", "->", "addDefaultTypes", "(", "$", "this", "->", "getTarget", "(", ")", ")", ";", "if", "(", "!", "$", "this", "->", "junctionConditions", "(", ")", ")", "{", "return", "$", "query", ";", "}", "$", "belongsTo", "=", "$", "this", "->", "junction", "(", ")", "->", "getAssociation", "(", "$", "this", "->", "getTarget", "(", ")", "->", "getAlias", "(", ")", ")", ";", "$", "conditions", "=", "$", "belongsTo", "->", "_joinCondition", "(", "[", "'foreignKey'", "=>", "$", "this", "->", "getTargetForeignKey", "(", ")", "]", ")", ";", "$", "conditions", "+=", "$", "this", "->", "junctionConditions", "(", ")", ";", "return", "$", "this", "->", "_appendJunctionJoin", "(", "$", "query", ",", "$", "conditions", ")", ";", "}" ]
Proxies the finding operation to the target table's find method and modifies the query accordingly based of this association configuration. If your association includes conditions, the junction table will be included in the query's contained associations. @param string|array|null $type the type of query to perform, if an array is passed, it will be interpreted as the `$options` parameter @param array $options The options to for the find @see \Cake\ORM\Table::find() @return \Cake\ORM\Query
[ "Proxies", "the", "finding", "operation", "to", "the", "target", "table", "s", "find", "method", "and", "modifies", "the", "query", "accordingly", "based", "of", "this", "association", "configuration", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L1100-L1120
211,251
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany._appendJunctionJoin
protected function _appendJunctionJoin($query, $conditions) { $name = $this->_junctionAssociationName(); /** @var array $joins */ $joins = $query->clause('join'); $matching = [ $name => [ 'table' => $this->junction()->getTable(), 'conditions' => $conditions, 'type' => QueryInterface::JOIN_TYPE_INNER ] ]; $assoc = $this->getTarget()->getAssociation($name); $query ->addDefaultTypes($assoc->getTarget()) ->join($matching + $joins, [], true); return $query; }
php
protected function _appendJunctionJoin($query, $conditions) { $name = $this->_junctionAssociationName(); /** @var array $joins */ $joins = $query->clause('join'); $matching = [ $name => [ 'table' => $this->junction()->getTable(), 'conditions' => $conditions, 'type' => QueryInterface::JOIN_TYPE_INNER ] ]; $assoc = $this->getTarget()->getAssociation($name); $query ->addDefaultTypes($assoc->getTarget()) ->join($matching + $joins, [], true); return $query; }
[ "protected", "function", "_appendJunctionJoin", "(", "$", "query", ",", "$", "conditions", ")", "{", "$", "name", "=", "$", "this", "->", "_junctionAssociationName", "(", ")", ";", "/** @var array $joins */", "$", "joins", "=", "$", "query", "->", "clause", "(", "'join'", ")", ";", "$", "matching", "=", "[", "$", "name", "=>", "[", "'table'", "=>", "$", "this", "->", "junction", "(", ")", "->", "getTable", "(", ")", ",", "'conditions'", "=>", "$", "conditions", ",", "'type'", "=>", "QueryInterface", "::", "JOIN_TYPE_INNER", "]", "]", ";", "$", "assoc", "=", "$", "this", "->", "getTarget", "(", ")", "->", "getAssociation", "(", "$", "name", ")", ";", "$", "query", "->", "addDefaultTypes", "(", "$", "assoc", "->", "getTarget", "(", ")", ")", "->", "join", "(", "$", "matching", "+", "$", "joins", ",", "[", "]", ",", "true", ")", ";", "return", "$", "query", ";", "}" ]
Append a join to the junction table. @param \Cake\ORM\Query $query The query to append. @param string|array $conditions The query conditions to use. @return \Cake\ORM\Query The modified query.
[ "Append", "a", "join", "to", "the", "junction", "table", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L1129-L1148
211,252
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany._checkPersistenceStatus
protected function _checkPersistenceStatus($sourceEntity, array $targetEntities) { if ($sourceEntity->isNew()) { $error = 'Source entity needs to be persisted before links can be created or removed.'; throw new InvalidArgumentException($error); } foreach ($targetEntities as $entity) { if ($entity->isNew()) { $error = 'Cannot link entities that have not been persisted yet.'; throw new InvalidArgumentException($error); } } return true; }
php
protected function _checkPersistenceStatus($sourceEntity, array $targetEntities) { if ($sourceEntity->isNew()) { $error = 'Source entity needs to be persisted before links can be created or removed.'; throw new InvalidArgumentException($error); } foreach ($targetEntities as $entity) { if ($entity->isNew()) { $error = 'Cannot link entities that have not been persisted yet.'; throw new InvalidArgumentException($error); } } return true; }
[ "protected", "function", "_checkPersistenceStatus", "(", "$", "sourceEntity", ",", "array", "$", "targetEntities", ")", "{", "if", "(", "$", "sourceEntity", "->", "isNew", "(", ")", ")", "{", "$", "error", "=", "'Source entity needs to be persisted before links can be created or removed.'", ";", "throw", "new", "InvalidArgumentException", "(", "$", "error", ")", ";", "}", "foreach", "(", "$", "targetEntities", "as", "$", "entity", ")", "{", "if", "(", "$", "entity", "->", "isNew", "(", ")", ")", "{", "$", "error", "=", "'Cannot link entities that have not been persisted yet.'", ";", "throw", "new", "InvalidArgumentException", "(", "$", "error", ")", ";", "}", "}", "return", "true", ";", "}" ]
Throws an exception should any of the passed entities is not persisted. @param \Cake\Datasource\EntityInterface $sourceEntity the row belonging to the `source` side of this association @param array $targetEntities list of entities belonging to the `target` side of this association @return bool @throws \InvalidArgumentException
[ "Throws", "an", "exception", "should", "any", "of", "the", "passed", "entities", "is", "not", "persisted", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L1326-L1341
211,253
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany._collectJointEntities
protected function _collectJointEntities($sourceEntity, $targetEntities) { $target = $this->getTarget(); $source = $this->getSource(); $junction = $this->junction(); $jointProperty = $this->_junctionProperty; $primary = (array)$target->getPrimaryKey(); $result = []; $missing = []; foreach ($targetEntities as $entity) { if (!($entity instanceof EntityInterface)) { continue; } $joint = $entity->get($jointProperty); if (!$joint || !($joint instanceof EntityInterface)) { $missing[] = $entity->extract($primary); continue; } $result[] = $joint; } if (empty($missing)) { return $result; } $belongsTo = $junction->getAssociation($target->getAlias()); $hasMany = $source->getAssociation($junction->getAlias()); $foreignKey = (array)$this->getForeignKey(); $assocForeignKey = (array)$belongsTo->getForeignKey(); $sourceKey = $sourceEntity->extract((array)$source->getPrimaryKey()); $unions = []; foreach ($missing as $key) { $unions[] = $hasMany->find('all') ->where(array_combine($foreignKey, $sourceKey)) ->andWhere(array_combine($assocForeignKey, $key)); } $query = array_shift($unions); foreach ($unions as $q) { $query->union($q); } return array_merge($result, $query->toArray()); }
php
protected function _collectJointEntities($sourceEntity, $targetEntities) { $target = $this->getTarget(); $source = $this->getSource(); $junction = $this->junction(); $jointProperty = $this->_junctionProperty; $primary = (array)$target->getPrimaryKey(); $result = []; $missing = []; foreach ($targetEntities as $entity) { if (!($entity instanceof EntityInterface)) { continue; } $joint = $entity->get($jointProperty); if (!$joint || !($joint instanceof EntityInterface)) { $missing[] = $entity->extract($primary); continue; } $result[] = $joint; } if (empty($missing)) { return $result; } $belongsTo = $junction->getAssociation($target->getAlias()); $hasMany = $source->getAssociation($junction->getAlias()); $foreignKey = (array)$this->getForeignKey(); $assocForeignKey = (array)$belongsTo->getForeignKey(); $sourceKey = $sourceEntity->extract((array)$source->getPrimaryKey()); $unions = []; foreach ($missing as $key) { $unions[] = $hasMany->find('all') ->where(array_combine($foreignKey, $sourceKey)) ->andWhere(array_combine($assocForeignKey, $key)); } $query = array_shift($unions); foreach ($unions as $q) { $query->union($q); } return array_merge($result, $query->toArray()); }
[ "protected", "function", "_collectJointEntities", "(", "$", "sourceEntity", ",", "$", "targetEntities", ")", "{", "$", "target", "=", "$", "this", "->", "getTarget", "(", ")", ";", "$", "source", "=", "$", "this", "->", "getSource", "(", ")", ";", "$", "junction", "=", "$", "this", "->", "junction", "(", ")", ";", "$", "jointProperty", "=", "$", "this", "->", "_junctionProperty", ";", "$", "primary", "=", "(", "array", ")", "$", "target", "->", "getPrimaryKey", "(", ")", ";", "$", "result", "=", "[", "]", ";", "$", "missing", "=", "[", "]", ";", "foreach", "(", "$", "targetEntities", "as", "$", "entity", ")", "{", "if", "(", "!", "(", "$", "entity", "instanceof", "EntityInterface", ")", ")", "{", "continue", ";", "}", "$", "joint", "=", "$", "entity", "->", "get", "(", "$", "jointProperty", ")", ";", "if", "(", "!", "$", "joint", "||", "!", "(", "$", "joint", "instanceof", "EntityInterface", ")", ")", "{", "$", "missing", "[", "]", "=", "$", "entity", "->", "extract", "(", "$", "primary", ")", ";", "continue", ";", "}", "$", "result", "[", "]", "=", "$", "joint", ";", "}", "if", "(", "empty", "(", "$", "missing", ")", ")", "{", "return", "$", "result", ";", "}", "$", "belongsTo", "=", "$", "junction", "->", "getAssociation", "(", "$", "target", "->", "getAlias", "(", ")", ")", ";", "$", "hasMany", "=", "$", "source", "->", "getAssociation", "(", "$", "junction", "->", "getAlias", "(", ")", ")", ";", "$", "foreignKey", "=", "(", "array", ")", "$", "this", "->", "getForeignKey", "(", ")", ";", "$", "assocForeignKey", "=", "(", "array", ")", "$", "belongsTo", "->", "getForeignKey", "(", ")", ";", "$", "sourceKey", "=", "$", "sourceEntity", "->", "extract", "(", "(", "array", ")", "$", "source", "->", "getPrimaryKey", "(", ")", ")", ";", "$", "unions", "=", "[", "]", ";", "foreach", "(", "$", "missing", "as", "$", "key", ")", "{", "$", "unions", "[", "]", "=", "$", "hasMany", "->", "find", "(", "'all'", ")", "->", "where", "(", "array_combine", "(", "$", "foreignKey", ",", "$", "sourceKey", ")", ")", "->", "andWhere", "(", "array_combine", "(", "$", "assocForeignKey", ",", "$", "key", ")", ")", ";", "}", "$", "query", "=", "array_shift", "(", "$", "unions", ")", ";", "foreach", "(", "$", "unions", "as", "$", "q", ")", "{", "$", "query", "->", "union", "(", "$", "q", ")", ";", "}", "return", "array_merge", "(", "$", "result", ",", "$", "query", "->", "toArray", "(", ")", ")", ";", "}" ]
Returns the list of joint entities that exist between the source entity and each of the passed target entities @param \Cake\Datasource\EntityInterface $sourceEntity The row belonging to the source side of this association. @param array $targetEntities The rows belonging to the target side of this association. @throws \InvalidArgumentException if any of the entities is lacking a primary key value @return array
[ "Returns", "the", "list", "of", "joint", "entities", "that", "exist", "between", "the", "source", "entity", "and", "each", "of", "the", "passed", "target", "entities" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L1355-L1403
211,254
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany._junctionAssociationName
protected function _junctionAssociationName() { if (!$this->_junctionAssociationName) { $this->_junctionAssociationName = $this->getTarget() ->getAssociation($this->junction()->getAlias()) ->getName(); } return $this->_junctionAssociationName; }
php
protected function _junctionAssociationName() { if (!$this->_junctionAssociationName) { $this->_junctionAssociationName = $this->getTarget() ->getAssociation($this->junction()->getAlias()) ->getName(); } return $this->_junctionAssociationName; }
[ "protected", "function", "_junctionAssociationName", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_junctionAssociationName", ")", "{", "$", "this", "->", "_junctionAssociationName", "=", "$", "this", "->", "getTarget", "(", ")", "->", "getAssociation", "(", "$", "this", "->", "junction", "(", ")", "->", "getAlias", "(", ")", ")", "->", "getName", "(", ")", ";", "}", "return", "$", "this", "->", "_junctionAssociationName", ";", "}" ]
Returns the name of the association from the target table to the junction table, this name is used to generate alias in the query and to later on retrieve the results. @return string
[ "Returns", "the", "name", "of", "the", "association", "from", "the", "target", "table", "to", "the", "junction", "table", "this", "name", "is", "used", "to", "generate", "alias", "in", "the", "query", "and", "to", "later", "on", "retrieve", "the", "results", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L1412-L1421
211,255
cakephp/cakephp
src/ORM/Association/BelongsToMany.php
BelongsToMany._junctionTableName
protected function _junctionTableName($name = null) { if ($name === null) { if (empty($this->_junctionTableName)) { $tablesNames = array_map('Cake\Utility\Inflector::underscore', [ $this->getSource()->getTable(), $this->getTarget()->getTable() ]); sort($tablesNames); $this->_junctionTableName = implode('_', $tablesNames); } return $this->_junctionTableName; } return $this->_junctionTableName = $name; }
php
protected function _junctionTableName($name = null) { if ($name === null) { if (empty($this->_junctionTableName)) { $tablesNames = array_map('Cake\Utility\Inflector::underscore', [ $this->getSource()->getTable(), $this->getTarget()->getTable() ]); sort($tablesNames); $this->_junctionTableName = implode('_', $tablesNames); } return $this->_junctionTableName; } return $this->_junctionTableName = $name; }
[ "protected", "function", "_junctionTableName", "(", "$", "name", "=", "null", ")", "{", "if", "(", "$", "name", "===", "null", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_junctionTableName", ")", ")", "{", "$", "tablesNames", "=", "array_map", "(", "'Cake\\Utility\\Inflector::underscore'", ",", "[", "$", "this", "->", "getSource", "(", ")", "->", "getTable", "(", ")", ",", "$", "this", "->", "getTarget", "(", ")", "->", "getTable", "(", ")", "]", ")", ";", "sort", "(", "$", "tablesNames", ")", ";", "$", "this", "->", "_junctionTableName", "=", "implode", "(", "'_'", ",", "$", "tablesNames", ")", ";", "}", "return", "$", "this", "->", "_junctionTableName", ";", "}", "return", "$", "this", "->", "_junctionTableName", "=", "$", "name", ";", "}" ]
Sets the name of the junction table. If no arguments are passed the current configured name is returned. A default name based of the associated tables will be generated if none found. @param string|null $name The name of the junction table. @return string
[ "Sets", "the", "name", "of", "the", "junction", "table", ".", "If", "no", "arguments", "are", "passed", "the", "current", "configured", "name", "is", "returned", ".", "A", "default", "name", "based", "of", "the", "associated", "tables", "will", "be", "generated", "if", "none", "found", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/BelongsToMany.php#L1431-L1447
211,256
cakephp/cakephp
src/Database/Dialect/SqlserverDialectTrait.php
SqlserverDialectTrait._pagingSubquery
protected function _pagingSubquery($original, $limit, $offset) { $field = '_cake_paging_._cake_page_rownum_'; if ($original->clause('order')) { // SQL server does not support column aliases in OVER clauses. But // the only practical way to specify the use of calculated columns // is with their alias. So substitute the select SQL in place of // any column aliases for those entries in the order clause. $select = $original->clause('select'); $order = new OrderByExpression(); $original ->clause('order') ->iterateParts(function ($direction, $orderBy) use ($select, $order) { $key = $orderBy; if (isset($select[$orderBy]) && $select[$orderBy] instanceof ExpressionInterface ) { $key = $select[$orderBy]->sql(new ValueBinder()); } $order->add([$key => $direction]); // Leave original order clause unchanged. return $orderBy; }); } else { $order = new OrderByExpression('(SELECT NULL)'); } $query = clone $original; $query->select([ '_cake_page_rownum_' => new UnaryExpression('ROW_NUMBER() OVER', $order) ])->limit(null) ->offset(null) ->order([], true); $outer = new Query($query->getConnection()); $outer->select('*') ->from(['_cake_paging_' => $query]); if ($offset) { $outer->where(["$field > " . (int)$offset]); } if ($limit) { $value = (int)$offset + (int)$limit; $outer->where(["$field <= $value"]); } // Decorate the original query as that is what the // end developer will be calling execute() on originally. $original->decorateResults(function ($row) { if (isset($row['_cake_page_rownum_'])) { unset($row['_cake_page_rownum_']); } return $row; }); return $outer; }
php
protected function _pagingSubquery($original, $limit, $offset) { $field = '_cake_paging_._cake_page_rownum_'; if ($original->clause('order')) { // SQL server does not support column aliases in OVER clauses. But // the only practical way to specify the use of calculated columns // is with their alias. So substitute the select SQL in place of // any column aliases for those entries in the order clause. $select = $original->clause('select'); $order = new OrderByExpression(); $original ->clause('order') ->iterateParts(function ($direction, $orderBy) use ($select, $order) { $key = $orderBy; if (isset($select[$orderBy]) && $select[$orderBy] instanceof ExpressionInterface ) { $key = $select[$orderBy]->sql(new ValueBinder()); } $order->add([$key => $direction]); // Leave original order clause unchanged. return $orderBy; }); } else { $order = new OrderByExpression('(SELECT NULL)'); } $query = clone $original; $query->select([ '_cake_page_rownum_' => new UnaryExpression('ROW_NUMBER() OVER', $order) ])->limit(null) ->offset(null) ->order([], true); $outer = new Query($query->getConnection()); $outer->select('*') ->from(['_cake_paging_' => $query]); if ($offset) { $outer->where(["$field > " . (int)$offset]); } if ($limit) { $value = (int)$offset + (int)$limit; $outer->where(["$field <= $value"]); } // Decorate the original query as that is what the // end developer will be calling execute() on originally. $original->decorateResults(function ($row) { if (isset($row['_cake_page_rownum_'])) { unset($row['_cake_page_rownum_']); } return $row; }); return $outer; }
[ "protected", "function", "_pagingSubquery", "(", "$", "original", ",", "$", "limit", ",", "$", "offset", ")", "{", "$", "field", "=", "'_cake_paging_._cake_page_rownum_'", ";", "if", "(", "$", "original", "->", "clause", "(", "'order'", ")", ")", "{", "// SQL server does not support column aliases in OVER clauses. But", "// the only practical way to specify the use of calculated columns", "// is with their alias. So substitute the select SQL in place of", "// any column aliases for those entries in the order clause.", "$", "select", "=", "$", "original", "->", "clause", "(", "'select'", ")", ";", "$", "order", "=", "new", "OrderByExpression", "(", ")", ";", "$", "original", "->", "clause", "(", "'order'", ")", "->", "iterateParts", "(", "function", "(", "$", "direction", ",", "$", "orderBy", ")", "use", "(", "$", "select", ",", "$", "order", ")", "{", "$", "key", "=", "$", "orderBy", ";", "if", "(", "isset", "(", "$", "select", "[", "$", "orderBy", "]", ")", "&&", "$", "select", "[", "$", "orderBy", "]", "instanceof", "ExpressionInterface", ")", "{", "$", "key", "=", "$", "select", "[", "$", "orderBy", "]", "->", "sql", "(", "new", "ValueBinder", "(", ")", ")", ";", "}", "$", "order", "->", "add", "(", "[", "$", "key", "=>", "$", "direction", "]", ")", ";", "// Leave original order clause unchanged.", "return", "$", "orderBy", ";", "}", ")", ";", "}", "else", "{", "$", "order", "=", "new", "OrderByExpression", "(", "'(SELECT NULL)'", ")", ";", "}", "$", "query", "=", "clone", "$", "original", ";", "$", "query", "->", "select", "(", "[", "'_cake_page_rownum_'", "=>", "new", "UnaryExpression", "(", "'ROW_NUMBER() OVER'", ",", "$", "order", ")", "]", ")", "->", "limit", "(", "null", ")", "->", "offset", "(", "null", ")", "->", "order", "(", "[", "]", ",", "true", ")", ";", "$", "outer", "=", "new", "Query", "(", "$", "query", "->", "getConnection", "(", ")", ")", ";", "$", "outer", "->", "select", "(", "'*'", ")", "->", "from", "(", "[", "'_cake_paging_'", "=>", "$", "query", "]", ")", ";", "if", "(", "$", "offset", ")", "{", "$", "outer", "->", "where", "(", "[", "\"$field > \"", ".", "(", "int", ")", "$", "offset", "]", ")", ";", "}", "if", "(", "$", "limit", ")", "{", "$", "value", "=", "(", "int", ")", "$", "offset", "+", "(", "int", ")", "$", "limit", ";", "$", "outer", "->", "where", "(", "[", "\"$field <= $value\"", "]", ")", ";", "}", "// Decorate the original query as that is what the", "// end developer will be calling execute() on originally.", "$", "original", "->", "decorateResults", "(", "function", "(", "$", "row", ")", "{", "if", "(", "isset", "(", "$", "row", "[", "'_cake_page_rownum_'", "]", ")", ")", "{", "unset", "(", "$", "row", "[", "'_cake_page_rownum_'", "]", ")", ";", "}", "return", "$", "row", ";", "}", ")", ";", "return", "$", "outer", ";", "}" ]
Generate a paging subquery for older versions of SQLserver. Prior to SQLServer 2012 there was no equivalent to LIMIT OFFSET, so a subquery must be used. @param \Cake\Database\Query $original The query to wrap in a subquery. @param int $limit The number of rows to fetch. @param int $offset The number of rows to offset. @return \Cake\Database\Query Modified query object.
[ "Generate", "a", "paging", "subquery", "for", "older", "versions", "of", "SQLserver", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Dialect/SqlserverDialectTrait.php#L104-L163
211,257
cakephp/cakephp
src/Routing/Route/InflectedRoute.php
InflectedRoute.parse
public function parse($url, $method = '') { $params = parent::parse($url, $method); if (!$params) { return false; } if (!empty($params['controller'])) { $params['controller'] = Inflector::camelize($params['controller']); } if (!empty($params['plugin'])) { if (strpos($params['plugin'], '/') === false) { $params['plugin'] = Inflector::camelize($params['plugin']); } else { list($vendor, $plugin) = explode('/', $params['plugin'], 2); $params['plugin'] = Inflector::camelize($vendor) . '/' . Inflector::camelize($plugin); } } return $params; }
php
public function parse($url, $method = '') { $params = parent::parse($url, $method); if (!$params) { return false; } if (!empty($params['controller'])) { $params['controller'] = Inflector::camelize($params['controller']); } if (!empty($params['plugin'])) { if (strpos($params['plugin'], '/') === false) { $params['plugin'] = Inflector::camelize($params['plugin']); } else { list($vendor, $plugin) = explode('/', $params['plugin'], 2); $params['plugin'] = Inflector::camelize($vendor) . '/' . Inflector::camelize($plugin); } } return $params; }
[ "public", "function", "parse", "(", "$", "url", ",", "$", "method", "=", "''", ")", "{", "$", "params", "=", "parent", "::", "parse", "(", "$", "url", ",", "$", "method", ")", ";", "if", "(", "!", "$", "params", ")", "{", "return", "false", ";", "}", "if", "(", "!", "empty", "(", "$", "params", "[", "'controller'", "]", ")", ")", "{", "$", "params", "[", "'controller'", "]", "=", "Inflector", "::", "camelize", "(", "$", "params", "[", "'controller'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "params", "[", "'plugin'", "]", ")", ")", "{", "if", "(", "strpos", "(", "$", "params", "[", "'plugin'", "]", ",", "'/'", ")", "===", "false", ")", "{", "$", "params", "[", "'plugin'", "]", "=", "Inflector", "::", "camelize", "(", "$", "params", "[", "'plugin'", "]", ")", ";", "}", "else", "{", "list", "(", "$", "vendor", ",", "$", "plugin", ")", "=", "explode", "(", "'/'", ",", "$", "params", "[", "'plugin'", "]", ",", "2", ")", ";", "$", "params", "[", "'plugin'", "]", "=", "Inflector", "::", "camelize", "(", "$", "vendor", ")", ".", "'/'", ".", "Inflector", "::", "camelize", "(", "$", "plugin", ")", ";", "}", "}", "return", "$", "params", ";", "}" ]
Parses a string URL into an array. If it matches, it will convert the prefix, controller and plugin keys to their camelized form. @param string $url The URL to parse @param string $method The HTTP method being matched. @return array|false An array of request parameters, or false on failure.
[ "Parses", "a", "string", "URL", "into", "an", "array", ".", "If", "it", "matches", "it", "will", "convert", "the", "prefix", "controller", "and", "plugin", "keys", "to", "their", "camelized", "form", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/InflectedRoute.php#L44-L63
211,258
cakephp/cakephp
src/Routing/Route/InflectedRoute.php
InflectedRoute._underscore
protected function _underscore($url) { if (!empty($url['controller'])) { $url['controller'] = Inflector::underscore($url['controller']); } if (!empty($url['plugin'])) { $url['plugin'] = Inflector::underscore($url['plugin']); } return $url; }
php
protected function _underscore($url) { if (!empty($url['controller'])) { $url['controller'] = Inflector::underscore($url['controller']); } if (!empty($url['plugin'])) { $url['plugin'] = Inflector::underscore($url['plugin']); } return $url; }
[ "protected", "function", "_underscore", "(", "$", "url", ")", "{", "if", "(", "!", "empty", "(", "$", "url", "[", "'controller'", "]", ")", ")", "{", "$", "url", "[", "'controller'", "]", "=", "Inflector", "::", "underscore", "(", "$", "url", "[", "'controller'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "url", "[", "'plugin'", "]", ")", ")", "{", "$", "url", "[", "'plugin'", "]", "=", "Inflector", "::", "underscore", "(", "$", "url", "[", "'plugin'", "]", ")", ";", "}", "return", "$", "url", ";", "}" ]
Helper method for underscoring keys in a URL array. @param array $url An array of URL keys. @return array
[ "Helper", "method", "for", "underscoring", "keys", "in", "a", "URL", "array", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/InflectedRoute.php#L92-L102
211,259
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.tieWith
public function tieWith($conjunction = null) { deprecationWarning( 'QueryExpression::tieWith() is deprecated. ' . 'Use QueryExpression::setConjunction()/getConjunction() instead.' ); if ($conjunction !== null) { return $this->setConjunction($conjunction); } return $this->getConjunction(); }
php
public function tieWith($conjunction = null) { deprecationWarning( 'QueryExpression::tieWith() is deprecated. ' . 'Use QueryExpression::setConjunction()/getConjunction() instead.' ); if ($conjunction !== null) { return $this->setConjunction($conjunction); } return $this->getConjunction(); }
[ "public", "function", "tieWith", "(", "$", "conjunction", "=", "null", ")", "{", "deprecationWarning", "(", "'QueryExpression::tieWith() is deprecated. '", ".", "'Use QueryExpression::setConjunction()/getConjunction() instead.'", ")", ";", "if", "(", "$", "conjunction", "!==", "null", ")", "{", "return", "$", "this", "->", "setConjunction", "(", "$", "conjunction", ")", ";", "}", "return", "$", "this", "->", "getConjunction", "(", ")", ";", "}" ]
Changes the conjunction for the conditions at this level of the expression tree. If called with no arguments it will return the currently configured value. @deprecated 3.4.0 Use setConjunction()/getConjunction() instead. @param string|null $conjunction value to be used for joining conditions. If null it will not set any value, but return the currently stored one @return string|$this
[ "Changes", "the", "conjunction", "for", "the", "conditions", "at", "this", "level", "of", "the", "expression", "tree", ".", "If", "called", "with", "no", "arguments", "it", "will", "return", "the", "currently", "configured", "value", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L109-L120
211,260
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.add
public function add($conditions, $types = []) { if (is_string($conditions)) { $this->_conditions[] = $conditions; return $this; } if ($conditions instanceof ExpressionInterface) { $this->_conditions[] = $conditions; return $this; } $this->_addConditions($conditions, $types); return $this; }
php
public function add($conditions, $types = []) { if (is_string($conditions)) { $this->_conditions[] = $conditions; return $this; } if ($conditions instanceof ExpressionInterface) { $this->_conditions[] = $conditions; return $this; } $this->_addConditions($conditions, $types); return $this; }
[ "public", "function", "add", "(", "$", "conditions", ",", "$", "types", "=", "[", "]", ")", "{", "if", "(", "is_string", "(", "$", "conditions", ")", ")", "{", "$", "this", "->", "_conditions", "[", "]", "=", "$", "conditions", ";", "return", "$", "this", ";", "}", "if", "(", "$", "conditions", "instanceof", "ExpressionInterface", ")", "{", "$", "this", "->", "_conditions", "[", "]", "=", "$", "conditions", ";", "return", "$", "this", ";", "}", "$", "this", "->", "_addConditions", "(", "$", "conditions", ",", "$", "types", ")", ";", "return", "$", "this", ";", "}" ]
Adds one or more conditions to this expression object. Conditions can be expressed in a one dimensional array, that will cause all conditions to be added directly at this level of the tree or they can be nested arbitrarily making it create more expression objects that will be nested inside and configured to use the specified conjunction. If the type passed for any of the fields is expressed "type[]" (note braces) then it will cause the placeholder to be re-written dynamically so if the value is an array, it will create as many placeholders as values are in it. @param string|array|\Cake\Database\ExpressionInterface $conditions single or multiple conditions to be added. When using an array and the key is 'OR' or 'AND' a new expression object will be created with that conjunction and internal array value passed as conditions. @param array $types associative array of fields pointing to the type of the values that are being passed. Used for correctly binding values to statements. @see \Cake\Database\Query::where() for examples on conditions @return $this
[ "Adds", "one", "or", "more", "conditions", "to", "this", "expression", "object", ".", "Conditions", "can", "be", "expressed", "in", "a", "one", "dimensional", "array", "that", "will", "cause", "all", "conditions", "to", "be", "added", "directly", "at", "this", "level", "of", "the", "tree", "or", "they", "can", "be", "nested", "arbitrarily", "making", "it", "create", "more", "expression", "objects", "that", "will", "be", "nested", "inside", "and", "configured", "to", "use", "the", "specified", "conjunction", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L160-L177
211,261
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.gt
public function gt($field, $value, $type = null) { if ($type === null) { $type = $this->_calculateType($field); } return $this->add(new Comparison($field, $value, $type, '>')); }
php
public function gt($field, $value, $type = null) { if ($type === null) { $type = $this->_calculateType($field); } return $this->add(new Comparison($field, $value, $type, '>')); }
[ "public", "function", "gt", "(", "$", "field", ",", "$", "value", ",", "$", "type", "=", "null", ")", "{", "if", "(", "$", "type", "===", "null", ")", "{", "$", "type", "=", "$", "this", "->", "_calculateType", "(", "$", "field", ")", ";", "}", "return", "$", "this", "->", "add", "(", "new", "Comparison", "(", "$", "field", ",", "$", "value", ",", "$", "type", ",", "'>'", ")", ")", ";", "}" ]
Adds a new condition to the expression object in the form "field > value". @param string|\Cake\Database\ExpressionInterface $field Database field to be compared against value @param mixed $value The value to be bound to $field for comparison @param string|null $type the type name for $value as configured using the Type map. @return $this
[ "Adds", "a", "new", "condition", "to", "the", "expression", "object", "in", "the", "form", "field", ">", "value", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L225-L232
211,262
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.isNull
public function isNull($field) { if (!($field instanceof ExpressionInterface)) { $field = new IdentifierExpression($field); } return $this->add(new UnaryExpression('IS NULL', $field, UnaryExpression::POSTFIX)); }
php
public function isNull($field) { if (!($field instanceof ExpressionInterface)) { $field = new IdentifierExpression($field); } return $this->add(new UnaryExpression('IS NULL', $field, UnaryExpression::POSTFIX)); }
[ "public", "function", "isNull", "(", "$", "field", ")", "{", "if", "(", "!", "(", "$", "field", "instanceof", "ExpressionInterface", ")", ")", "{", "$", "field", "=", "new", "IdentifierExpression", "(", "$", "field", ")", ";", "}", "return", "$", "this", "->", "add", "(", "new", "UnaryExpression", "(", "'IS NULL'", ",", "$", "field", ",", "UnaryExpression", "::", "POSTFIX", ")", ")", ";", "}" ]
Adds a new condition to the expression object in the form "field IS NULL". @param string|\Cake\Database\ExpressionInterface $field database field to be tested for null @return $this
[ "Adds", "a", "new", "condition", "to", "the", "expression", "object", "in", "the", "form", "field", "IS", "NULL", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L292-L299
211,263
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.isNotNull
public function isNotNull($field) { if (!($field instanceof ExpressionInterface)) { $field = new IdentifierExpression($field); } return $this->add(new UnaryExpression('IS NOT NULL', $field, UnaryExpression::POSTFIX)); }
php
public function isNotNull($field) { if (!($field instanceof ExpressionInterface)) { $field = new IdentifierExpression($field); } return $this->add(new UnaryExpression('IS NOT NULL', $field, UnaryExpression::POSTFIX)); }
[ "public", "function", "isNotNull", "(", "$", "field", ")", "{", "if", "(", "!", "(", "$", "field", "instanceof", "ExpressionInterface", ")", ")", "{", "$", "field", "=", "new", "IdentifierExpression", "(", "$", "field", ")", ";", "}", "return", "$", "this", "->", "add", "(", "new", "UnaryExpression", "(", "'IS NOT NULL'", ",", "$", "field", ",", "UnaryExpression", "::", "POSTFIX", ")", ")", ";", "}" ]
Adds a new condition to the expression object in the form "field IS NOT NULL". @param string|\Cake\Database\ExpressionInterface $field database field to be tested for not null @return $this
[ "Adds", "a", "new", "condition", "to", "the", "expression", "object", "in", "the", "form", "field", "IS", "NOT", "NULL", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L308-L315
211,264
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.addCase
public function addCase($conditions, $values = [], $types = []) { return $this->add(new CaseExpression($conditions, $values, $types)); }
php
public function addCase($conditions, $values = [], $types = []) { return $this->add(new CaseExpression($conditions, $values, $types)); }
[ "public", "function", "addCase", "(", "$", "conditions", ",", "$", "values", "=", "[", "]", ",", "$", "types", "=", "[", "]", ")", "{", "return", "$", "this", "->", "add", "(", "new", "CaseExpression", "(", "$", "conditions", ",", "$", "values", ",", "$", "types", ")", ")", ";", "}" ]
Adds a new case expression to the expression object @param array|\Cake\Database\ExpressionInterface $conditions The conditions to test. Must be a ExpressionInterface instance, or an array of ExpressionInterface instances. @param array|\Cake\Database\ExpressionInterface $values associative array of values to be associated with the conditions passed in $conditions. If there are more $values than $conditions, the last $value is used as the `ELSE` value @param array $types associative array of types to be associated with the values passed in $values @return $this
[ "Adds", "a", "new", "case", "expression", "to", "the", "expression", "object" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L383-L386
211,265
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.between
public function between($field, $from, $to, $type = null) { if ($type === null) { $type = $this->_calculateType($field); } return $this->add(new BetweenExpression($field, $from, $to, $type)); }
php
public function between($field, $from, $to, $type = null) { if ($type === null) { $type = $this->_calculateType($field); } return $this->add(new BetweenExpression($field, $from, $to, $type)); }
[ "public", "function", "between", "(", "$", "field", ",", "$", "from", ",", "$", "to", ",", "$", "type", "=", "null", ")", "{", "if", "(", "$", "type", "===", "null", ")", "{", "$", "type", "=", "$", "this", "->", "_calculateType", "(", "$", "field", ")", ";", "}", "return", "$", "this", "->", "add", "(", "new", "BetweenExpression", "(", "$", "field", ",", "$", "from", ",", "$", "to", ",", "$", "type", ")", ")", ";", "}" ]
Adds a new condition to the expression object in the form "field BETWEEN from AND to". @param string|\Cake\Database\ExpressionInterface $field The field name to compare for values in between the range. @param mixed $from The initial value of the range. @param mixed $to The ending value in the comparison range. @param string|null $type the type name for $value as configured using the Type map. @return $this
[ "Adds", "a", "new", "condition", "to", "the", "expression", "object", "in", "the", "form", "field", "BETWEEN", "from", "AND", "to", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L441-L448
211,266
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.and_
public function and_($conditions, $types = []) { if ($this->isCallable($conditions)) { return $conditions(new static([], $this->getTypeMap()->setTypes($types))); } return new static($conditions, $this->getTypeMap()->setTypes($types)); }
php
public function and_($conditions, $types = []) { if ($this->isCallable($conditions)) { return $conditions(new static([], $this->getTypeMap()->setTypes($types))); } return new static($conditions, $this->getTypeMap()->setTypes($types)); }
[ "public", "function", "and_", "(", "$", "conditions", ",", "$", "types", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "isCallable", "(", "$", "conditions", ")", ")", "{", "return", "$", "conditions", "(", "new", "static", "(", "[", "]", ",", "$", "this", "->", "getTypeMap", "(", ")", "->", "setTypes", "(", "$", "types", ")", ")", ")", ";", "}", "return", "new", "static", "(", "$", "conditions", ",", "$", "this", "->", "getTypeMap", "(", ")", "->", "setTypes", "(", "$", "types", ")", ")", ";", "}" ]
Returns a new QueryExpression object containing all the conditions passed and set up the conjunction to be "AND" @param callable|string|array|\Cake\Database\ExpressionInterface $conditions to be joined with AND @param array $types associative array of fields pointing to the type of the values that are being passed. Used for correctly binding values to statements. @return \Cake\Database\Expression\QueryExpression
[ "Returns", "a", "new", "QueryExpression", "object", "containing", "all", "the", "conditions", "passed", "and", "set", "up", "the", "conjunction", "to", "be", "AND" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L460-L467
211,267
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.or_
public function or_($conditions, $types = []) { if ($this->isCallable($conditions)) { return $conditions(new static([], $this->getTypeMap()->setTypes($types), 'OR')); } return new static($conditions, $this->getTypeMap()->setTypes($types), 'OR'); }
php
public function or_($conditions, $types = []) { if ($this->isCallable($conditions)) { return $conditions(new static([], $this->getTypeMap()->setTypes($types), 'OR')); } return new static($conditions, $this->getTypeMap()->setTypes($types), 'OR'); }
[ "public", "function", "or_", "(", "$", "conditions", ",", "$", "types", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "isCallable", "(", "$", "conditions", ")", ")", "{", "return", "$", "conditions", "(", "new", "static", "(", "[", "]", ",", "$", "this", "->", "getTypeMap", "(", ")", "->", "setTypes", "(", "$", "types", ")", ",", "'OR'", ")", ")", ";", "}", "return", "new", "static", "(", "$", "conditions", ",", "$", "this", "->", "getTypeMap", "(", ")", "->", "setTypes", "(", "$", "types", ")", ",", "'OR'", ")", ";", "}" ]
Returns a new QueryExpression object containing all the conditions passed and set up the conjunction to be "OR" @param callable|string|array|\Cake\Database\ExpressionInterface $conditions to be joined with OR @param array $types associative array of fields pointing to the type of the values that are being passed. Used for correctly binding values to statements. @return \Cake\Database\Expression\QueryExpression
[ "Returns", "a", "new", "QueryExpression", "object", "containing", "all", "the", "conditions", "passed", "and", "set", "up", "the", "conjunction", "to", "be", "OR" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L478-L485
211,268
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.equalFields
public function equalFields($left, $right) { $wrapIdentifier = function ($field) { if ($field instanceof ExpressionInterface) { return $field; } return new IdentifierExpression($field); }; return $this->eq($wrapIdentifier($left), $wrapIdentifier($right)); }
php
public function equalFields($left, $right) { $wrapIdentifier = function ($field) { if ($field instanceof ExpressionInterface) { return $field; } return new IdentifierExpression($field); }; return $this->eq($wrapIdentifier($left), $wrapIdentifier($right)); }
[ "public", "function", "equalFields", "(", "$", "left", ",", "$", "right", ")", "{", "$", "wrapIdentifier", "=", "function", "(", "$", "field", ")", "{", "if", "(", "$", "field", "instanceof", "ExpressionInterface", ")", "{", "return", "$", "field", ";", "}", "return", "new", "IdentifierExpression", "(", "$", "field", ")", ";", "}", ";", "return", "$", "this", "->", "eq", "(", "$", "wrapIdentifier", "(", "$", "left", ")", ",", "$", "wrapIdentifier", "(", "$", "right", ")", ")", ";", "}" ]
Builds equal condition or assignment with identifier wrapping. @param string $left Left join condition field name. @param string $right Right join condition field name. @return $this
[ "Builds", "equal", "condition", "or", "assignment", "with", "identifier", "wrapping", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L523-L534
211,269
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.traverse
public function traverse(callable $callable) { foreach ($this->_conditions as $c) { if ($c instanceof ExpressionInterface) { $callable($c); $c->traverse($callable); } } }
php
public function traverse(callable $callable) { foreach ($this->_conditions as $c) { if ($c instanceof ExpressionInterface) { $callable($c); $c->traverse($callable); } } }
[ "public", "function", "traverse", "(", "callable", "$", "callable", ")", "{", "foreach", "(", "$", "this", "->", "_conditions", "as", "$", "c", ")", "{", "if", "(", "$", "c", "instanceof", "ExpressionInterface", ")", "{", "$", "callable", "(", "$", "c", ")", ";", "$", "c", "->", "traverse", "(", "$", "callable", ")", ";", "}", "}", "}" ]
Traverses the tree structure of this query expression by executing a callback function for each of the conditions that are included in this object. Useful for compiling the final expression, or doing introspection in the structure. Callback function receives as only argument an instance of ExpressionInterface @param callable $callable The callable to apply to all sub-expressions. @return void
[ "Traverses", "the", "tree", "structure", "of", "this", "query", "expression", "by", "executing", "a", "callback", "function", "for", "each", "of", "the", "conditions", "that", "are", "included", "in", "this", "object", ".", "Useful", "for", "compiling", "the", "final", "expression", "or", "doing", "introspection", "in", "the", "structure", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L579-L587
211,270
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.iterateParts
public function iterateParts(callable $callable) { $parts = []; foreach ($this->_conditions as $k => $c) { $key =& $k; $part = $callable($c, $key); if ($part !== null) { $parts[$key] = $part; } } $this->_conditions = $parts; return $this; }
php
public function iterateParts(callable $callable) { $parts = []; foreach ($this->_conditions as $k => $c) { $key =& $k; $part = $callable($c, $key); if ($part !== null) { $parts[$key] = $part; } } $this->_conditions = $parts; return $this; }
[ "public", "function", "iterateParts", "(", "callable", "$", "callable", ")", "{", "$", "parts", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "_conditions", "as", "$", "k", "=>", "$", "c", ")", "{", "$", "key", "=", "&", "$", "k", ";", "$", "part", "=", "$", "callable", "(", "$", "c", ",", "$", "key", ")", ";", "if", "(", "$", "part", "!==", "null", ")", "{", "$", "parts", "[", "$", "key", "]", "=", "$", "part", ";", "}", "}", "$", "this", "->", "_conditions", "=", "$", "parts", ";", "return", "$", "this", ";", "}" ]
Executes a callable function for each of the parts that form this expression. The callable function is required to return a value with which the currently visited part will be replaced. If the callable function returns null then the part will be discarded completely from this expression. The callback function will receive each of the conditions as first param and the key as second param. It is possible to declare the second parameter as passed by reference, this will enable you to change the key under which the modified part is stored. @param callable $callable The callable to apply to each part. @return $this
[ "Executes", "a", "callable", "function", "for", "each", "of", "the", "parts", "that", "form", "this", "expression", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L604-L617
211,271
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression.isCallable
public function isCallable($c) { if (is_string($c)) { return false; } if (is_object($c) && is_callable($c)) { return true; } return is_array($c) && isset($c[0]) && is_object($c[0]) && is_callable($c); }
php
public function isCallable($c) { if (is_string($c)) { return false; } if (is_object($c) && is_callable($c)) { return true; } return is_array($c) && isset($c[0]) && is_object($c[0]) && is_callable($c); }
[ "public", "function", "isCallable", "(", "$", "c", ")", "{", "if", "(", "is_string", "(", "$", "c", ")", ")", "{", "return", "false", ";", "}", "if", "(", "is_object", "(", "$", "c", ")", "&&", "is_callable", "(", "$", "c", ")", ")", "{", "return", "true", ";", "}", "return", "is_array", "(", "$", "c", ")", "&&", "isset", "(", "$", "c", "[", "0", "]", ")", "&&", "is_object", "(", "$", "c", "[", "0", "]", ")", "&&", "is_callable", "(", "$", "c", ")", ";", "}" ]
Check whether or not a callable is acceptable. We don't accept ['class', 'method'] style callbacks, as they often contain user input and arrays of strings are easy to sneak in. @param callable $c The callable to check. @return bool Valid callable.
[ "Check", "whether", "or", "not", "a", "callable", "is", "acceptable", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L645-L655
211,272
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression._addConditions
protected function _addConditions(array $conditions, array $types) { $operators = ['and', 'or', 'xor']; $typeMap = $this->getTypeMap()->setTypes($types); foreach ($conditions as $k => $c) { $numericKey = is_numeric($k); if ($this->isCallable($c)) { $expr = new static([], $typeMap); $c = $c($expr, $this); } if ($numericKey && empty($c)) { continue; } $isArray = is_array($c); $isOperator = in_array(strtolower($k), $operators); $isNot = strtolower($k) === 'not'; if (($isOperator || $isNot) && ($isArray || $c instanceof Countable) && count($c) === 0) { continue; } if ($numericKey && $c instanceof ExpressionInterface) { $this->_conditions[] = $c; continue; } if ($numericKey && is_string($c)) { $this->_conditions[] = $c; continue; } if ($numericKey && $isArray || $isOperator) { $this->_conditions[] = new static($c, $typeMap, $numericKey ? 'AND' : $k); continue; } if ($isNot) { $this->_conditions[] = new UnaryExpression('NOT', new static($c, $typeMap)); continue; } if (!$numericKey) { $this->_conditions[] = $this->_parseCondition($k, $c); } } }
php
protected function _addConditions(array $conditions, array $types) { $operators = ['and', 'or', 'xor']; $typeMap = $this->getTypeMap()->setTypes($types); foreach ($conditions as $k => $c) { $numericKey = is_numeric($k); if ($this->isCallable($c)) { $expr = new static([], $typeMap); $c = $c($expr, $this); } if ($numericKey && empty($c)) { continue; } $isArray = is_array($c); $isOperator = in_array(strtolower($k), $operators); $isNot = strtolower($k) === 'not'; if (($isOperator || $isNot) && ($isArray || $c instanceof Countable) && count($c) === 0) { continue; } if ($numericKey && $c instanceof ExpressionInterface) { $this->_conditions[] = $c; continue; } if ($numericKey && is_string($c)) { $this->_conditions[] = $c; continue; } if ($numericKey && $isArray || $isOperator) { $this->_conditions[] = new static($c, $typeMap, $numericKey ? 'AND' : $k); continue; } if ($isNot) { $this->_conditions[] = new UnaryExpression('NOT', new static($c, $typeMap)); continue; } if (!$numericKey) { $this->_conditions[] = $this->_parseCondition($k, $c); } } }
[ "protected", "function", "_addConditions", "(", "array", "$", "conditions", ",", "array", "$", "types", ")", "{", "$", "operators", "=", "[", "'and'", ",", "'or'", ",", "'xor'", "]", ";", "$", "typeMap", "=", "$", "this", "->", "getTypeMap", "(", ")", "->", "setTypes", "(", "$", "types", ")", ";", "foreach", "(", "$", "conditions", "as", "$", "k", "=>", "$", "c", ")", "{", "$", "numericKey", "=", "is_numeric", "(", "$", "k", ")", ";", "if", "(", "$", "this", "->", "isCallable", "(", "$", "c", ")", ")", "{", "$", "expr", "=", "new", "static", "(", "[", "]", ",", "$", "typeMap", ")", ";", "$", "c", "=", "$", "c", "(", "$", "expr", ",", "$", "this", ")", ";", "}", "if", "(", "$", "numericKey", "&&", "empty", "(", "$", "c", ")", ")", "{", "continue", ";", "}", "$", "isArray", "=", "is_array", "(", "$", "c", ")", ";", "$", "isOperator", "=", "in_array", "(", "strtolower", "(", "$", "k", ")", ",", "$", "operators", ")", ";", "$", "isNot", "=", "strtolower", "(", "$", "k", ")", "===", "'not'", ";", "if", "(", "(", "$", "isOperator", "||", "$", "isNot", ")", "&&", "(", "$", "isArray", "||", "$", "c", "instanceof", "Countable", ")", "&&", "count", "(", "$", "c", ")", "===", "0", ")", "{", "continue", ";", "}", "if", "(", "$", "numericKey", "&&", "$", "c", "instanceof", "ExpressionInterface", ")", "{", "$", "this", "->", "_conditions", "[", "]", "=", "$", "c", ";", "continue", ";", "}", "if", "(", "$", "numericKey", "&&", "is_string", "(", "$", "c", ")", ")", "{", "$", "this", "->", "_conditions", "[", "]", "=", "$", "c", ";", "continue", ";", "}", "if", "(", "$", "numericKey", "&&", "$", "isArray", "||", "$", "isOperator", ")", "{", "$", "this", "->", "_conditions", "[", "]", "=", "new", "static", "(", "$", "c", ",", "$", "typeMap", ",", "$", "numericKey", "?", "'AND'", ":", "$", "k", ")", ";", "continue", ";", "}", "if", "(", "$", "isNot", ")", "{", "$", "this", "->", "_conditions", "[", "]", "=", "new", "UnaryExpression", "(", "'NOT'", ",", "new", "static", "(", "$", "c", ",", "$", "typeMap", ")", ")", ";", "continue", ";", "}", "if", "(", "!", "$", "numericKey", ")", "{", "$", "this", "->", "_conditions", "[", "]", "=", "$", "this", "->", "_parseCondition", "(", "$", "k", ",", "$", "c", ")", ";", "}", "}", "}" ]
Auxiliary function used for decomposing a nested array of conditions and build a tree structure inside this object to represent the full SQL expression. String conditions are stored directly in the conditions, while any other representation is wrapped around an adequate instance or of this class. @param array $conditions list of conditions to be stored in this object @param array $types list of types associated on fields referenced in $conditions @return void
[ "Auxiliary", "function", "used", "for", "decomposing", "a", "nested", "array", "of", "conditions", "and", "build", "a", "tree", "structure", "inside", "this", "object", "to", "represent", "the", "full", "SQL", "expression", ".", "String", "conditions", "are", "stored", "directly", "in", "the", "conditions", "while", "any", "other", "representation", "is", "wrapped", "around", "an", "adequate", "instance", "or", "of", "this", "class", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L684-L734
211,273
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression._parseCondition
protected function _parseCondition($field, $value) { $operator = '='; $expression = $field; $parts = explode(' ', trim($field), 2); if (count($parts) > 1) { list($expression, $operator) = $parts; } $type = $this->getTypeMap()->type($expression); $operator = strtolower(trim($operator)); $typeMultiple = strpos($type, '[]') !== false; if (in_array($operator, ['in', 'not in']) || $typeMultiple) { $type = $type ?: 'string'; $type .= $typeMultiple ? null : '[]'; $operator = $operator === '=' ? 'IN' : $operator; $operator = $operator === '!=' ? 'NOT IN' : $operator; $typeMultiple = true; } if ($typeMultiple) { $value = $value instanceof ExpressionInterface ? $value : (array)$value; } if ($operator === 'is' && $value === null) { return new UnaryExpression( 'IS NULL', new IdentifierExpression($expression), UnaryExpression::POSTFIX ); } if ($operator === 'is not' && $value === null) { return new UnaryExpression( 'IS NOT NULL', new IdentifierExpression($expression), UnaryExpression::POSTFIX ); } if ($operator === 'is' && $value !== null) { $operator = '='; } if ($operator === 'is not' && $value !== null) { $operator = '!='; } return new Comparison($expression, $value, $type, $operator); }
php
protected function _parseCondition($field, $value) { $operator = '='; $expression = $field; $parts = explode(' ', trim($field), 2); if (count($parts) > 1) { list($expression, $operator) = $parts; } $type = $this->getTypeMap()->type($expression); $operator = strtolower(trim($operator)); $typeMultiple = strpos($type, '[]') !== false; if (in_array($operator, ['in', 'not in']) || $typeMultiple) { $type = $type ?: 'string'; $type .= $typeMultiple ? null : '[]'; $operator = $operator === '=' ? 'IN' : $operator; $operator = $operator === '!=' ? 'NOT IN' : $operator; $typeMultiple = true; } if ($typeMultiple) { $value = $value instanceof ExpressionInterface ? $value : (array)$value; } if ($operator === 'is' && $value === null) { return new UnaryExpression( 'IS NULL', new IdentifierExpression($expression), UnaryExpression::POSTFIX ); } if ($operator === 'is not' && $value === null) { return new UnaryExpression( 'IS NOT NULL', new IdentifierExpression($expression), UnaryExpression::POSTFIX ); } if ($operator === 'is' && $value !== null) { $operator = '='; } if ($operator === 'is not' && $value !== null) { $operator = '!='; } return new Comparison($expression, $value, $type, $operator); }
[ "protected", "function", "_parseCondition", "(", "$", "field", ",", "$", "value", ")", "{", "$", "operator", "=", "'='", ";", "$", "expression", "=", "$", "field", ";", "$", "parts", "=", "explode", "(", "' '", ",", "trim", "(", "$", "field", ")", ",", "2", ")", ";", "if", "(", "count", "(", "$", "parts", ")", ">", "1", ")", "{", "list", "(", "$", "expression", ",", "$", "operator", ")", "=", "$", "parts", ";", "}", "$", "type", "=", "$", "this", "->", "getTypeMap", "(", ")", "->", "type", "(", "$", "expression", ")", ";", "$", "operator", "=", "strtolower", "(", "trim", "(", "$", "operator", ")", ")", ";", "$", "typeMultiple", "=", "strpos", "(", "$", "type", ",", "'[]'", ")", "!==", "false", ";", "if", "(", "in_array", "(", "$", "operator", ",", "[", "'in'", ",", "'not in'", "]", ")", "||", "$", "typeMultiple", ")", "{", "$", "type", "=", "$", "type", "?", ":", "'string'", ";", "$", "type", ".=", "$", "typeMultiple", "?", "null", ":", "'[]'", ";", "$", "operator", "=", "$", "operator", "===", "'='", "?", "'IN'", ":", "$", "operator", ";", "$", "operator", "=", "$", "operator", "===", "'!='", "?", "'NOT IN'", ":", "$", "operator", ";", "$", "typeMultiple", "=", "true", ";", "}", "if", "(", "$", "typeMultiple", ")", "{", "$", "value", "=", "$", "value", "instanceof", "ExpressionInterface", "?", "$", "value", ":", "(", "array", ")", "$", "value", ";", "}", "if", "(", "$", "operator", "===", "'is'", "&&", "$", "value", "===", "null", ")", "{", "return", "new", "UnaryExpression", "(", "'IS NULL'", ",", "new", "IdentifierExpression", "(", "$", "expression", ")", ",", "UnaryExpression", "::", "POSTFIX", ")", ";", "}", "if", "(", "$", "operator", "===", "'is not'", "&&", "$", "value", "===", "null", ")", "{", "return", "new", "UnaryExpression", "(", "'IS NOT NULL'", ",", "new", "IdentifierExpression", "(", "$", "expression", ")", ",", "UnaryExpression", "::", "POSTFIX", ")", ";", "}", "if", "(", "$", "operator", "===", "'is'", "&&", "$", "value", "!==", "null", ")", "{", "$", "operator", "=", "'='", ";", "}", "if", "(", "$", "operator", "===", "'is not'", "&&", "$", "value", "!==", "null", ")", "{", "$", "operator", "=", "'!='", ";", "}", "return", "new", "Comparison", "(", "$", "expression", ",", "$", "value", ",", "$", "type", ",", "$", "operator", ")", ";", "}" ]
Parses a string conditions by trying to extract the operator inside it if any and finally returning either an adequate QueryExpression object or a plain string representation of the condition. This function is responsible for generating the placeholders and replacing the values by them, while storing the value elsewhere for future binding. @param string $field The value from with the actual field and operator will be extracted. @param mixed $value The value to be bound to a placeholder for the field @return string|\Cake\Database\ExpressionInterface
[ "Parses", "a", "string", "conditions", "by", "trying", "to", "extract", "the", "operator", "inside", "it", "if", "any", "and", "finally", "returning", "either", "an", "adequate", "QueryExpression", "object", "or", "a", "plain", "string", "representation", "of", "the", "condition", ".", "This", "function", "is", "responsible", "for", "generating", "the", "placeholders", "and", "replacing", "the", "values", "by", "them", "while", "storing", "the", "value", "elsewhere", "for", "future", "binding", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L748-L799
211,274
cakephp/cakephp
src/Database/Expression/QueryExpression.php
QueryExpression._calculateType
protected function _calculateType($field) { $field = $field instanceof IdentifierExpression ? $field->getIdentifier() : $field; if (is_string($field)) { return $this->getTypeMap()->type($field); } return null; }
php
protected function _calculateType($field) { $field = $field instanceof IdentifierExpression ? $field->getIdentifier() : $field; if (is_string($field)) { return $this->getTypeMap()->type($field); } return null; }
[ "protected", "function", "_calculateType", "(", "$", "field", ")", "{", "$", "field", "=", "$", "field", "instanceof", "IdentifierExpression", "?", "$", "field", "->", "getIdentifier", "(", ")", ":", "$", "field", ";", "if", "(", "is_string", "(", "$", "field", ")", ")", "{", "return", "$", "this", "->", "getTypeMap", "(", ")", "->", "type", "(", "$", "field", ")", ";", "}", "return", "null", ";", "}" ]
Returns the type name for the passed field if it was stored in the typeMap @param string|\Cake\Database\Expression\IdentifierExpression $field The field name to get a type for. @return string|null The computed type or null, if the type is unknown.
[ "Returns", "the", "type", "name", "for", "the", "passed", "field", "if", "it", "was", "stored", "in", "the", "typeMap" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/QueryExpression.php#L807-L815
211,275
cakephp/cakephp
src/Http/Client/FormData.php
FormData.boundary
public function boundary() { if ($this->_boundary) { return $this->_boundary; } $this->_boundary = md5(uniqid(time())); return $this->_boundary; }
php
public function boundary() { if ($this->_boundary) { return $this->_boundary; } $this->_boundary = md5(uniqid(time())); return $this->_boundary; }
[ "public", "function", "boundary", "(", ")", "{", "if", "(", "$", "this", "->", "_boundary", ")", "{", "return", "$", "this", "->", "_boundary", ";", "}", "$", "this", "->", "_boundary", "=", "md5", "(", "uniqid", "(", "time", "(", ")", ")", ")", ";", "return", "$", "this", "->", "_boundary", ";", "}" ]
Get the boundary marker @return string
[ "Get", "the", "boundary", "marker" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/FormData.php#L62-L70
211,276
cakephp/cakephp
src/Http/Client/FormData.php
FormData.add
public function add($name, $value = null) { if (is_array($value)) { $this->addRecursive($name, $value); } elseif (is_resource($value)) { $this->addFile($name, $value); } elseif ($name instanceof FormDataPart && $value === null) { $this->_hasComplexPart = true; $this->_parts[] = $name; } else { $this->_parts[] = $this->newPart($name, $value); } return $this; }
php
public function add($name, $value = null) { if (is_array($value)) { $this->addRecursive($name, $value); } elseif (is_resource($value)) { $this->addFile($name, $value); } elseif ($name instanceof FormDataPart && $value === null) { $this->_hasComplexPart = true; $this->_parts[] = $name; } else { $this->_parts[] = $this->newPart($name, $value); } return $this; }
[ "public", "function", "add", "(", "$", "name", ",", "$", "value", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "this", "->", "addRecursive", "(", "$", "name", ",", "$", "value", ")", ";", "}", "elseif", "(", "is_resource", "(", "$", "value", ")", ")", "{", "$", "this", "->", "addFile", "(", "$", "name", ",", "$", "value", ")", ";", "}", "elseif", "(", "$", "name", "instanceof", "FormDataPart", "&&", "$", "value", "===", "null", ")", "{", "$", "this", "->", "_hasComplexPart", "=", "true", ";", "$", "this", "->", "_parts", "[", "]", "=", "$", "name", ";", "}", "else", "{", "$", "this", "->", "_parts", "[", "]", "=", "$", "this", "->", "newPart", "(", "$", "name", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add a new part to the data. The value for a part can be a string, array, int, float, filehandle, or object implementing __toString() If the $value is an array, multiple parts will be added. Files will be read from their current position and saved in memory. @param string|\Cake\Http\Client\FormData $name The name of the part to add, or the part data object. @param mixed $value The value for the part. @return $this
[ "Add", "a", "new", "part", "to", "the", "data", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/FormData.php#L98-L112
211,277
cakephp/cakephp
src/Http/Client/FormData.php
FormData.addMany
public function addMany(array $data) { foreach ($data as $name => $value) { $this->add($name, $value); } return $this; }
php
public function addMany(array $data) { foreach ($data as $name => $value) { $this->add($name, $value); } return $this; }
[ "public", "function", "addMany", "(", "array", "$", "data", ")", "{", "foreach", "(", "$", "data", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "this", "->", "add", "(", "$", "name", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add multiple parts at once. Iterates the parameter and adds all the key/values. @param array $data Array of data to add. @return $this
[ "Add", "multiple", "parts", "at", "once", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/FormData.php#L122-L129
211,278
cakephp/cakephp
src/Http/Client/FormData.php
FormData.addRecursive
public function addRecursive($name, $value) { foreach ($value as $key => $value) { $key = $name . '[' . $key . ']'; $this->add($key, $value); } }
php
public function addRecursive($name, $value) { foreach ($value as $key => $value) { $key = $name . '[' . $key . ']'; $this->add($key, $value); } }
[ "public", "function", "addRecursive", "(", "$", "name", ",", "$", "value", ")", "{", "foreach", "(", "$", "value", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "key", "=", "$", "name", ".", "'['", ".", "$", "key", ".", "']'", ";", "$", "this", "->", "add", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}" ]
Recursively add data. @param string $name The name to use. @param mixed $value The value to add. @return void
[ "Recursively", "add", "data", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/FormData.php#L177-L183
211,279
cakephp/cakephp
src/Shell/Helper/TableHelper.php
TableHelper._calculateWidths
protected function _calculateWidths($rows) { $widths = []; foreach ($rows as $line) { foreach (array_values($line) as $k => $v) { $columnLength = $this->_cellWidth($v); if ($columnLength >= (isset($widths[$k]) ? $widths[$k] : 0)) { $widths[$k] = $columnLength; } } } return $widths; }
php
protected function _calculateWidths($rows) { $widths = []; foreach ($rows as $line) { foreach (array_values($line) as $k => $v) { $columnLength = $this->_cellWidth($v); if ($columnLength >= (isset($widths[$k]) ? $widths[$k] : 0)) { $widths[$k] = $columnLength; } } } return $widths; }
[ "protected", "function", "_calculateWidths", "(", "$", "rows", ")", "{", "$", "widths", "=", "[", "]", ";", "foreach", "(", "$", "rows", "as", "$", "line", ")", "{", "foreach", "(", "array_values", "(", "$", "line", ")", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "columnLength", "=", "$", "this", "->", "_cellWidth", "(", "$", "v", ")", ";", "if", "(", "$", "columnLength", ">=", "(", "isset", "(", "$", "widths", "[", "$", "k", "]", ")", "?", "$", "widths", "[", "$", "k", "]", ":", "0", ")", ")", "{", "$", "widths", "[", "$", "k", "]", "=", "$", "columnLength", ";", "}", "}", "}", "return", "$", "widths", ";", "}" ]
Calculate the column widths @param array $rows The rows on which the columns width will be calculated on. @return array
[ "Calculate", "the", "column", "widths" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Helper/TableHelper.php#L42-L55
211,280
cakephp/cakephp
src/Shell/Helper/TableHelper.php
TableHelper._cellWidth
protected function _cellWidth($text) { if (strpos($text, '<') === false && strpos($text, '>') === false) { return mb_strwidth($text); } $styles = array_keys($this->_io->styles()); $tags = implode('|', $styles); $text = preg_replace('#</?(?:' . $tags . ')>#', '', $text); return mb_strwidth($text); }
php
protected function _cellWidth($text) { if (strpos($text, '<') === false && strpos($text, '>') === false) { return mb_strwidth($text); } $styles = array_keys($this->_io->styles()); $tags = implode('|', $styles); $text = preg_replace('#</?(?:' . $tags . ')>#', '', $text); return mb_strwidth($text); }
[ "protected", "function", "_cellWidth", "(", "$", "text", ")", "{", "if", "(", "strpos", "(", "$", "text", ",", "'<'", ")", "===", "false", "&&", "strpos", "(", "$", "text", ",", "'>'", ")", "===", "false", ")", "{", "return", "mb_strwidth", "(", "$", "text", ")", ";", "}", "$", "styles", "=", "array_keys", "(", "$", "this", "->", "_io", "->", "styles", "(", ")", ")", ";", "$", "tags", "=", "implode", "(", "'|'", ",", "$", "styles", ")", ";", "$", "text", "=", "preg_replace", "(", "'#</?(?:'", ".", "$", "tags", ".", "')>#'", ",", "''", ",", "$", "text", ")", ";", "return", "mb_strwidth", "(", "$", "text", ")", ";", "}" ]
Get the width of a cell exclusive of style tags. @param string $text The text to calculate a width for. @return int The width of the textual content in visible characters.
[ "Get", "the", "width", "of", "a", "cell", "exclusive", "of", "style", "tags", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Helper/TableHelper.php#L63-L73
211,281
cakephp/cakephp
src/Shell/Helper/TableHelper.php
TableHelper._rowSeparator
protected function _rowSeparator($widths) { $out = ''; foreach ($widths as $column) { $out .= '+' . str_repeat('-', $column + 2); } $out .= '+'; $this->_io->out($out); }
php
protected function _rowSeparator($widths) { $out = ''; foreach ($widths as $column) { $out .= '+' . str_repeat('-', $column + 2); } $out .= '+'; $this->_io->out($out); }
[ "protected", "function", "_rowSeparator", "(", "$", "widths", ")", "{", "$", "out", "=", "''", ";", "foreach", "(", "$", "widths", "as", "$", "column", ")", "{", "$", "out", ".=", "'+'", ".", "str_repeat", "(", "'-'", ",", "$", "column", "+", "2", ")", ";", "}", "$", "out", ".=", "'+'", ";", "$", "this", "->", "_io", "->", "out", "(", "$", "out", ")", ";", "}" ]
Output a row separator. @param array $widths The widths of each column to output. @return void
[ "Output", "a", "row", "separator", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Helper/TableHelper.php#L81-L89
211,282
cakephp/cakephp
src/Shell/Helper/TableHelper.php
TableHelper._render
protected function _render(array $row, $widths, $options = []) { if (count($row) === 0) { return; } $out = ''; foreach (array_values($row) as $i => $column) { $pad = $widths[$i] - $this->_cellWidth($column); if (!empty($options['style'])) { $column = $this->_addStyle($column, $options['style']); } $out .= '| ' . $column . str_repeat(' ', $pad) . ' '; } $out .= '|'; $this->_io->out($out); }
php
protected function _render(array $row, $widths, $options = []) { if (count($row) === 0) { return; } $out = ''; foreach (array_values($row) as $i => $column) { $pad = $widths[$i] - $this->_cellWidth($column); if (!empty($options['style'])) { $column = $this->_addStyle($column, $options['style']); } $out .= '| ' . $column . str_repeat(' ', $pad) . ' '; } $out .= '|'; $this->_io->out($out); }
[ "protected", "function", "_render", "(", "array", "$", "row", ",", "$", "widths", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "count", "(", "$", "row", ")", "===", "0", ")", "{", "return", ";", "}", "$", "out", "=", "''", ";", "foreach", "(", "array_values", "(", "$", "row", ")", "as", "$", "i", "=>", "$", "column", ")", "{", "$", "pad", "=", "$", "widths", "[", "$", "i", "]", "-", "$", "this", "->", "_cellWidth", "(", "$", "column", ")", ";", "if", "(", "!", "empty", "(", "$", "options", "[", "'style'", "]", ")", ")", "{", "$", "column", "=", "$", "this", "->", "_addStyle", "(", "$", "column", ",", "$", "options", "[", "'style'", "]", ")", ";", "}", "$", "out", ".=", "'| '", ".", "$", "column", ".", "str_repeat", "(", "' '", ",", "$", "pad", ")", ".", "' '", ";", "}", "$", "out", ".=", "'|'", ";", "$", "this", "->", "_io", "->", "out", "(", "$", "out", ")", ";", "}" ]
Output a row. @param array $row The row to output. @param array $widths The widths of each column to output. @param array $options Options to be passed. @return void
[ "Output", "a", "row", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Helper/TableHelper.php#L99-L115
211,283
cakephp/cakephp
src/Shell/Helper/TableHelper.php
TableHelper.output
public function output($rows) { if (!is_array($rows) || count($rows) === 0) { return; } $config = $this->getConfig(); $widths = $this->_calculateWidths($rows); $this->_rowSeparator($widths); if ($config['headers'] === true) { $this->_render(array_shift($rows), $widths, ['style' => $config['headerStyle']]); $this->_rowSeparator($widths); } if (!$rows) { return; } foreach ($rows as $line) { $this->_render($line, $widths); if ($config['rowSeparator'] === true) { $this->_rowSeparator($widths); } } if ($config['rowSeparator'] !== true) { $this->_rowSeparator($widths); } }
php
public function output($rows) { if (!is_array($rows) || count($rows) === 0) { return; } $config = $this->getConfig(); $widths = $this->_calculateWidths($rows); $this->_rowSeparator($widths); if ($config['headers'] === true) { $this->_render(array_shift($rows), $widths, ['style' => $config['headerStyle']]); $this->_rowSeparator($widths); } if (!$rows) { return; } foreach ($rows as $line) { $this->_render($line, $widths); if ($config['rowSeparator'] === true) { $this->_rowSeparator($widths); } } if ($config['rowSeparator'] !== true) { $this->_rowSeparator($widths); } }
[ "public", "function", "output", "(", "$", "rows", ")", "{", "if", "(", "!", "is_array", "(", "$", "rows", ")", "||", "count", "(", "$", "rows", ")", "===", "0", ")", "{", "return", ";", "}", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "$", "widths", "=", "$", "this", "->", "_calculateWidths", "(", "$", "rows", ")", ";", "$", "this", "->", "_rowSeparator", "(", "$", "widths", ")", ";", "if", "(", "$", "config", "[", "'headers'", "]", "===", "true", ")", "{", "$", "this", "->", "_render", "(", "array_shift", "(", "$", "rows", ")", ",", "$", "widths", ",", "[", "'style'", "=>", "$", "config", "[", "'headerStyle'", "]", "]", ")", ";", "$", "this", "->", "_rowSeparator", "(", "$", "widths", ")", ";", "}", "if", "(", "!", "$", "rows", ")", "{", "return", ";", "}", "foreach", "(", "$", "rows", "as", "$", "line", ")", "{", "$", "this", "->", "_render", "(", "$", "line", ",", "$", "widths", ")", ";", "if", "(", "$", "config", "[", "'rowSeparator'", "]", "===", "true", ")", "{", "$", "this", "->", "_rowSeparator", "(", "$", "widths", ")", ";", "}", "}", "if", "(", "$", "config", "[", "'rowSeparator'", "]", "!==", "true", ")", "{", "$", "this", "->", "_rowSeparator", "(", "$", "widths", ")", ";", "}", "}" ]
Output a table. Data will be output based on the order of the values in the array. The keys will not be used to align data. @param array $rows The data to render out. @return void
[ "Output", "a", "table", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Helper/TableHelper.php#L126-L154
211,284
cakephp/cakephp
src/Event/EventManager.php
EventManager.instance
public static function instance($manager = null) { if ($manager instanceof EventManager) { static::$_generalManager = $manager; } if (empty(static::$_generalManager)) { static::$_generalManager = new static(); } static::$_generalManager->_isGlobal = true; return static::$_generalManager; }
php
public static function instance($manager = null) { if ($manager instanceof EventManager) { static::$_generalManager = $manager; } if (empty(static::$_generalManager)) { static::$_generalManager = new static(); } static::$_generalManager->_isGlobal = true; return static::$_generalManager; }
[ "public", "static", "function", "instance", "(", "$", "manager", "=", "null", ")", "{", "if", "(", "$", "manager", "instanceof", "EventManager", ")", "{", "static", "::", "$", "_generalManager", "=", "$", "manager", ";", "}", "if", "(", "empty", "(", "static", "::", "$", "_generalManager", ")", ")", "{", "static", "::", "$", "_generalManager", "=", "new", "static", "(", ")", ";", "}", "static", "::", "$", "_generalManager", "->", "_isGlobal", "=", "true", ";", "return", "static", "::", "$", "_generalManager", ";", "}" ]
Returns the globally available instance of a Cake\Event\EventManager this is used for dispatching events attached from outside the scope other managers were created. Usually for creating hook systems or inter-class communication If called with the first parameter, it will be set as the globally available instance @param \Cake\Event\EventManager|null $manager Event manager instance. @return static The global event manager
[ "Returns", "the", "globally", "available", "instance", "of", "a", "Cake", "\\", "Event", "\\", "EventManager", "this", "is", "used", "for", "dispatching", "events", "attached", "from", "outside", "the", "scope", "other", "managers", "were", "created", ".", "Usually", "for", "creating", "hook", "systems", "or", "inter", "-", "class", "communication" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/EventManager.php#L81-L93
211,285
cakephp/cakephp
src/Event/EventManager.php
EventManager.attach
public function attach($callable, $eventKey = null, array $options = []) { deprecationWarning('EventManager::attach() is deprecated. Use EventManager::on() instead.'); if ($eventKey === null) { $this->on($callable); return; } if ($options) { $this->on($eventKey, $options, $callable); return; } $this->on($eventKey, $callable); }
php
public function attach($callable, $eventKey = null, array $options = []) { deprecationWarning('EventManager::attach() is deprecated. Use EventManager::on() instead.'); if ($eventKey === null) { $this->on($callable); return; } if ($options) { $this->on($eventKey, $options, $callable); return; } $this->on($eventKey, $callable); }
[ "public", "function", "attach", "(", "$", "callable", ",", "$", "eventKey", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "deprecationWarning", "(", "'EventManager::attach() is deprecated. Use EventManager::on() instead.'", ")", ";", "if", "(", "$", "eventKey", "===", "null", ")", "{", "$", "this", "->", "on", "(", "$", "callable", ")", ";", "return", ";", "}", "if", "(", "$", "options", ")", "{", "$", "this", "->", "on", "(", "$", "eventKey", ",", "$", "options", ",", "$", "callable", ")", ";", "return", ";", "}", "$", "this", "->", "on", "(", "$", "eventKey", ",", "$", "callable", ")", ";", "}" ]
Adds a new listener to an event. @param callable|\Cake\Event\EventListenerInterface $callable PHP valid callback type or instance of Cake\Event\EventListenerInterface to be called when the event named with $eventKey is triggered. If a Cake\Event\EventListenerInterface instance is passed, then the `implementedEvents` method will be called on the object to register the declared events individually as methods to be managed by this class. It is possible to define multiple event handlers per event name. @param string|null $eventKey The event unique identifier name with which the callback will be associated. If $callable is an instance of Cake\Event\EventListenerInterface this argument will be ignored @param array $options used to set the `priority` flag to the listener. In the future more options may be added. Priorities are treated as queues. Lower values are called before higher ones, and multiple attachments added to the same priority queue will be treated in the order of insertion. @return void @throws \InvalidArgumentException When event key is missing or callable is not an instance of Cake\Event\EventListenerInterface. @deprecated 3.0.0 Use on() instead.
[ "Adds", "a", "new", "listener", "to", "an", "event", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/EventManager.php#L115-L129
211,286
cakephp/cakephp
src/Event/EventManager.php
EventManager._attachSubscriber
protected function _attachSubscriber(EventListenerInterface $subscriber) { foreach ((array)$subscriber->implementedEvents() as $eventKey => $function) { $options = []; $method = $function; if (is_array($function) && isset($function['callable'])) { list($method, $options) = $this->_extractCallable($function, $subscriber); } elseif (is_array($function) && is_numeric(key($function))) { foreach ($function as $f) { list($method, $options) = $this->_extractCallable($f, $subscriber); $this->on($eventKey, $options, $method); } continue; } if (is_string($method)) { $method = [$subscriber, $function]; } $this->on($eventKey, $options, $method); } }
php
protected function _attachSubscriber(EventListenerInterface $subscriber) { foreach ((array)$subscriber->implementedEvents() as $eventKey => $function) { $options = []; $method = $function; if (is_array($function) && isset($function['callable'])) { list($method, $options) = $this->_extractCallable($function, $subscriber); } elseif (is_array($function) && is_numeric(key($function))) { foreach ($function as $f) { list($method, $options) = $this->_extractCallable($f, $subscriber); $this->on($eventKey, $options, $method); } continue; } if (is_string($method)) { $method = [$subscriber, $function]; } $this->on($eventKey, $options, $method); } }
[ "protected", "function", "_attachSubscriber", "(", "EventListenerInterface", "$", "subscriber", ")", "{", "foreach", "(", "(", "array", ")", "$", "subscriber", "->", "implementedEvents", "(", ")", "as", "$", "eventKey", "=>", "$", "function", ")", "{", "$", "options", "=", "[", "]", ";", "$", "method", "=", "$", "function", ";", "if", "(", "is_array", "(", "$", "function", ")", "&&", "isset", "(", "$", "function", "[", "'callable'", "]", ")", ")", "{", "list", "(", "$", "method", ",", "$", "options", ")", "=", "$", "this", "->", "_extractCallable", "(", "$", "function", ",", "$", "subscriber", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "function", ")", "&&", "is_numeric", "(", "key", "(", "$", "function", ")", ")", ")", "{", "foreach", "(", "$", "function", "as", "$", "f", ")", "{", "list", "(", "$", "method", ",", "$", "options", ")", "=", "$", "this", "->", "_extractCallable", "(", "$", "f", ",", "$", "subscriber", ")", ";", "$", "this", "->", "on", "(", "$", "eventKey", ",", "$", "options", ",", "$", "method", ")", ";", "}", "continue", ";", "}", "if", "(", "is_string", "(", "$", "method", ")", ")", "{", "$", "method", "=", "[", "$", "subscriber", ",", "$", "function", "]", ";", "}", "$", "this", "->", "on", "(", "$", "eventKey", ",", "$", "options", ",", "$", "method", ")", ";", "}", "}" ]
Auxiliary function to attach all implemented callbacks of a Cake\Event\EventListenerInterface class instance as individual methods on this manager @param \Cake\Event\EventListenerInterface $subscriber Event listener. @return void
[ "Auxiliary", "function", "to", "attach", "all", "implemented", "callbacks", "of", "a", "Cake", "\\", "Event", "\\", "EventListenerInterface", "class", "instance", "as", "individual", "methods", "on", "this", "manager" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/EventManager.php#L170-L189
211,287
cakephp/cakephp
src/Event/EventManager.php
EventManager._extractCallable
protected function _extractCallable($function, $object) { $method = $function['callable']; $options = $function; unset($options['callable']); if (is_string($method)) { $method = [$object, $method]; } return [$method, $options]; }
php
protected function _extractCallable($function, $object) { $method = $function['callable']; $options = $function; unset($options['callable']); if (is_string($method)) { $method = [$object, $method]; } return [$method, $options]; }
[ "protected", "function", "_extractCallable", "(", "$", "function", ",", "$", "object", ")", "{", "$", "method", "=", "$", "function", "[", "'callable'", "]", ";", "$", "options", "=", "$", "function", ";", "unset", "(", "$", "options", "[", "'callable'", "]", ")", ";", "if", "(", "is_string", "(", "$", "method", ")", ")", "{", "$", "method", "=", "[", "$", "object", ",", "$", "method", "]", ";", "}", "return", "[", "$", "method", ",", "$", "options", "]", ";", "}" ]
Auxiliary function to extract and return a PHP callback type out of the callable definition from the return value of the `implementedEvents` method on a Cake\Event\EventListenerInterface @param array $function the array taken from a handler definition for an event @param \Cake\Event\EventListenerInterface $object The handler object @return callable
[ "Auxiliary", "function", "to", "extract", "and", "return", "a", "PHP", "callback", "type", "out", "of", "the", "callable", "definition", "from", "the", "return", "value", "of", "the", "implementedEvents", "method", "on", "a", "Cake", "\\", "Event", "\\", "EventListenerInterface" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/EventManager.php#L199-L209
211,288
cakephp/cakephp
src/Event/EventManager.php
EventManager.detach
public function detach($callable, $eventKey = null) { deprecationWarning('EventManager::detach() is deprecated. Use EventManager::off() instead.'); if ($eventKey === null) { $this->off($callable); return; } $this->off($eventKey, $callable); }
php
public function detach($callable, $eventKey = null) { deprecationWarning('EventManager::detach() is deprecated. Use EventManager::off() instead.'); if ($eventKey === null) { $this->off($callable); return; } $this->off($eventKey, $callable); }
[ "public", "function", "detach", "(", "$", "callable", ",", "$", "eventKey", "=", "null", ")", "{", "deprecationWarning", "(", "'EventManager::detach() is deprecated. Use EventManager::off() instead.'", ")", ";", "if", "(", "$", "eventKey", "===", "null", ")", "{", "$", "this", "->", "off", "(", "$", "callable", ")", ";", "return", ";", "}", "$", "this", "->", "off", "(", "$", "eventKey", ",", "$", "callable", ")", ";", "}" ]
Removes a listener from the active listeners. @param callable|\Cake\Event\EventListenerInterface $callable any valid PHP callback type or an instance of EventListenerInterface @param string|null $eventKey The event unique identifier name with which the callback has been associated @return void @deprecated 3.0.0 Use off() instead.
[ "Removes", "a", "listener", "from", "the", "active", "listeners", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/EventManager.php#L219-L228
211,289
cakephp/cakephp
src/Event/EventManager.php
EventManager._detachSubscriber
protected function _detachSubscriber(EventListenerInterface $subscriber, $eventKey = null) { $events = (array)$subscriber->implementedEvents(); if (!empty($eventKey) && empty($events[$eventKey])) { return; } if (!empty($eventKey)) { $events = [$eventKey => $events[$eventKey]]; } foreach ($events as $key => $function) { if (is_array($function)) { if (is_numeric(key($function))) { foreach ($function as $handler) { $handler = isset($handler['callable']) ? $handler['callable'] : $handler; $this->off($key, [$subscriber, $handler]); } continue; } $function = $function['callable']; } $this->off($key, [$subscriber, $function]); } }
php
protected function _detachSubscriber(EventListenerInterface $subscriber, $eventKey = null) { $events = (array)$subscriber->implementedEvents(); if (!empty($eventKey) && empty($events[$eventKey])) { return; } if (!empty($eventKey)) { $events = [$eventKey => $events[$eventKey]]; } foreach ($events as $key => $function) { if (is_array($function)) { if (is_numeric(key($function))) { foreach ($function as $handler) { $handler = isset($handler['callable']) ? $handler['callable'] : $handler; $this->off($key, [$subscriber, $handler]); } continue; } $function = $function['callable']; } $this->off($key, [$subscriber, $function]); } }
[ "protected", "function", "_detachSubscriber", "(", "EventListenerInterface", "$", "subscriber", ",", "$", "eventKey", "=", "null", ")", "{", "$", "events", "=", "(", "array", ")", "$", "subscriber", "->", "implementedEvents", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "eventKey", ")", "&&", "empty", "(", "$", "events", "[", "$", "eventKey", "]", ")", ")", "{", "return", ";", "}", "if", "(", "!", "empty", "(", "$", "eventKey", ")", ")", "{", "$", "events", "=", "[", "$", "eventKey", "=>", "$", "events", "[", "$", "eventKey", "]", "]", ";", "}", "foreach", "(", "$", "events", "as", "$", "key", "=>", "$", "function", ")", "{", "if", "(", "is_array", "(", "$", "function", ")", ")", "{", "if", "(", "is_numeric", "(", "key", "(", "$", "function", ")", ")", ")", "{", "foreach", "(", "$", "function", "as", "$", "handler", ")", "{", "$", "handler", "=", "isset", "(", "$", "handler", "[", "'callable'", "]", ")", "?", "$", "handler", "[", "'callable'", "]", ":", "$", "handler", ";", "$", "this", "->", "off", "(", "$", "key", ",", "[", "$", "subscriber", ",", "$", "handler", "]", ")", ";", "}", "continue", ";", "}", "$", "function", "=", "$", "function", "[", "'callable'", "]", ";", "}", "$", "this", "->", "off", "(", "$", "key", ",", "[", "$", "subscriber", ",", "$", "function", "]", ")", ";", "}", "}" ]
Auxiliary function to help detach all listeners provided by an object implementing EventListenerInterface @param \Cake\Event\EventListenerInterface $subscriber the subscriber to be detached @param string|null $eventKey optional event key name to unsubscribe the listener from @return void
[ "Auxiliary", "function", "to", "help", "detach", "all", "listeners", "provided", "by", "an", "object", "implementing", "EventListenerInterface" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/EventManager.php#L279-L301
211,290
cakephp/cakephp
src/Event/EventManager.php
EventManager.matchingListeners
public function matchingListeners($eventKeyPattern) { $matchPattern = '/' . preg_quote($eventKeyPattern, '/') . '/'; $matches = array_intersect_key( $this->_listeners, array_flip( preg_grep($matchPattern, array_keys($this->_listeners), 0) ) ); return $matches; }
php
public function matchingListeners($eventKeyPattern) { $matchPattern = '/' . preg_quote($eventKeyPattern, '/') . '/'; $matches = array_intersect_key( $this->_listeners, array_flip( preg_grep($matchPattern, array_keys($this->_listeners), 0) ) ); return $matches; }
[ "public", "function", "matchingListeners", "(", "$", "eventKeyPattern", ")", "{", "$", "matchPattern", "=", "'/'", ".", "preg_quote", "(", "$", "eventKeyPattern", ",", "'/'", ")", ".", "'/'", ";", "$", "matches", "=", "array_intersect_key", "(", "$", "this", "->", "_listeners", ",", "array_flip", "(", "preg_grep", "(", "$", "matchPattern", ",", "array_keys", "(", "$", "this", "->", "_listeners", ")", ",", "0", ")", ")", ")", ";", "return", "$", "matches", ";", "}" ]
Returns the listeners matching a specified pattern @param string $eventKeyPattern Pattern to match. @return array
[ "Returns", "the", "listeners", "matching", "a", "specified", "pattern" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/EventManager.php#L407-L418
211,291
cakephp/cakephp
src/Event/EventManager.php
EventManager.addEventToList
public function addEventToList(Event $event) { if ($this->_eventList) { $this->_eventList->add($event); } return $this; }
php
public function addEventToList(Event $event) { if ($this->_eventList) { $this->_eventList->add($event); } return $this; }
[ "public", "function", "addEventToList", "(", "Event", "$", "event", ")", "{", "if", "(", "$", "this", "->", "_eventList", ")", "{", "$", "this", "->", "_eventList", "->", "add", "(", "$", "event", ")", ";", "}", "return", "$", "this", ";", "}" ]
Adds an event to the list if the event list object is present. @param \Cake\Event\Event $event An event to add to the list. @return $this
[ "Adds", "an", "event", "to", "the", "list", "if", "the", "event", "list", "object", "is", "present", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/EventManager.php#L436-L443
211,292
cakephp/cakephp
src/Event/EventManager.php
EventManager.setEventList
public function setEventList(EventList $eventList) { $this->_eventList = $eventList; $this->_trackEvents = true; return $this; }
php
public function setEventList(EventList $eventList) { $this->_eventList = $eventList; $this->_trackEvents = true; return $this; }
[ "public", "function", "setEventList", "(", "EventList", "$", "eventList", ")", "{", "$", "this", "->", "_eventList", "=", "$", "eventList", ";", "$", "this", "->", "_trackEvents", "=", "true", ";", "return", "$", "this", ";", "}" ]
Enables the listing of dispatched events. @param \Cake\Event\EventList $eventList The event list object to use. @return $this
[ "Enables", "the", "listing", "of", "dispatched", "events", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/EventManager.php#L474-L480
211,293
cakephp/cakephp
src/I18n/Number.php
Number.precision
public static function precision($value, $precision = 3, array $options = []) { $formatter = static::formatter(['precision' => $precision, 'places' => $precision] + $options); return $formatter->format($value); }
php
public static function precision($value, $precision = 3, array $options = []) { $formatter = static::formatter(['precision' => $precision, 'places' => $precision] + $options); return $formatter->format($value); }
[ "public", "static", "function", "precision", "(", "$", "value", ",", "$", "precision", "=", "3", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "formatter", "=", "static", "::", "formatter", "(", "[", "'precision'", "=>", "$", "precision", ",", "'places'", "=>", "$", "precision", "]", "+", "$", "options", ")", ";", "return", "$", "formatter", "->", "format", "(", "$", "value", ")", ";", "}" ]
Formats a number with a level of precision. Options: - `locale`: The locale name to use for formatting the number, e.g. fr_FR @param float $value A floating point number. @param int $precision The precision of the returned number. @param array $options Additional options @return string Formatted float. @link https://book.cakephp.org/3.0/en/core-libraries/number.html#formatting-floating-point-numbers
[ "Formats", "a", "number", "with", "a", "level", "of", "precision", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Number.php#L70-L75
211,294
cakephp/cakephp
src/I18n/Number.php
Number.parseFloat
public static function parseFloat($value, array $options = []) { $formatter = static::formatter($options); return (float)$formatter->parse($value, NumberFormatter::TYPE_DOUBLE); }
php
public static function parseFloat($value, array $options = []) { $formatter = static::formatter($options); return (float)$formatter->parse($value, NumberFormatter::TYPE_DOUBLE); }
[ "public", "static", "function", "parseFloat", "(", "$", "value", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "formatter", "=", "static", "::", "formatter", "(", "$", "options", ")", ";", "return", "(", "float", ")", "$", "formatter", "->", "parse", "(", "$", "value", ",", "NumberFormatter", "::", "TYPE_DOUBLE", ")", ";", "}" ]
Parse a localized numeric string and transform it in a float point Options: - `locale` - The locale name to use for parsing the number, e.g. fr_FR - `type` - The formatter type to construct, set it to `currency` if you need to parse numbers representing money. @param string $value A numeric string. @param array $options An array with options. @return float point number
[ "Parse", "a", "localized", "numeric", "string", "and", "transform", "it", "in", "a", "float", "point" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Number.php#L161-L166
211,295
cakephp/cakephp
src/I18n/Number.php
Number.formatter
public static function formatter($options = []) { $locale = isset($options['locale']) ? $options['locale'] : ini_get('intl.default_locale'); if (!$locale) { $locale = static::DEFAULT_LOCALE; } $type = NumberFormatter::DECIMAL; if (!empty($options['type'])) { $type = $options['type']; if ($options['type'] === static::FORMAT_CURRENCY) { $type = NumberFormatter::CURRENCY; } } if (!isset(static::$_formatters[$locale][$type])) { static::$_formatters[$locale][$type] = new NumberFormatter($locale, $type); } $formatter = static::$_formatters[$locale][$type]; $options = array_intersect_key($options, [ 'places' => null, 'precision' => null, 'pattern' => null, 'useIntlCode' => null ]); if (empty($options)) { return $formatter; } $formatter = clone $formatter; return static::_setAttributes($formatter, $options); }
php
public static function formatter($options = []) { $locale = isset($options['locale']) ? $options['locale'] : ini_get('intl.default_locale'); if (!$locale) { $locale = static::DEFAULT_LOCALE; } $type = NumberFormatter::DECIMAL; if (!empty($options['type'])) { $type = $options['type']; if ($options['type'] === static::FORMAT_CURRENCY) { $type = NumberFormatter::CURRENCY; } } if (!isset(static::$_formatters[$locale][$type])) { static::$_formatters[$locale][$type] = new NumberFormatter($locale, $type); } $formatter = static::$_formatters[$locale][$type]; $options = array_intersect_key($options, [ 'places' => null, 'precision' => null, 'pattern' => null, 'useIntlCode' => null ]); if (empty($options)) { return $formatter; } $formatter = clone $formatter; return static::_setAttributes($formatter, $options); }
[ "public", "static", "function", "formatter", "(", "$", "options", "=", "[", "]", ")", "{", "$", "locale", "=", "isset", "(", "$", "options", "[", "'locale'", "]", ")", "?", "$", "options", "[", "'locale'", "]", ":", "ini_get", "(", "'intl.default_locale'", ")", ";", "if", "(", "!", "$", "locale", ")", "{", "$", "locale", "=", "static", "::", "DEFAULT_LOCALE", ";", "}", "$", "type", "=", "NumberFormatter", "::", "DECIMAL", ";", "if", "(", "!", "empty", "(", "$", "options", "[", "'type'", "]", ")", ")", "{", "$", "type", "=", "$", "options", "[", "'type'", "]", ";", "if", "(", "$", "options", "[", "'type'", "]", "===", "static", "::", "FORMAT_CURRENCY", ")", "{", "$", "type", "=", "NumberFormatter", "::", "CURRENCY", ";", "}", "}", "if", "(", "!", "isset", "(", "static", "::", "$", "_formatters", "[", "$", "locale", "]", "[", "$", "type", "]", ")", ")", "{", "static", "::", "$", "_formatters", "[", "$", "locale", "]", "[", "$", "type", "]", "=", "new", "NumberFormatter", "(", "$", "locale", ",", "$", "type", ")", ";", "}", "$", "formatter", "=", "static", "::", "$", "_formatters", "[", "$", "locale", "]", "[", "$", "type", "]", ";", "$", "options", "=", "array_intersect_key", "(", "$", "options", ",", "[", "'places'", "=>", "null", ",", "'precision'", "=>", "null", ",", "'pattern'", "=>", "null", ",", "'useIntlCode'", "=>", "null", "]", ")", ";", "if", "(", "empty", "(", "$", "options", ")", ")", "{", "return", "$", "formatter", ";", "}", "$", "formatter", "=", "clone", "$", "formatter", ";", "return", "static", "::", "_setAttributes", "(", "$", "formatter", ",", "$", "options", ")", ";", "}" ]
Returns a formatter object that can be reused for similar formatting task under the same locale and options. This is often a speedier alternative to using other methods in this class as only one formatter object needs to be constructed. ### Options - `locale` - The locale name to use for formatting the number, e.g. fr_FR - `type` - The formatter type to construct, set it to `currency` if you need to format numbers representing money or a NumberFormatter constant. - `places` - Number of decimal places to use. e.g. 2 - `precision` - Maximum Number of decimal places to use, e.g. 2 - `pattern` - An ICU number pattern to use for formatting the number. e.g #,##0.00 - `useIntlCode` - Whether or not to replace the currency symbol with the international currency code. @param array $options An array with options. @return \NumberFormatter The configured formatter instance
[ "Returns", "a", "formatter", "object", "that", "can", "be", "reused", "for", "similar", "formatting", "task", "under", "the", "same", "locale", "and", "options", ".", "This", "is", "often", "a", "speedier", "alternative", "to", "using", "other", "methods", "in", "this", "class", "as", "only", "one", "formatter", "object", "needs", "to", "be", "constructed", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Number.php#L287-L322
211,296
cakephp/cakephp
src/I18n/Number.php
Number.config
public static function config($locale, $type = NumberFormatter::DECIMAL, array $options = []) { static::$_formatters[$locale][$type] = static::_setAttributes( new NumberFormatter($locale, $type), $options ); }
php
public static function config($locale, $type = NumberFormatter::DECIMAL, array $options = []) { static::$_formatters[$locale][$type] = static::_setAttributes( new NumberFormatter($locale, $type), $options ); }
[ "public", "static", "function", "config", "(", "$", "locale", ",", "$", "type", "=", "NumberFormatter", "::", "DECIMAL", ",", "array", "$", "options", "=", "[", "]", ")", "{", "static", "::", "$", "_formatters", "[", "$", "locale", "]", "[", "$", "type", "]", "=", "static", "::", "_setAttributes", "(", "new", "NumberFormatter", "(", "$", "locale", ",", "$", "type", ")", ",", "$", "options", ")", ";", "}" ]
Configure formatters. @param string $locale The locale name to use for formatting the number, e.g. fr_FR @param int $type The formatter type to construct. Defaults to NumberFormatter::DECIMAL. @param array $options See Number::formatter() for possible options. @return void
[ "Configure", "formatters", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Number.php#L332-L338
211,297
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent.startup
public function startup(Event $event) { /** @var \Cake\Controller\Controller $controller */ $controller = $event->getSubject(); $request = $controller->request; $this->session = $request->getSession(); $this->_action = $request->getParam('action'); $hasData = ($request->getData() || $request->is(['put', 'post', 'delete', 'patch'])); try { $this->_secureRequired($controller); $this->_authRequired($controller); $isNotRequestAction = !$request->getParam('requested'); if ($this->_action === $this->_config['blackHoleCallback']) { throw new AuthSecurityException(sprintf('Action %s is defined as the blackhole callback.', $this->_action)); } if (!in_array($this->_action, (array)$this->_config['unlockedActions']) && $hasData && $isNotRequestAction && $this->_config['validatePost'] ) { $this->_validatePost($controller); } } catch (SecurityException $se) { return $this->blackHole($controller, $se->getType(), $se); } $request = $this->generateToken($request); if ($hasData && is_array($controller->getRequest()->getData())) { $request = $request->withoutData('_Token'); } $controller->setRequest($request); }
php
public function startup(Event $event) { /** @var \Cake\Controller\Controller $controller */ $controller = $event->getSubject(); $request = $controller->request; $this->session = $request->getSession(); $this->_action = $request->getParam('action'); $hasData = ($request->getData() || $request->is(['put', 'post', 'delete', 'patch'])); try { $this->_secureRequired($controller); $this->_authRequired($controller); $isNotRequestAction = !$request->getParam('requested'); if ($this->_action === $this->_config['blackHoleCallback']) { throw new AuthSecurityException(sprintf('Action %s is defined as the blackhole callback.', $this->_action)); } if (!in_array($this->_action, (array)$this->_config['unlockedActions']) && $hasData && $isNotRequestAction && $this->_config['validatePost'] ) { $this->_validatePost($controller); } } catch (SecurityException $se) { return $this->blackHole($controller, $se->getType(), $se); } $request = $this->generateToken($request); if ($hasData && is_array($controller->getRequest()->getData())) { $request = $request->withoutData('_Token'); } $controller->setRequest($request); }
[ "public", "function", "startup", "(", "Event", "$", "event", ")", "{", "/** @var \\Cake\\Controller\\Controller $controller */", "$", "controller", "=", "$", "event", "->", "getSubject", "(", ")", ";", "$", "request", "=", "$", "controller", "->", "request", ";", "$", "this", "->", "session", "=", "$", "request", "->", "getSession", "(", ")", ";", "$", "this", "->", "_action", "=", "$", "request", "->", "getParam", "(", "'action'", ")", ";", "$", "hasData", "=", "(", "$", "request", "->", "getData", "(", ")", "||", "$", "request", "->", "is", "(", "[", "'put'", ",", "'post'", ",", "'delete'", ",", "'patch'", "]", ")", ")", ";", "try", "{", "$", "this", "->", "_secureRequired", "(", "$", "controller", ")", ";", "$", "this", "->", "_authRequired", "(", "$", "controller", ")", ";", "$", "isNotRequestAction", "=", "!", "$", "request", "->", "getParam", "(", "'requested'", ")", ";", "if", "(", "$", "this", "->", "_action", "===", "$", "this", "->", "_config", "[", "'blackHoleCallback'", "]", ")", "{", "throw", "new", "AuthSecurityException", "(", "sprintf", "(", "'Action %s is defined as the blackhole callback.'", ",", "$", "this", "->", "_action", ")", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "this", "->", "_action", ",", "(", "array", ")", "$", "this", "->", "_config", "[", "'unlockedActions'", "]", ")", "&&", "$", "hasData", "&&", "$", "isNotRequestAction", "&&", "$", "this", "->", "_config", "[", "'validatePost'", "]", ")", "{", "$", "this", "->", "_validatePost", "(", "$", "controller", ")", ";", "}", "}", "catch", "(", "SecurityException", "$", "se", ")", "{", "return", "$", "this", "->", "blackHole", "(", "$", "controller", ",", "$", "se", "->", "getType", "(", ")", ",", "$", "se", ")", ";", "}", "$", "request", "=", "$", "this", "->", "generateToken", "(", "$", "request", ")", ";", "if", "(", "$", "hasData", "&&", "is_array", "(", "$", "controller", "->", "getRequest", "(", ")", "->", "getData", "(", ")", ")", ")", "{", "$", "request", "=", "$", "request", "->", "withoutData", "(", "'_Token'", ")", ";", "}", "$", "controller", "->", "setRequest", "(", "$", "request", ")", ";", "}" ]
Component startup. All security checking happens here. @param \Cake\Event\Event $event An Event instance @return mixed
[ "Component", "startup", ".", "All", "security", "checking", "happens", "here", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L101-L135
211,298
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent._throwException
protected function _throwException($exception = null) { if ($exception !== null) { if (!Configure::read('debug') && $exception instanceof SecurityException) { $exception->setReason($exception->getMessage()); $exception->setMessage(self::DEFAULT_EXCEPTION_MESSAGE); } throw $exception; } throw new BadRequestException(self::DEFAULT_EXCEPTION_MESSAGE); }
php
protected function _throwException($exception = null) { if ($exception !== null) { if (!Configure::read('debug') && $exception instanceof SecurityException) { $exception->setReason($exception->getMessage()); $exception->setMessage(self::DEFAULT_EXCEPTION_MESSAGE); } throw $exception; } throw new BadRequestException(self::DEFAULT_EXCEPTION_MESSAGE); }
[ "protected", "function", "_throwException", "(", "$", "exception", "=", "null", ")", "{", "if", "(", "$", "exception", "!==", "null", ")", "{", "if", "(", "!", "Configure", "::", "read", "(", "'debug'", ")", "&&", "$", "exception", "instanceof", "SecurityException", ")", "{", "$", "exception", "->", "setReason", "(", "$", "exception", "->", "getMessage", "(", ")", ")", ";", "$", "exception", "->", "setMessage", "(", "self", "::", "DEFAULT_EXCEPTION_MESSAGE", ")", ";", "}", "throw", "$", "exception", ";", "}", "throw", "new", "BadRequestException", "(", "self", "::", "DEFAULT_EXCEPTION_MESSAGE", ")", ";", "}" ]
Check debug status and throw an Exception based on the existing one @param \Cake\Controller\Exception\SecurityException|null $exception Additional debug info describing the cause @throws \Cake\Http\Exception\BadRequestException @return void
[ "Check", "debug", "status", "and", "throw", "an", "Exception", "based", "on", "the", "existing", "one" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L205-L215
211,299
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent._secureRequired
protected function _secureRequired(Controller $controller) { if (is_array($this->_config['requireSecure']) && !empty($this->_config['requireSecure']) ) { $requireSecure = $this->_config['requireSecure']; if (in_array($this->_action, $requireSecure) || $requireSecure === ['*']) { if (!$this->getController()->getRequest()->is('ssl')) { throw new SecurityException( 'Request is not SSL and the action is required to be secure' ); } } } return true; }
php
protected function _secureRequired(Controller $controller) { if (is_array($this->_config['requireSecure']) && !empty($this->_config['requireSecure']) ) { $requireSecure = $this->_config['requireSecure']; if (in_array($this->_action, $requireSecure) || $requireSecure === ['*']) { if (!$this->getController()->getRequest()->is('ssl')) { throw new SecurityException( 'Request is not SSL and the action is required to be secure' ); } } } return true; }
[ "protected", "function", "_secureRequired", "(", "Controller", "$", "controller", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "_config", "[", "'requireSecure'", "]", ")", "&&", "!", "empty", "(", "$", "this", "->", "_config", "[", "'requireSecure'", "]", ")", ")", "{", "$", "requireSecure", "=", "$", "this", "->", "_config", "[", "'requireSecure'", "]", ";", "if", "(", "in_array", "(", "$", "this", "->", "_action", ",", "$", "requireSecure", ")", "||", "$", "requireSecure", "===", "[", "'*'", "]", ")", "{", "if", "(", "!", "$", "this", "->", "getController", "(", ")", "->", "getRequest", "(", ")", "->", "is", "(", "'ssl'", ")", ")", "{", "throw", "new", "SecurityException", "(", "'Request is not SSL and the action is required to be secure'", ")", ";", "}", "}", "}", "return", "true", ";", "}" ]
Check if access requires secure connection @param \Cake\Controller\Controller $controller Instantiating controller @return bool true if secure connection required
[ "Check", "if", "access", "requires", "secure", "connection" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L238-L255