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
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
yiisoft/yii-core
|
src/base/Event.php
|
Event.setResult
|
public function setResult($result): self
{
$this->_result = $result;
$this->_hasResult = true;
return $this;
}
|
php
|
public function setResult($result): self
{
$this->_result = $result;
$this->_hasResult = true;
return $this;
}
|
[
"public",
"function",
"setResult",
"(",
"$",
"result",
")",
":",
"self",
"{",
"$",
"this",
"->",
"_result",
"=",
"$",
"result",
";",
"$",
"this",
"->",
"_hasResult",
"=",
"true",
";",
"return",
"$",
"this",
";",
"}"
] |
Set result associated with this event.
@param mixed $result result associated with this event.
@return self
|
[
"Set",
"result",
"associated",
"with",
"this",
"event",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Event.php#L97-L103
|
train
|
yiisoft/yii-core
|
src/base/Event.php
|
Event.getName
|
public function getName()
{
if ($this->_name === null) {
$this->_name = $this->defaultName();
}
return $this->_name;
}
|
php
|
public function getName()
{
if ($this->_name === null) {
$this->_name = $this->defaultName();
}
return $this->_name;
}
|
[
"public",
"function",
"getName",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_name",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_name",
"=",
"$",
"this",
"->",
"defaultName",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_name",
";",
"}"
] |
Returns event name.
@return string event name.
@since 3.0.0
|
[
"Returns",
"event",
"name",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Event.php#L119-L125
|
train
|
yiisoft/yii-core
|
src/http/HeaderCollection.php
|
HeaderCollection.fromArray
|
public function fromArray(array $array)
{
$this->removeAll();
foreach ($array as $name => $values) {
if (\is_array($values)) {
foreach ($values as $value) {
$this->add($name, $value);
}
} else {
$this->add($name, $values);
}
}
}
|
php
|
public function fromArray(array $array)
{
$this->removeAll();
foreach ($array as $name => $values) {
if (\is_array($values)) {
foreach ($values as $value) {
$this->add($name, $value);
}
} else {
$this->add($name, $values);
}
}
}
|
[
"public",
"function",
"fromArray",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"this",
"->",
"removeAll",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"name",
"=>",
"$",
"values",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"values",
")",
";",
"}",
"}",
"}"
] |
Populates the header collection from an array.
@param array $array the headers to populate from
@since 2.0.3
|
[
"Populates",
"the",
"header",
"collection",
"from",
"an",
"array",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/http/HeaderCollection.php#L180-L192
|
train
|
yiisoft/yii-core
|
src/helpers/BaseYii.php
|
BaseYii.createObject
|
public static function createObject($config, array $params = [], ContainerInterface $container = null)
{
return static::get('factory', $container)->create($config, $params);
}
|
php
|
public static function createObject($config, array $params = [], ContainerInterface $container = null)
{
return static::get('factory', $container)->create($config, $params);
}
|
[
"public",
"static",
"function",
"createObject",
"(",
"$",
"config",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"ContainerInterface",
"$",
"container",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"get",
"(",
"'factory'",
",",
"$",
"container",
")",
"->",
"create",
"(",
"$",
"config",
",",
"$",
"params",
")",
";",
"}"
] |
Creates a new object using the given configuration and constructor parameters.
@param string|array|callable $config the object configuration.
@param array $params the constructor parameters.
@param ContainerInterface $container the container, default one will be used if not given.
@return object the created object.
@see \yii\di\Factory::create()
|
[
"Creates",
"a",
"new",
"object",
"using",
"the",
"given",
"configuration",
"and",
"constructor",
"parameters",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseYii.php#L67-L70
|
train
|
yiisoft/yii-core
|
src/helpers/BaseYii.php
|
BaseYii.log
|
public static function log($level, $message, $category = 'application')
{
if (LogLevel::DEBUG === $level && !YII_DEBUG) {
return;
}
$logger = static::get('logger', null, false);
if ($logger) {
return $logger->log($level, $message, ['category' => $category]);
}
error_log($message);
}
|
php
|
public static function log($level, $message, $category = 'application')
{
if (LogLevel::DEBUG === $level && !YII_DEBUG) {
return;
}
$logger = static::get('logger', null, false);
if ($logger) {
return $logger->log($level, $message, ['category' => $category]);
}
error_log($message);
}
|
[
"public",
"static",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"category",
"=",
"'application'",
")",
"{",
"if",
"(",
"LogLevel",
"::",
"DEBUG",
"===",
"$",
"level",
"&&",
"!",
"YII_DEBUG",
")",
"{",
"return",
";",
"}",
"$",
"logger",
"=",
"static",
"::",
"get",
"(",
"'logger'",
",",
"null",
",",
"false",
")",
";",
"if",
"(",
"$",
"logger",
")",
"{",
"return",
"$",
"logger",
"->",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"[",
"'category'",
"=>",
"$",
"category",
"]",
")",
";",
"}",
"error_log",
"(",
"$",
"message",
")",
";",
"}"
] |
Logs given message with level and category.
Uses `logger` service if container is available.
Else logs message with PHP built-in `error_log()`.
@param string $level log level.
@param mixed $message the message to be logged. This can be a simple string or a more
complex data structure, such as array.
@param string $category the category of the message.
@since 3.0.0
@see Psr\Log\LoggerInterface::log()
|
[
"Logs",
"given",
"message",
"with",
"level",
"and",
"category",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseYii.php#L117-L129
|
train
|
yiisoft/yii-core
|
src/helpers/BaseYii.php
|
BaseYii.getLocaleString
|
public static function getLocaleString(string $default = 'en-US'): string
{
$i18n = static::get('i18n', null, false);
return $i18n ? (string)$i18n->getLocale() : $default;
}
|
php
|
public static function getLocaleString(string $default = 'en-US'): string
{
$i18n = static::get('i18n', null, false);
return $i18n ? (string)$i18n->getLocale() : $default;
}
|
[
"public",
"static",
"function",
"getLocaleString",
"(",
"string",
"$",
"default",
"=",
"'en-US'",
")",
":",
"string",
"{",
"$",
"i18n",
"=",
"static",
"::",
"get",
"(",
"'i18n'",
",",
"null",
",",
"false",
")",
";",
"return",
"$",
"i18n",
"?",
"(",
"string",
")",
"$",
"i18n",
"->",
"getLocale",
"(",
")",
":",
"$",
"default",
";",
"}"
] |
Returns current locale if set or default.
@return string
|
[
"Returns",
"current",
"locale",
"if",
"set",
"or",
"default",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseYii.php#L281-L286
|
train
|
yiisoft/yii-core
|
src/helpers/BaseYii.php
|
BaseYii.getSourceLocaleString
|
public static function getSourceLocaleString(string $default = 'en-US'): string
{
$view = static::get('view', null, false);
return $view ? (string)$view->getSourceLocale() : $default;
}
|
php
|
public static function getSourceLocaleString(string $default = 'en-US'): string
{
$view = static::get('view', null, false);
return $view ? (string)$view->getSourceLocale() : $default;
}
|
[
"public",
"static",
"function",
"getSourceLocaleString",
"(",
"string",
"$",
"default",
"=",
"'en-US'",
")",
":",
"string",
"{",
"$",
"view",
"=",
"static",
"::",
"get",
"(",
"'view'",
",",
"null",
",",
"false",
")",
";",
"return",
"$",
"view",
"?",
"(",
"string",
")",
"$",
"view",
"->",
"getSourceLocale",
"(",
")",
":",
"$",
"default",
";",
"}"
] |
Returns current source locale if set or default.
@return string
|
[
"Returns",
"current",
"source",
"locale",
"if",
"set",
"or",
"default",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseYii.php#L292-L297
|
train
|
yiisoft/yii-core
|
src/helpers/BaseYii.php
|
BaseYii.getTimeZone
|
public static function getTimeZone(string $default = 'UTC'): string
{
$i18n = static::get('i18n', null, false);
return $i18n ? (string)$i18n->getTimeZone() : $default;
}
|
php
|
public static function getTimeZone(string $default = 'UTC'): string
{
$i18n = static::get('i18n', null, false);
return $i18n ? (string)$i18n->getTimeZone() : $default;
}
|
[
"public",
"static",
"function",
"getTimeZone",
"(",
"string",
"$",
"default",
"=",
"'UTC'",
")",
":",
"string",
"{",
"$",
"i18n",
"=",
"static",
"::",
"get",
"(",
"'i18n'",
",",
"null",
",",
"false",
")",
";",
"return",
"$",
"i18n",
"?",
"(",
"string",
")",
"$",
"i18n",
"->",
"getTimeZone",
"(",
")",
":",
"$",
"default",
";",
"}"
] |
Returns current timezone if set or default.
@return string
|
[
"Returns",
"current",
"timezone",
"if",
"set",
"or",
"default",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseYii.php#L303-L308
|
train
|
yiisoft/yii-core
|
src/helpers/BaseYii.php
|
BaseYii.getEncoding
|
public static function getEncoding(ContainerInterface $container = null): string
{
$i18n = static::get('i18n', $container, false);
return $i18n ? $i18n->getEncoding() : mb_internal_encoding();
}
|
php
|
public static function getEncoding(ContainerInterface $container = null): string
{
$i18n = static::get('i18n', $container, false);
return $i18n ? $i18n->getEncoding() : mb_internal_encoding();
}
|
[
"public",
"static",
"function",
"getEncoding",
"(",
"ContainerInterface",
"$",
"container",
"=",
"null",
")",
":",
"string",
"{",
"$",
"i18n",
"=",
"static",
"::",
"get",
"(",
"'i18n'",
",",
"$",
"container",
",",
"false",
")",
";",
"return",
"$",
"i18n",
"?",
"$",
"i18n",
"->",
"getEncoding",
"(",
")",
":",
"mb_internal_encoding",
"(",
")",
";",
"}"
] |
Returns current application encoding.
@param ContainerInterface|null $container
@return string
|
[
"Returns",
"current",
"application",
"encoding",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseYii.php#L315-L320
|
train
|
yiisoft/yii-core
|
src/helpers/BaseYii.php
|
BaseYii.get
|
public static function get(string $name, ContainerInterface $container = null, bool $throwException = true)
{
if ($container === null) {
$container = static::$container;
}
if ($container !== null && $container->has($name)) {
return static::$container->get($name);
}
if ($throwException) {
throw new InvalidConfigException("No '$name' service can be found");
} else {
return null;
}
}
|
php
|
public static function get(string $name, ContainerInterface $container = null, bool $throwException = true)
{
if ($container === null) {
$container = static::$container;
}
if ($container !== null && $container->has($name)) {
return static::$container->get($name);
}
if ($throwException) {
throw new InvalidConfigException("No '$name' service can be found");
} else {
return null;
}
}
|
[
"public",
"static",
"function",
"get",
"(",
"string",
"$",
"name",
",",
"ContainerInterface",
"$",
"container",
"=",
"null",
",",
"bool",
"$",
"throwException",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"container",
"===",
"null",
")",
"{",
"$",
"container",
"=",
"static",
"::",
"$",
"container",
";",
"}",
"if",
"(",
"$",
"container",
"!==",
"null",
"&&",
"$",
"container",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"return",
"static",
"::",
"$",
"container",
"->",
"get",
"(",
"$",
"name",
")",
";",
"}",
"if",
"(",
"$",
"throwException",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"\"No '$name' service can be found\"",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns service from container.
@param string $name service or class/interface name.
@param ContainerInterface $container DI container, default one will be used if not given.
@param bool $throwException whether to throw an exception or return null.
@return object service object.
|
[
"Returns",
"service",
"from",
"container",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseYii.php#L329-L344
|
train
|
yiisoft/yii-core
|
src/base/Security.php
|
Security.decrypt
|
protected function decrypt($data, $passwordBased, $secret, $info)
{
if (!extension_loaded('openssl')) {
throw new InvalidConfigException('Encryption requires the OpenSSL PHP extension');
}
if (!isset($this->allowedCiphers[$this->cipher][0], $this->allowedCiphers[$this->cipher][1])) {
throw new InvalidConfigException($this->cipher . ' is not an allowed cipher');
}
[$blockSize, $keySize] = $this->allowedCiphers[$this->cipher];
$keySalt = StringHelper::byteSubstr($data, 0, $keySize);
if ($passwordBased) {
$key = $this->pbkdf2($this->kdfHash, $secret, $keySalt, $this->derivationIterations, $keySize);
} else {
$key = $this->hkdf($this->kdfHash, $secret, $keySalt, $info, $keySize);
}
$authKey = $this->hkdf($this->kdfHash, $key, null, $this->authKeyInfo, $keySize);
$data = $this->validateData(StringHelper::byteSubstr($data, $keySize), $authKey);
if ($data === false) {
return false;
}
$iv = StringHelper::byteSubstr($data, 0, $blockSize);
$encrypted = StringHelper::byteSubstr($data, $blockSize);
$decrypted = openssl_decrypt($encrypted, $this->cipher, $key, OPENSSL_RAW_DATA, $iv);
if ($decrypted === false) {
throw new \yii\exceptions\Exception('OpenSSL failure on decryption: ' . openssl_error_string());
}
return $decrypted;
}
|
php
|
protected function decrypt($data, $passwordBased, $secret, $info)
{
if (!extension_loaded('openssl')) {
throw new InvalidConfigException('Encryption requires the OpenSSL PHP extension');
}
if (!isset($this->allowedCiphers[$this->cipher][0], $this->allowedCiphers[$this->cipher][1])) {
throw new InvalidConfigException($this->cipher . ' is not an allowed cipher');
}
[$blockSize, $keySize] = $this->allowedCiphers[$this->cipher];
$keySalt = StringHelper::byteSubstr($data, 0, $keySize);
if ($passwordBased) {
$key = $this->pbkdf2($this->kdfHash, $secret, $keySalt, $this->derivationIterations, $keySize);
} else {
$key = $this->hkdf($this->kdfHash, $secret, $keySalt, $info, $keySize);
}
$authKey = $this->hkdf($this->kdfHash, $key, null, $this->authKeyInfo, $keySize);
$data = $this->validateData(StringHelper::byteSubstr($data, $keySize), $authKey);
if ($data === false) {
return false;
}
$iv = StringHelper::byteSubstr($data, 0, $blockSize);
$encrypted = StringHelper::byteSubstr($data, $blockSize);
$decrypted = openssl_decrypt($encrypted, $this->cipher, $key, OPENSSL_RAW_DATA, $iv);
if ($decrypted === false) {
throw new \yii\exceptions\Exception('OpenSSL failure on decryption: ' . openssl_error_string());
}
return $decrypted;
}
|
[
"protected",
"function",
"decrypt",
"(",
"$",
"data",
",",
"$",
"passwordBased",
",",
"$",
"secret",
",",
"$",
"info",
")",
"{",
"if",
"(",
"!",
"extension_loaded",
"(",
"'openssl'",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"'Encryption requires the OpenSSL PHP extension'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"allowedCiphers",
"[",
"$",
"this",
"->",
"cipher",
"]",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"allowedCiphers",
"[",
"$",
"this",
"->",
"cipher",
"]",
"[",
"1",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"$",
"this",
"->",
"cipher",
".",
"' is not an allowed cipher'",
")",
";",
"}",
"[",
"$",
"blockSize",
",",
"$",
"keySize",
"]",
"=",
"$",
"this",
"->",
"allowedCiphers",
"[",
"$",
"this",
"->",
"cipher",
"]",
";",
"$",
"keySalt",
"=",
"StringHelper",
"::",
"byteSubstr",
"(",
"$",
"data",
",",
"0",
",",
"$",
"keySize",
")",
";",
"if",
"(",
"$",
"passwordBased",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"pbkdf2",
"(",
"$",
"this",
"->",
"kdfHash",
",",
"$",
"secret",
",",
"$",
"keySalt",
",",
"$",
"this",
"->",
"derivationIterations",
",",
"$",
"keySize",
")",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"hkdf",
"(",
"$",
"this",
"->",
"kdfHash",
",",
"$",
"secret",
",",
"$",
"keySalt",
",",
"$",
"info",
",",
"$",
"keySize",
")",
";",
"}",
"$",
"authKey",
"=",
"$",
"this",
"->",
"hkdf",
"(",
"$",
"this",
"->",
"kdfHash",
",",
"$",
"key",
",",
"null",
",",
"$",
"this",
"->",
"authKeyInfo",
",",
"$",
"keySize",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"validateData",
"(",
"StringHelper",
"::",
"byteSubstr",
"(",
"$",
"data",
",",
"$",
"keySize",
")",
",",
"$",
"authKey",
")",
";",
"if",
"(",
"$",
"data",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"iv",
"=",
"StringHelper",
"::",
"byteSubstr",
"(",
"$",
"data",
",",
"0",
",",
"$",
"blockSize",
")",
";",
"$",
"encrypted",
"=",
"StringHelper",
"::",
"byteSubstr",
"(",
"$",
"data",
",",
"$",
"blockSize",
")",
";",
"$",
"decrypted",
"=",
"openssl_decrypt",
"(",
"$",
"encrypted",
",",
"$",
"this",
"->",
"cipher",
",",
"$",
"key",
",",
"OPENSSL_RAW_DATA",
",",
"$",
"iv",
")",
";",
"if",
"(",
"$",
"decrypted",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"yii",
"\\",
"exceptions",
"\\",
"Exception",
"(",
"'OpenSSL failure on decryption: '",
".",
"openssl_error_string",
"(",
")",
")",
";",
"}",
"return",
"$",
"decrypted",
";",
"}"
] |
Decrypts data.
@param string $data encrypted data to be decrypted.
@param bool $passwordBased set true to use password-based key derivation
@param string $secret the decryption password or key
@param string|null $info context/application specific information, @see encrypt()
@return bool|string the decrypted data or false on authentication failure
@throws InvalidConfigException on OpenSSL not loaded
@throws Exception on OpenSSL error
@see encrypt()
|
[
"Decrypts",
"data",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Security.php#L216-L249
|
train
|
yiisoft/yii-core
|
src/base/Module.php
|
Module.createController
|
public function createController($route)
{
if ($route === '') {
$route = $this->defaultRoute;
}
// double slashes or leading/ending slashes may cause substr problem
$route = trim($route, '/');
if (strpos($route, '//') !== false) {
return false;
}
if (strpos($route, '/') !== false) {
[$id, $route] = explode('/', $route, 2);
} else {
$id = $route;
$route = '';
}
// module and controller map take precedence
if (isset($this->controllerMap[$id])) {
$controller = $this->app->createObject($this->controllerMap[$id], [$id, $this]);
return [$controller, $route];
}
$module = $this->getModule($id);
if ($module !== null) {
return $module->createController($route);
}
if (($pos = strrpos($route, '/')) !== false) {
$id .= '/' . substr($route, 0, $pos);
$route = substr($route, $pos + 1);
}
$controller = $this->createControllerByID($id);
if ($controller === null && $route !== '') {
$controller = $this->createControllerByID($id . '/' . $route);
$route = '';
}
return $controller === null ? false : [$controller, $route];
}
|
php
|
public function createController($route)
{
if ($route === '') {
$route = $this->defaultRoute;
}
// double slashes or leading/ending slashes may cause substr problem
$route = trim($route, '/');
if (strpos($route, '//') !== false) {
return false;
}
if (strpos($route, '/') !== false) {
[$id, $route] = explode('/', $route, 2);
} else {
$id = $route;
$route = '';
}
// module and controller map take precedence
if (isset($this->controllerMap[$id])) {
$controller = $this->app->createObject($this->controllerMap[$id], [$id, $this]);
return [$controller, $route];
}
$module = $this->getModule($id);
if ($module !== null) {
return $module->createController($route);
}
if (($pos = strrpos($route, '/')) !== false) {
$id .= '/' . substr($route, 0, $pos);
$route = substr($route, $pos + 1);
}
$controller = $this->createControllerByID($id);
if ($controller === null && $route !== '') {
$controller = $this->createControllerByID($id . '/' . $route);
$route = '';
}
return $controller === null ? false : [$controller, $route];
}
|
[
"public",
"function",
"createController",
"(",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"===",
"''",
")",
"{",
"$",
"route",
"=",
"$",
"this",
"->",
"defaultRoute",
";",
"}",
"// double slashes or leading/ending slashes may cause substr problem",
"$",
"route",
"=",
"trim",
"(",
"$",
"route",
",",
"'/'",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"route",
",",
"'//'",
")",
"!==",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"route",
",",
"'/'",
")",
"!==",
"false",
")",
"{",
"[",
"$",
"id",
",",
"$",
"route",
"]",
"=",
"explode",
"(",
"'/'",
",",
"$",
"route",
",",
"2",
")",
";",
"}",
"else",
"{",
"$",
"id",
"=",
"$",
"route",
";",
"$",
"route",
"=",
"''",
";",
"}",
"// module and controller map take precedence",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"controllerMap",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"app",
"->",
"createObject",
"(",
"$",
"this",
"->",
"controllerMap",
"[",
"$",
"id",
"]",
",",
"[",
"$",
"id",
",",
"$",
"this",
"]",
")",
";",
"return",
"[",
"$",
"controller",
",",
"$",
"route",
"]",
";",
"}",
"$",
"module",
"=",
"$",
"this",
"->",
"getModule",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"module",
"!==",
"null",
")",
"{",
"return",
"$",
"module",
"->",
"createController",
"(",
"$",
"route",
")",
";",
"}",
"if",
"(",
"(",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"route",
",",
"'/'",
")",
")",
"!==",
"false",
")",
"{",
"$",
"id",
".=",
"'/'",
".",
"substr",
"(",
"$",
"route",
",",
"0",
",",
"$",
"pos",
")",
";",
"$",
"route",
"=",
"substr",
"(",
"$",
"route",
",",
"$",
"pos",
"+",
"1",
")",
";",
"}",
"$",
"controller",
"=",
"$",
"this",
"->",
"createControllerByID",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"controller",
"===",
"null",
"&&",
"$",
"route",
"!==",
"''",
")",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"createControllerByID",
"(",
"$",
"id",
".",
"'/'",
".",
"$",
"route",
")",
";",
"$",
"route",
"=",
"''",
";",
"}",
"return",
"$",
"controller",
"===",
"null",
"?",
"false",
":",
"[",
"$",
"controller",
",",
"$",
"route",
"]",
";",
"}"
] |
Creates a controller instance based on the given route.
The route should be relative to this module. The method implements the following algorithm
to resolve the given route:
1. If the route is empty, use [[defaultRoute]];
2. If the first segment of the route is a valid module ID as declared in [[modules]],
call the module's `createController()` with the rest part of the route;
3. If the first segment of the route is found in [[controllerMap]], create a controller
based on the corresponding configuration found in [[controllerMap]];
4. The given route is in the format of `abc/def/xyz`. Try either `abc\DefController`
or `abc\def\XyzController` class within the [[controllerNamespace|controller namespace]].
If any of the above steps resolves into a controller, it is returned together with the rest
part of the route which will be treated as the action ID. Otherwise, `false` will be returned.
@param string $route the route consisting of module, controller and action IDs.
@return array|bool If the controller is created successfully, it will be returned together
with the requested action ID. Otherwise `false` will be returned.
@throws InvalidConfigException if the controller class and its file do not match.
|
[
"Creates",
"a",
"controller",
"instance",
"based",
"on",
"the",
"given",
"route",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Module.php#L576-L617
|
train
|
yiisoft/yii-core
|
src/base/Module.php
|
Module.get
|
public function get($id, bool $throwException = true)
{
if (!$this->_container->has($id)) {
if ($throwException) {
throw new InvalidConfigException("Unknown component ID: $id");
}
return null;
}
return $this->_container->get($id);
}
|
php
|
public function get($id, bool $throwException = true)
{
if (!$this->_container->has($id)) {
if ($throwException) {
throw new InvalidConfigException("Unknown component ID: $id");
}
return null;
}
return $this->_container->get($id);
}
|
[
"public",
"function",
"get",
"(",
"$",
"id",
",",
"bool",
"$",
"throwException",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_container",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"if",
"(",
"$",
"throwException",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"\"Unknown component ID: $id\"",
")",
";",
"}",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"_container",
"->",
"get",
"(",
"$",
"id",
")",
";",
"}"
] |
Returns instance from DI by ID.
@param string $id
@param bool $throwException
|
[
"Returns",
"instance",
"from",
"DI",
"by",
"ID",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Module.php#L796-L806
|
train
|
yiisoft/yii-core
|
src/http/MessageTrait.php
|
MessageTrait.getHeaderCollection
|
public function getHeaderCollection()
{
if ($this->_headerCollection === null) {
$headerCollection = new HeaderCollection();
$headerCollection->fromArray($this->defaultHeaders());
$this->_headerCollection = $headerCollection;
}
return $this->_headerCollection;
}
|
php
|
public function getHeaderCollection()
{
if ($this->_headerCollection === null) {
$headerCollection = new HeaderCollection();
$headerCollection->fromArray($this->defaultHeaders());
$this->_headerCollection = $headerCollection;
}
return $this->_headerCollection;
}
|
[
"public",
"function",
"getHeaderCollection",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_headerCollection",
"===",
"null",
")",
"{",
"$",
"headerCollection",
"=",
"new",
"HeaderCollection",
"(",
")",
";",
"$",
"headerCollection",
"->",
"fromArray",
"(",
"$",
"this",
"->",
"defaultHeaders",
"(",
")",
")",
";",
"$",
"this",
"->",
"_headerCollection",
"=",
"$",
"headerCollection",
";",
"}",
"return",
"$",
"this",
"->",
"_headerCollection",
";",
"}"
] |
Returns the header collection.
The header collection contains the currently registered HTTP headers.
@return HeaderCollection the header collection
|
[
"Returns",
"the",
"header",
"collection",
".",
"The",
"header",
"collection",
"contains",
"the",
"currently",
"registered",
"HTTP",
"headers",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/http/MessageTrait.php#L100-L108
|
train
|
yiisoft/yii-core
|
src/http/MessageTrait.php
|
MessageTrait.setHeaders
|
public function setHeaders($headers)
{
$headerCollection = $this->getHeaderCollection();
$headerCollection->removeAll();
$headerCollection->fromArray($headers);
}
|
php
|
public function setHeaders($headers)
{
$headerCollection = $this->getHeaderCollection();
$headerCollection->removeAll();
$headerCollection->fromArray($headers);
}
|
[
"public",
"function",
"setHeaders",
"(",
"$",
"headers",
")",
"{",
"$",
"headerCollection",
"=",
"$",
"this",
"->",
"getHeaderCollection",
"(",
")",
";",
"$",
"headerCollection",
"->",
"removeAll",
"(",
")",
";",
"$",
"headerCollection",
"->",
"fromArray",
"(",
"$",
"headers",
")",
";",
"}"
] |
Sets up message's headers at batch, removing any previously existing ones.
@param string[][] $headers an associative array of the message's headers.
|
[
"Sets",
"up",
"message",
"s",
"headers",
"at",
"batch",
"removing",
"any",
"previously",
"existing",
"ones",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/http/MessageTrait.php#L123-L128
|
train
|
yiisoft/yii-core
|
src/http/MessageTrait.php
|
MessageTrait.withBody
|
public function withBody(StreamInterface $body)
{
if ($this->getBody() === $body) {
return $this;
}
$newInstance = clone $this;
$newInstance->setBody($body);
return $newInstance;
}
|
php
|
public function withBody(StreamInterface $body)
{
if ($this->getBody() === $body) {
return $this;
}
$newInstance = clone $this;
$newInstance->setBody($body);
return $newInstance;
}
|
[
"public",
"function",
"withBody",
"(",
"StreamInterface",
"$",
"body",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getBody",
"(",
")",
"===",
"$",
"body",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"newInstance",
"=",
"clone",
"$",
"this",
";",
"$",
"newInstance",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"return",
"$",
"newInstance",
";",
"}"
] |
Return an instance with the specified message body.
This method retains the immutability of the message and returns an instance that has the
new body stream.
@param StreamInterface $body Body.
@return static
@throws \InvalidArgumentException When the body is not valid.
|
[
"Return",
"an",
"instance",
"with",
"the",
"specified",
"message",
"body",
".",
"This",
"method",
"retains",
"the",
"immutability",
"of",
"the",
"message",
"and",
"returns",
"an",
"instance",
"that",
"has",
"the",
"new",
"body",
"stream",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/http/MessageTrait.php#L329-L338
|
train
|
yiisoft/yii-core
|
src/helpers/BaseUrl.php
|
BaseUrl.canonical
|
public static function canonical()
{
$params = Yii::getApp()->controller->actionParams;
$params[0] = Yii::getApp()->controller->getRoute();
return static::getUrlManager()->createAbsoluteUrl($params);
}
|
php
|
public static function canonical()
{
$params = Yii::getApp()->controller->actionParams;
$params[0] = Yii::getApp()->controller->getRoute();
return static::getUrlManager()->createAbsoluteUrl($params);
}
|
[
"public",
"static",
"function",
"canonical",
"(",
")",
"{",
"$",
"params",
"=",
"Yii",
"::",
"getApp",
"(",
")",
"->",
"controller",
"->",
"actionParams",
";",
"$",
"params",
"[",
"0",
"]",
"=",
"Yii",
"::",
"getApp",
"(",
")",
"->",
"controller",
"->",
"getRoute",
"(",
")",
";",
"return",
"static",
"::",
"getUrlManager",
"(",
")",
"->",
"createAbsoluteUrl",
"(",
"$",
"params",
")",
";",
"}"
] |
Returns the canonical URL of the currently requested page.
The canonical URL is constructed using the current controller's [[\yii\web\Controller::route]] and
[[\yii\web\Controller::actionParams]]. You may use the following code in the layout view to add a link tag
about canonical URL:
```php
$this->registerLinkTag(['rel' => 'canonical', 'href' => Url::canonical()]);
```
@return string the canonical URL of the currently requested page
|
[
"Returns",
"the",
"canonical",
"URL",
"of",
"the",
"currently",
"requested",
"page",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseUrl.php#L341-L347
|
train
|
yiisoft/yii-core
|
src/helpers/BaseHtml.php
|
BaseHtml.beginTag
|
public static function beginTag($name, $options = [])
{
if ($name === null || $name === false) {
return '';
}
return '<' . $name . static::renderTagAttributes($options) . '>';
}
|
php
|
public static function beginTag($name, $options = [])
{
if ($name === null || $name === false) {
return '';
}
return '<' . $name . static::renderTagAttributes($options) . '>';
}
|
[
"public",
"static",
"function",
"beginTag",
"(",
"$",
"name",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"null",
"||",
"$",
"name",
"===",
"false",
")",
"{",
"return",
"''",
";",
"}",
"return",
"'<'",
".",
"$",
"name",
".",
"static",
"::",
"renderTagAttributes",
"(",
"$",
"options",
")",
".",
"'>'",
";",
"}"
] |
Generates a start tag.
@param string|bool|null $name the tag name. If $name is `null` or `false`, the corresponding content will be rendered without any tag.
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
If a value is null, the corresponding attribute will not be rendered.
See [[renderTagAttributes()]] for details on how attributes are being rendered.
@return string the generated start tag
@see endTag()
@see tag()
|
[
"Generates",
"a",
"start",
"tag",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseHtml.php#L165-L172
|
train
|
yiisoft/yii-core
|
src/helpers/BaseHtml.php
|
BaseHtml.getInputId
|
public static function getInputId($model, $attribute)
{
$name = strtolower(static::getInputName($model, $attribute));
return str_replace(['[]', '][', '[', ']', ' ', '.'], ['', '-', '-', '', '-', '-'], $name);
}
|
php
|
public static function getInputId($model, $attribute)
{
$name = strtolower(static::getInputName($model, $attribute));
return str_replace(['[]', '][', '[', ']', ' ', '.'], ['', '-', '-', '', '-', '-'], $name);
}
|
[
"public",
"static",
"function",
"getInputId",
"(",
"$",
"model",
",",
"$",
"attribute",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"static",
"::",
"getInputName",
"(",
"$",
"model",
",",
"$",
"attribute",
")",
")",
";",
"return",
"str_replace",
"(",
"[",
"'[]'",
",",
"']['",
",",
"'['",
",",
"']'",
",",
"' '",
",",
"'.'",
"]",
",",
"[",
"''",
",",
"'-'",
",",
"'-'",
",",
"''",
",",
"'-'",
",",
"'-'",
"]",
",",
"$",
"name",
")",
";",
"}"
] |
Generates an appropriate input ID for the specified attribute name or expression.
This method converts the result [[getInputName()]] into a valid input ID.
For example, if [[getInputName()]] returns `Post[content]`, this method will return `post-content`.
@param Model $model the model object
@param string $attribute the attribute name or expression. See [[getAttributeName()]] for explanation of attribute expression.
@return string the generated input ID
@throws InvalidArgumentException if the attribute name contains non-word characters.
|
[
"Generates",
"an",
"appropriate",
"input",
"ID",
"for",
"the",
"specified",
"attribute",
"name",
"or",
"expression",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseHtml.php#L2292-L2296
|
train
|
yiisoft/yii-core
|
src/base/Aliases.php
|
Aliases.set
|
public function set(string $alias, ?string $path): void
{
if (strncmp($alias, '@', 1)) {
$alias = '@' . $alias;
}
$pos = strpos($alias, '/');
$root = $pos === false ? $alias : substr($alias, 0, $pos);
if ($path !== null) {
$path = strncmp($path, '@', 1) ? rtrim($path, '\\/') : $this->get($path);
if (!isset($this->aliases[$root])) {
if ($pos === false) {
$this->aliases[$root] = $path;
} else {
$this->aliases[$root] = [$alias => $path];
}
} elseif (\is_string($this->aliases[$root])) {
if ($pos === false) {
$this->aliases[$root] = $path;
} else {
$this->aliases[$root] = [
$alias => $path,
$root => $this->aliases[$root],
];
}
} else {
$this->aliases[$root][$alias] = $path;
krsort($this->aliases[$root]);
}
} elseif (isset($this->aliases[$root])) {
if (\is_array($this->aliases[$root])) {
unset($this->aliases[$root][$alias]);
} elseif ($pos === false) {
unset($this->aliases[$root]);
}
}
}
|
php
|
public function set(string $alias, ?string $path): void
{
if (strncmp($alias, '@', 1)) {
$alias = '@' . $alias;
}
$pos = strpos($alias, '/');
$root = $pos === false ? $alias : substr($alias, 0, $pos);
if ($path !== null) {
$path = strncmp($path, '@', 1) ? rtrim($path, '\\/') : $this->get($path);
if (!isset($this->aliases[$root])) {
if ($pos === false) {
$this->aliases[$root] = $path;
} else {
$this->aliases[$root] = [$alias => $path];
}
} elseif (\is_string($this->aliases[$root])) {
if ($pos === false) {
$this->aliases[$root] = $path;
} else {
$this->aliases[$root] = [
$alias => $path,
$root => $this->aliases[$root],
];
}
} else {
$this->aliases[$root][$alias] = $path;
krsort($this->aliases[$root]);
}
} elseif (isset($this->aliases[$root])) {
if (\is_array($this->aliases[$root])) {
unset($this->aliases[$root][$alias]);
} elseif ($pos === false) {
unset($this->aliases[$root]);
}
}
}
|
[
"public",
"function",
"set",
"(",
"string",
"$",
"alias",
",",
"?",
"string",
"$",
"path",
")",
":",
"void",
"{",
"if",
"(",
"strncmp",
"(",
"$",
"alias",
",",
"'@'",
",",
"1",
")",
")",
"{",
"$",
"alias",
"=",
"'@'",
".",
"$",
"alias",
";",
"}",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"alias",
",",
"'/'",
")",
";",
"$",
"root",
"=",
"$",
"pos",
"===",
"false",
"?",
"$",
"alias",
":",
"substr",
"(",
"$",
"alias",
",",
"0",
",",
"$",
"pos",
")",
";",
"if",
"(",
"$",
"path",
"!==",
"null",
")",
"{",
"$",
"path",
"=",
"strncmp",
"(",
"$",
"path",
",",
"'@'",
",",
"1",
")",
"?",
"rtrim",
"(",
"$",
"path",
",",
"'\\\\/'",
")",
":",
"$",
"this",
"->",
"get",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
")",
")",
"{",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
"=",
"$",
"path",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
"=",
"[",
"$",
"alias",
"=>",
"$",
"path",
"]",
";",
"}",
"}",
"elseif",
"(",
"\\",
"is_string",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
")",
")",
"{",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
"=",
"$",
"path",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
"=",
"[",
"$",
"alias",
"=>",
"$",
"path",
",",
"$",
"root",
"=>",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
",",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
"[",
"$",
"alias",
"]",
"=",
"$",
"path",
";",
"krsort",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
")",
";",
"}",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
")",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
"[",
"$",
"alias",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"root",
"]",
")",
";",
"}",
"}",
"}"
] |
Registers a path alias.
A path alias is a short name representing a long path (a file path, a URL, etc.)
For example, we use '@yii' as the alias of the path to the Yii framework directory.
A path alias must start with the character '@' so that it can be easily differentiated
from non-alias paths.
Note that this method does not check if the given path exists or not. All it does is
to associate the alias with the path.
Any trailing '/' and '\' characters in the given path will be trimmed.
See the [guide article on aliases](guide:concept-aliases) for more information.
@param string $alias the alias name (e.g. "@yii"). It must start with a '@' character.
It may contain the forward slash '/' which serves as boundary character when performing
alias translation by [[get()]].
@param string $path the path corresponding to the alias. If this is null, the alias will
be removed. Trailing '/' and '\' characters will be trimmed. This can be
- a directory or a file path (e.g. `/tmp`, `/tmp/main.txt`)
- a URL (e.g. `http://www.yiiframework.com`)
- a path alias (e.g. `@yii/base`). In this case, the path alias will be converted into the
actual path first by calling [[get()]].
@throws InvalidArgumentException if $path is an invalid alias.
@see get()
|
[
"Registers",
"a",
"path",
"alias",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Aliases.php#L61-L96
|
train
|
yiisoft/yii-core
|
src/validators/FileValidator.php
|
FileValidator.getSizeLimit
|
public function getSizeLimit()
{
// Get the lowest between post_max_size and upload_max_filesize, log a warning if the first is < than the latter
$limit = $this->sizeToBytes(ini_get('upload_max_filesize'));
$postLimit = $this->sizeToBytes(ini_get('post_max_size'));
if ($postLimit > 0 && $postLimit < $limit) {
Yii::warning('PHP.ini\'s \'post_max_size\' is less than \'upload_max_filesize\'.', __METHOD__);
$limit = $postLimit;
}
if ($this->maxSize !== null && $limit > 0 && $this->maxSize < $limit) {
$limit = $this->maxSize;
}
if (($request = Yii::getApp()->getRequest()) instanceof \yii\web\Request) {
$maxFileSize = Yii::getApp()->getRequest()->getParsedBodyParam('MAX_FILE_SIZE', 0);
if ($maxFileSize > 0 && $maxFileSize < $limit) {
$limit = (int)$maxFileSize;
}
}
return $limit;
}
|
php
|
public function getSizeLimit()
{
// Get the lowest between post_max_size and upload_max_filesize, log a warning if the first is < than the latter
$limit = $this->sizeToBytes(ini_get('upload_max_filesize'));
$postLimit = $this->sizeToBytes(ini_get('post_max_size'));
if ($postLimit > 0 && $postLimit < $limit) {
Yii::warning('PHP.ini\'s \'post_max_size\' is less than \'upload_max_filesize\'.', __METHOD__);
$limit = $postLimit;
}
if ($this->maxSize !== null && $limit > 0 && $this->maxSize < $limit) {
$limit = $this->maxSize;
}
if (($request = Yii::getApp()->getRequest()) instanceof \yii\web\Request) {
$maxFileSize = Yii::getApp()->getRequest()->getParsedBodyParam('MAX_FILE_SIZE', 0);
if ($maxFileSize > 0 && $maxFileSize < $limit) {
$limit = (int)$maxFileSize;
}
}
return $limit;
}
|
[
"public",
"function",
"getSizeLimit",
"(",
")",
"{",
"// Get the lowest between post_max_size and upload_max_filesize, log a warning if the first is < than the latter",
"$",
"limit",
"=",
"$",
"this",
"->",
"sizeToBytes",
"(",
"ini_get",
"(",
"'upload_max_filesize'",
")",
")",
";",
"$",
"postLimit",
"=",
"$",
"this",
"->",
"sizeToBytes",
"(",
"ini_get",
"(",
"'post_max_size'",
")",
")",
";",
"if",
"(",
"$",
"postLimit",
">",
"0",
"&&",
"$",
"postLimit",
"<",
"$",
"limit",
")",
"{",
"Yii",
"::",
"warning",
"(",
"'PHP.ini\\'s \\'post_max_size\\' is less than \\'upload_max_filesize\\'.'",
",",
"__METHOD__",
")",
";",
"$",
"limit",
"=",
"$",
"postLimit",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"maxSize",
"!==",
"null",
"&&",
"$",
"limit",
">",
"0",
"&&",
"$",
"this",
"->",
"maxSize",
"<",
"$",
"limit",
")",
"{",
"$",
"limit",
"=",
"$",
"this",
"->",
"maxSize",
";",
"}",
"if",
"(",
"(",
"$",
"request",
"=",
"Yii",
"::",
"getApp",
"(",
")",
"->",
"getRequest",
"(",
")",
")",
"instanceof",
"\\",
"yii",
"\\",
"web",
"\\",
"Request",
")",
"{",
"$",
"maxFileSize",
"=",
"Yii",
"::",
"getApp",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getParsedBodyParam",
"(",
"'MAX_FILE_SIZE'",
",",
"0",
")",
";",
"if",
"(",
"$",
"maxFileSize",
">",
"0",
"&&",
"$",
"maxFileSize",
"<",
"$",
"limit",
")",
"{",
"$",
"limit",
"=",
"(",
"int",
")",
"$",
"maxFileSize",
";",
"}",
"}",
"return",
"$",
"limit",
";",
"}"
] |
Returns the maximum size allowed for uploaded files.
This is determined based on four factors:
- 'upload_max_filesize' in php.ini
- 'post_max_size' in php.ini
- 'MAX_FILE_SIZE' hidden field
- [[maxSize]]
@return int the size limit for uploaded files.
|
[
"Returns",
"the",
"maximum",
"size",
"allowed",
"for",
"uploaded",
"files",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/validators/FileValidator.php#L338-L359
|
train
|
yiisoft/yii-core
|
src/helpers/BaseFileHelper.php
|
BaseFileHelper.unlink
|
public static function unlink($path): bool
{
$isWindows = DIRECTORY_SEPARATOR === '\\';
if (!$isWindows) {
return unlink($path);
}
if (is_link($path) && is_dir($path)) {
return rmdir($path);
}
return unlink($path);
}
|
php
|
public static function unlink($path): bool
{
$isWindows = DIRECTORY_SEPARATOR === '\\';
if (!$isWindows) {
return unlink($path);
}
if (is_link($path) && is_dir($path)) {
return rmdir($path);
}
return unlink($path);
}
|
[
"public",
"static",
"function",
"unlink",
"(",
"$",
"path",
")",
":",
"bool",
"{",
"$",
"isWindows",
"=",
"DIRECTORY_SEPARATOR",
"===",
"'\\\\'",
";",
"if",
"(",
"!",
"$",
"isWindows",
")",
"{",
"return",
"unlink",
"(",
"$",
"path",
")",
";",
"}",
"if",
"(",
"is_link",
"(",
"$",
"path",
")",
"&&",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"return",
"rmdir",
"(",
"$",
"path",
")",
";",
"}",
"return",
"unlink",
"(",
"$",
"path",
")",
";",
"}"
] |
Removes a file or symlink in a cross-platform way
@param string $path
@return bool
@since 2.0.14
|
[
"Removes",
"a",
"file",
"or",
"symlink",
"in",
"a",
"cross",
"-",
"platform",
"way"
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseFileHelper.php#L377-L390
|
train
|
yiisoft/yii-core
|
src/helpers/BaseFileHelper.php
|
BaseFileHelper.firstWildcardInPattern
|
private static function firstWildcardInPattern($pattern)
{
$wildcards = ['*', '?', '[', '\\'];
$wildcardSearch = function ($carry, $item) use ($pattern) {
$position = strpos($pattern, $item);
if ($position === false) {
return $carry === false ? $position : $carry;
}
return $carry === false ? $position : min($carry, $position);
};
return array_reduce($wildcards, $wildcardSearch, false);
}
|
php
|
private static function firstWildcardInPattern($pattern)
{
$wildcards = ['*', '?', '[', '\\'];
$wildcardSearch = function ($carry, $item) use ($pattern) {
$position = strpos($pattern, $item);
if ($position === false) {
return $carry === false ? $position : $carry;
}
return $carry === false ? $position : min($carry, $position);
};
return array_reduce($wildcards, $wildcardSearch, false);
}
|
[
"private",
"static",
"function",
"firstWildcardInPattern",
"(",
"$",
"pattern",
")",
"{",
"$",
"wildcards",
"=",
"[",
"'*'",
",",
"'?'",
",",
"'['",
",",
"'\\\\'",
"]",
";",
"$",
"wildcardSearch",
"=",
"function",
"(",
"$",
"carry",
",",
"$",
"item",
")",
"use",
"(",
"$",
"pattern",
")",
"{",
"$",
"position",
"=",
"strpos",
"(",
"$",
"pattern",
",",
"$",
"item",
")",
";",
"if",
"(",
"$",
"position",
"===",
"false",
")",
"{",
"return",
"$",
"carry",
"===",
"false",
"?",
"$",
"position",
":",
"$",
"carry",
";",
"}",
"return",
"$",
"carry",
"===",
"false",
"?",
"$",
"position",
":",
"min",
"(",
"$",
"carry",
",",
"$",
"position",
")",
";",
"}",
";",
"return",
"array_reduce",
"(",
"$",
"wildcards",
",",
"$",
"wildcardSearch",
",",
"false",
")",
";",
"}"
] |
Searches for the first wildcard character in the pattern.
@param string $pattern the pattern to search in
@return int|bool position of first wildcard character or false if not found
|
[
"Searches",
"for",
"the",
"first",
"wildcard",
"character",
"in",
"the",
"pattern",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseFileHelper.php#L787-L801
|
train
|
yiisoft/yii-core
|
src/base/Application.php
|
Application.debug
|
public function debug($message, string $category = 'application'): void
{
$this->log(LogLevel::DEBUG, $message, $category);
}
|
php
|
public function debug($message, string $category = 'application'): void
{
$this->log(LogLevel::DEBUG, $message, $category);
}
|
[
"public",
"function",
"debug",
"(",
"$",
"message",
",",
"string",
"$",
"category",
"=",
"'application'",
")",
":",
"void",
"{",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"$",
"message",
",",
"$",
"category",
")",
";",
"}"
] |
Logs a debug message.
Trace messages are logged mainly for development purpose to see
the execution work flow of some code.
@param mixed $message the message to be logged.
@param string $category the category of the message.
|
[
"Logs",
"a",
"debug",
"message",
".",
"Trace",
"messages",
"are",
"logged",
"mainly",
"for",
"development",
"purpose",
"to",
"see",
"the",
"execution",
"work",
"flow",
"of",
"some",
"code",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Application.php#L330-L333
|
train
|
yiisoft/yii-core
|
src/base/Application.php
|
Application.log
|
public function log(string $level, $message, $category = 'application'): void
{
$this->getLogger()->log($level, $message, ['category' => $category]);
}
|
php
|
public function log(string $level, $message, $category = 'application'): void
{
$this->getLogger()->log($level, $message, ['category' => $category]);
}
|
[
"public",
"function",
"log",
"(",
"string",
"$",
"level",
",",
"$",
"message",
",",
"$",
"category",
"=",
"'application'",
")",
":",
"void",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"[",
"'category'",
"=>",
"$",
"category",
"]",
")",
";",
"}"
] |
Logs given message through `logger` service.
@param string $level log level.
@param mixed $message the message to be logged. This can be a simple string or a more
complex data structure, such as array.
@param string $category the category of the message.
@since 3.0.0
|
[
"Logs",
"given",
"message",
"through",
"logger",
"service",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Application.php#L380-L383
|
train
|
yiisoft/yii-core
|
src/base/Application.php
|
Application.setBasePath
|
public function setBasePath($path)
{
parent::setBasePath($path);
$this->setAlias('@app', $this->getBasePath());
if (empty($this->getAlias('@root', false))) {
$this->setAlias('@root', dirname(__DIR__, 5));
}
}
|
php
|
public function setBasePath($path)
{
parent::setBasePath($path);
$this->setAlias('@app', $this->getBasePath());
if (empty($this->getAlias('@root', false))) {
$this->setAlias('@root', dirname(__DIR__, 5));
}
}
|
[
"public",
"function",
"setBasePath",
"(",
"$",
"path",
")",
"{",
"parent",
"::",
"setBasePath",
"(",
"$",
"path",
")",
";",
"$",
"this",
"->",
"setAlias",
"(",
"'@app'",
",",
"$",
"this",
"->",
"getBasePath",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"getAlias",
"(",
"'@root'",
",",
"false",
")",
")",
")",
"{",
"$",
"this",
"->",
"setAlias",
"(",
"'@root'",
",",
"dirname",
"(",
"__DIR__",
",",
"5",
")",
")",
";",
"}",
"}"
] |
Sets the root directory of the application and the @app alias.
This method can only be invoked at the beginning of the constructor.
@param string $path the root directory of the application.
@property string the root directory of the application.
@throws InvalidArgumentException if the directory does not exist.
|
[
"Sets",
"the",
"root",
"directory",
"of",
"the",
"application",
"and",
"the"
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Application.php#L519-L526
|
train
|
yiisoft/yii-core
|
src/base/Application.php
|
Application.run
|
public function run()
{
if (YII_ENABLE_ERROR_HANDLER) {
$this->get('errorHandler')->register();
}
try {
$this->state = self::STATE_BEFORE_REQUEST;
$this->trigger(RequestEvent::BEFORE);
$this->state = self::STATE_HANDLING_REQUEST;
$this->response = $this->handleRequest($this->getRequest());
$this->state = self::STATE_AFTER_REQUEST;
$this->trigger(RequestEvent::AFTER);
$this->state = self::STATE_SENDING_RESPONSE;
$this->response->send();
$this->state = self::STATE_END;
return $this->response->exitStatus;
} catch (ExitException $e) {
$this->end($e->statusCode, $this->response ?? null);
return $e->statusCode;
}
}
|
php
|
public function run()
{
if (YII_ENABLE_ERROR_HANDLER) {
$this->get('errorHandler')->register();
}
try {
$this->state = self::STATE_BEFORE_REQUEST;
$this->trigger(RequestEvent::BEFORE);
$this->state = self::STATE_HANDLING_REQUEST;
$this->response = $this->handleRequest($this->getRequest());
$this->state = self::STATE_AFTER_REQUEST;
$this->trigger(RequestEvent::AFTER);
$this->state = self::STATE_SENDING_RESPONSE;
$this->response->send();
$this->state = self::STATE_END;
return $this->response->exitStatus;
} catch (ExitException $e) {
$this->end($e->statusCode, $this->response ?? null);
return $e->statusCode;
}
}
|
[
"public",
"function",
"run",
"(",
")",
"{",
"if",
"(",
"YII_ENABLE_ERROR_HANDLER",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"'errorHandler'",
")",
"->",
"register",
"(",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_BEFORE_REQUEST",
";",
"$",
"this",
"->",
"trigger",
"(",
"RequestEvent",
"::",
"BEFORE",
")",
";",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_HANDLING_REQUEST",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"this",
"->",
"handleRequest",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
")",
";",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_AFTER_REQUEST",
";",
"$",
"this",
"->",
"trigger",
"(",
"RequestEvent",
"::",
"AFTER",
")",
";",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_SENDING_RESPONSE",
";",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
")",
";",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_END",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"exitStatus",
";",
"}",
"catch",
"(",
"ExitException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"end",
"(",
"$",
"e",
"->",
"statusCode",
",",
"$",
"this",
"->",
"response",
"??",
"null",
")",
";",
"return",
"$",
"e",
"->",
"statusCode",
";",
"}",
"}"
] |
Runs the application.
This is the main entrance of an application.
@return int the exit status (0 means normal, non-zero values mean abnormal)
|
[
"Runs",
"the",
"application",
".",
"This",
"is",
"the",
"main",
"entrance",
"of",
"an",
"application",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Application.php#L533-L559
|
train
|
yiisoft/yii-core
|
src/i18n/Formatter.php
|
Formatter.asNtext
|
public function asNtext($value)
{
if ($value === null) {
return $this->getNullDisplay();
}
return nl2br(Html::encode($value));
}
|
php
|
public function asNtext($value)
{
if ($value === null) {
return $this->getNullDisplay();
}
return nl2br(Html::encode($value));
}
|
[
"public",
"function",
"asNtext",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getNullDisplay",
"(",
")",
";",
"}",
"return",
"nl2br",
"(",
"Html",
"::",
"encode",
"(",
"$",
"value",
")",
")",
";",
"}"
] |
Formats the value as an HTML-encoded plain text with newlines converted into breaks.
@param string $value the value to be formatted.
@return string the formatted result.
|
[
"Formats",
"the",
"value",
"as",
"an",
"HTML",
"-",
"encoded",
"plain",
"text",
"with",
"newlines",
"converted",
"into",
"breaks",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/Formatter.php#L556-L563
|
train
|
yiisoft/yii-core
|
src/i18n/Formatter.php
|
Formatter.asImage
|
public function asImage($value, $options = [])
{
if ($value === null) {
return $this->getNullDisplay();
}
return Html::img($value, $options);
}
|
php
|
public function asImage($value, $options = [])
{
if ($value === null) {
return $this->getNullDisplay();
}
return Html::img($value, $options);
}
|
[
"public",
"function",
"asImage",
"(",
"$",
"value",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getNullDisplay",
"(",
")",
";",
"}",
"return",
"Html",
"::",
"img",
"(",
"$",
"value",
",",
"$",
"options",
")",
";",
"}"
] |
Formats the value as an image tag.
@param mixed $value the value to be formatted.
@param array $options the tag options in terms of name-value pairs. See [[Html::img()]].
@return string the formatted result.
|
[
"Formats",
"the",
"value",
"as",
"an",
"image",
"tag",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/Formatter.php#L619-L626
|
train
|
yiisoft/yii-core
|
src/i18n/Formatter.php
|
Formatter.asBoolean
|
public function asBoolean($value)
{
if ($value === null) {
return $this->getNullDisplay();
}
return $value ? $this->getBooleanFormat()[1] : $this->getBooleanFormat()[0];
}
|
php
|
public function asBoolean($value)
{
if ($value === null) {
return $this->getNullDisplay();
}
return $value ? $this->getBooleanFormat()[1] : $this->getBooleanFormat()[0];
}
|
[
"public",
"function",
"asBoolean",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getNullDisplay",
"(",
")",
";",
"}",
"return",
"$",
"value",
"?",
"$",
"this",
"->",
"getBooleanFormat",
"(",
")",
"[",
"1",
"]",
":",
"$",
"this",
"->",
"getBooleanFormat",
"(",
")",
"[",
"0",
"]",
";",
"}"
] |
Formats the value as a boolean.
@param mixed $value the value to be formatted.
@return string the formatted result.
@see booleanFormat
|
[
"Formats",
"the",
"value",
"as",
"a",
"boolean",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/Formatter.php#L653-L660
|
train
|
yiisoft/yii-core
|
src/i18n/Formatter.php
|
Formatter.asScientific
|
public function asScientific($value, $decimals = null, $options = [], $textOptions = [])
{
if ($value === null) {
return $this->getNullDisplay();
}
$value = $this->normalizeNumericValue($value);
if ($this->_intlLoaded) {
$f = $this->createNumberFormatter(NumberFormatter::SCIENTIFIC, $decimals, $options, $textOptions);
if (($result = $f->format($value)) === false) {
throw new InvalidArgumentException('Formatting scientific number value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
}
return $result;
}
if ($decimals !== null) {
return sprintf("%.{$decimals}E", $value);
}
return sprintf('%.E', $value);
}
|
php
|
public function asScientific($value, $decimals = null, $options = [], $textOptions = [])
{
if ($value === null) {
return $this->getNullDisplay();
}
$value = $this->normalizeNumericValue($value);
if ($this->_intlLoaded) {
$f = $this->createNumberFormatter(NumberFormatter::SCIENTIFIC, $decimals, $options, $textOptions);
if (($result = $f->format($value)) === false) {
throw new InvalidArgumentException('Formatting scientific number value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
}
return $result;
}
if ($decimals !== null) {
return sprintf("%.{$decimals}E", $value);
}
return sprintf('%.E', $value);
}
|
[
"public",
"function",
"asScientific",
"(",
"$",
"value",
",",
"$",
"decimals",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"textOptions",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getNullDisplay",
"(",
")",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"normalizeNumericValue",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_intlLoaded",
")",
"{",
"$",
"f",
"=",
"$",
"this",
"->",
"createNumberFormatter",
"(",
"NumberFormatter",
"::",
"SCIENTIFIC",
",",
"$",
"decimals",
",",
"$",
"options",
",",
"$",
"textOptions",
")",
";",
"if",
"(",
"(",
"$",
"result",
"=",
"$",
"f",
"->",
"format",
"(",
"$",
"value",
")",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Formatting scientific number value failed: '",
".",
"$",
"f",
"->",
"getErrorCode",
"(",
")",
".",
"' '",
".",
"$",
"f",
"->",
"getErrorMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"if",
"(",
"$",
"decimals",
"!==",
"null",
")",
"{",
"return",
"sprintf",
"(",
"\"%.{$decimals}E\"",
",",
"$",
"value",
")",
";",
"}",
"return",
"sprintf",
"(",
"'%.E'",
",",
"$",
"value",
")",
";",
"}"
] |
Formats the value as a scientific number.
@param mixed $value the value to be formatted.
@param int $decimals the number of digits after the decimal point.
If not given, the number of digits depends in the input value and is determined based on
`NumberFormatter::MIN_FRACTION_DIGITS` and `NumberFormatter::MAX_FRACTION_DIGITS`, which can be configured
using [[$numberFormatterOptions]].
If the [PHP intl extension](http://php.net/manual/en/book.intl.php) is not available, the default value depends on your PHP configuration.
If you want consistent behavior between environments where intl is available and not, you should explicitly
specify a value here.
@param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
@param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
@return string the formatted result.
@throws InvalidArgumentException if the input value is not numeric or the formatting failed.
|
[
"Formats",
"the",
"value",
"as",
"a",
"scientific",
"number",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/Formatter.php#L1276-L1297
|
train
|
yiisoft/yii-core
|
src/i18n/Formatter.php
|
Formatter.asCurrency
|
public function asCurrency($value, $currency = null, $options = [], $textOptions = [])
{
if ($value === null) {
return $this->getNullDisplay();
}
$normalizedValue = $this->normalizeNumericValue($value);
if ($this->isNormalizedValueMispresented($value, $normalizedValue)) {
return $this->asCurrencyStringFallback((string) $value, $currency);
}
if ($this->_intlLoaded) {
$currency = $currency ?: $this->currencyCode;
// currency code must be set before fraction digits
// http://php.net/manual/en/numberformatter.formatcurrency.php#114376
if ($currency && !isset($textOptions[NumberFormatter::CURRENCY_CODE])) {
$textOptions[NumberFormatter::CURRENCY_CODE] = $currency;
}
$formatter = $this->createNumberFormatter(NumberFormatter::CURRENCY, null, $options, $textOptions);
if ($currency === null) {
$result = $formatter->format($normalizedValue);
} else {
$result = $formatter->formatCurrency($normalizedValue, $currency);
}
if ($result === false) {
throw new InvalidArgumentException('Formatting currency value failed: ' . $formatter->getErrorCode() . ' ' . $formatter->getErrorMessage());
}
return $result;
}
if ($currency === null) {
if ($this->currencyCode === null) {
throw new InvalidConfigException('The default currency code for the formatter is not defined and the php intl extension is not installed which could take the default currency from the locale.');
}
$currency = $this->currencyCode;
}
return $currency . ' ' . $this->asDecimal($normalizedValue, 2, $options, $textOptions);
}
|
php
|
public function asCurrency($value, $currency = null, $options = [], $textOptions = [])
{
if ($value === null) {
return $this->getNullDisplay();
}
$normalizedValue = $this->normalizeNumericValue($value);
if ($this->isNormalizedValueMispresented($value, $normalizedValue)) {
return $this->asCurrencyStringFallback((string) $value, $currency);
}
if ($this->_intlLoaded) {
$currency = $currency ?: $this->currencyCode;
// currency code must be set before fraction digits
// http://php.net/manual/en/numberformatter.formatcurrency.php#114376
if ($currency && !isset($textOptions[NumberFormatter::CURRENCY_CODE])) {
$textOptions[NumberFormatter::CURRENCY_CODE] = $currency;
}
$formatter = $this->createNumberFormatter(NumberFormatter::CURRENCY, null, $options, $textOptions);
if ($currency === null) {
$result = $formatter->format($normalizedValue);
} else {
$result = $formatter->formatCurrency($normalizedValue, $currency);
}
if ($result === false) {
throw new InvalidArgumentException('Formatting currency value failed: ' . $formatter->getErrorCode() . ' ' . $formatter->getErrorMessage());
}
return $result;
}
if ($currency === null) {
if ($this->currencyCode === null) {
throw new InvalidConfigException('The default currency code for the formatter is not defined and the php intl extension is not installed which could take the default currency from the locale.');
}
$currency = $this->currencyCode;
}
return $currency . ' ' . $this->asDecimal($normalizedValue, 2, $options, $textOptions);
}
|
[
"public",
"function",
"asCurrency",
"(",
"$",
"value",
",",
"$",
"currency",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"textOptions",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getNullDisplay",
"(",
")",
";",
"}",
"$",
"normalizedValue",
"=",
"$",
"this",
"->",
"normalizeNumericValue",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isNormalizedValueMispresented",
"(",
"$",
"value",
",",
"$",
"normalizedValue",
")",
")",
"{",
"return",
"$",
"this",
"->",
"asCurrencyStringFallback",
"(",
"(",
"string",
")",
"$",
"value",
",",
"$",
"currency",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_intlLoaded",
")",
"{",
"$",
"currency",
"=",
"$",
"currency",
"?",
":",
"$",
"this",
"->",
"currencyCode",
";",
"// currency code must be set before fraction digits",
"// http://php.net/manual/en/numberformatter.formatcurrency.php#114376",
"if",
"(",
"$",
"currency",
"&&",
"!",
"isset",
"(",
"$",
"textOptions",
"[",
"NumberFormatter",
"::",
"CURRENCY_CODE",
"]",
")",
")",
"{",
"$",
"textOptions",
"[",
"NumberFormatter",
"::",
"CURRENCY_CODE",
"]",
"=",
"$",
"currency",
";",
"}",
"$",
"formatter",
"=",
"$",
"this",
"->",
"createNumberFormatter",
"(",
"NumberFormatter",
"::",
"CURRENCY",
",",
"null",
",",
"$",
"options",
",",
"$",
"textOptions",
")",
";",
"if",
"(",
"$",
"currency",
"===",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"formatter",
"->",
"format",
"(",
"$",
"normalizedValue",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"formatter",
"->",
"formatCurrency",
"(",
"$",
"normalizedValue",
",",
"$",
"currency",
")",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Formatting currency value failed: '",
".",
"$",
"formatter",
"->",
"getErrorCode",
"(",
")",
".",
"' '",
".",
"$",
"formatter",
"->",
"getErrorMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"if",
"(",
"$",
"currency",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"currencyCode",
"===",
"null",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"'The default currency code for the formatter is not defined and the php intl extension is not installed which could take the default currency from the locale.'",
")",
";",
"}",
"$",
"currency",
"=",
"$",
"this",
"->",
"currencyCode",
";",
"}",
"return",
"$",
"currency",
".",
"' '",
".",
"$",
"this",
"->",
"asDecimal",
"(",
"$",
"normalizedValue",
",",
"2",
",",
"$",
"options",
",",
"$",
"textOptions",
")",
";",
"}"
] |
Formats the value as a currency number.
This function does not require the [PHP intl extension](http://php.net/manual/en/book.intl.php) to be installed
to work, but it is highly recommended to install it to get good formatting results.
Since 2.0.16 numbers that are mispresented after normalization are formatted as strings using fallback function
without PHP intl extension support. For very big numbers it's recommended to pass them as strings and not use
scientific notation otherwise the output might be wrong.
@param mixed $value the value to be formatted.
@param string $currency the 3-letter ISO 4217 currency code indicating the currency to use.
If null, [[currencyCode]] will be used.
@param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
@param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
@return string the formatted result.
@throws InvalidArgumentException if the input value is not numeric or the formatting failed.
@throws InvalidConfigException if no currency is given and [[currencyCode]] is not defined.
|
[
"Formats",
"the",
"value",
"as",
"a",
"currency",
"number",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/Formatter.php#L1318-L1358
|
train
|
yiisoft/yii-core
|
src/i18n/Formatter.php
|
Formatter.asSpellout
|
public function asSpellout($value)
{
if ($value === null) {
return $this->getNullDisplay();
}
$value = $this->normalizeNumericValue($value);
if ($this->_intlLoaded) {
$f = $this->createNumberFormatter(NumberFormatter::SPELLOUT);
if (($result = $f->format($value)) === false) {
throw new InvalidArgumentException('Formatting number as spellout failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
}
return $result;
}
throw new InvalidConfigException('Format as Spellout is only supported when PHP intl extension is installed.');
}
|
php
|
public function asSpellout($value)
{
if ($value === null) {
return $this->getNullDisplay();
}
$value = $this->normalizeNumericValue($value);
if ($this->_intlLoaded) {
$f = $this->createNumberFormatter(NumberFormatter::SPELLOUT);
if (($result = $f->format($value)) === false) {
throw new InvalidArgumentException('Formatting number as spellout failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
}
return $result;
}
throw new InvalidConfigException('Format as Spellout is only supported when PHP intl extension is installed.');
}
|
[
"public",
"function",
"asSpellout",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getNullDisplay",
"(",
")",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"normalizeNumericValue",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_intlLoaded",
")",
"{",
"$",
"f",
"=",
"$",
"this",
"->",
"createNumberFormatter",
"(",
"NumberFormatter",
"::",
"SPELLOUT",
")",
";",
"if",
"(",
"(",
"$",
"result",
"=",
"$",
"f",
"->",
"format",
"(",
"$",
"value",
")",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Formatting number as spellout failed: '",
".",
"$",
"f",
"->",
"getErrorCode",
"(",
")",
".",
"' '",
".",
"$",
"f",
"->",
"getErrorMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"throw",
"new",
"InvalidConfigException",
"(",
"'Format as Spellout is only supported when PHP intl extension is installed.'",
")",
";",
"}"
] |
Formats the value as a number spellout.
This function requires the [PHP intl extension](http://php.net/manual/en/book.intl.php) to be installed.
This formatter does not work well with very big numbers.
@param mixed $value the value to be formatted
@return string the formatted result.
@throws InvalidArgumentException if the input value is not numeric or the formatting failed.
@throws InvalidConfigException when the [PHP intl extension](http://php.net/manual/en/book.intl.php) is not available.
|
[
"Formats",
"the",
"value",
"as",
"a",
"number",
"spellout",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/Formatter.php#L1371-L1387
|
train
|
yiisoft/yii-core
|
src/i18n/Formatter.php
|
Formatter.createNumberFormatter
|
protected function createNumberFormatter($style, $decimals = null, $options = [], $textOptions = [])
{
$formatter = new NumberFormatter($this->getLocale(), $style);
// set text attributes
foreach ($this->numberFormatterTextOptions as $name => $attribute) {
$formatter->setTextAttribute($name, $attribute);
}
foreach ($textOptions as $name => $attribute) {
$formatter->setTextAttribute($name, $attribute);
}
// set attributes
foreach ($this->numberFormatterOptions as $name => $value) {
$formatter->setAttribute($name, $value);
}
foreach ($options as $name => $value) {
$formatter->setAttribute($name, $value);
}
if ($decimals !== null) {
$formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
$formatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimals);
}
// set symbols
if ($this->decimalSeparator !== null) {
$formatter->setSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, $this->decimalSeparator);
}
if ($this->thousandSeparator !== null) {
$formatter->setSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, $this->thousandSeparator);
$formatter->setSymbol(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, $this->thousandSeparator);
}
foreach ($this->numberFormatterSymbols as $name => $symbol) {
$formatter->setSymbol($name, $symbol);
}
return $formatter;
}
|
php
|
protected function createNumberFormatter($style, $decimals = null, $options = [], $textOptions = [])
{
$formatter = new NumberFormatter($this->getLocale(), $style);
// set text attributes
foreach ($this->numberFormatterTextOptions as $name => $attribute) {
$formatter->setTextAttribute($name, $attribute);
}
foreach ($textOptions as $name => $attribute) {
$formatter->setTextAttribute($name, $attribute);
}
// set attributes
foreach ($this->numberFormatterOptions as $name => $value) {
$formatter->setAttribute($name, $value);
}
foreach ($options as $name => $value) {
$formatter->setAttribute($name, $value);
}
if ($decimals !== null) {
$formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
$formatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimals);
}
// set symbols
if ($this->decimalSeparator !== null) {
$formatter->setSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, $this->decimalSeparator);
}
if ($this->thousandSeparator !== null) {
$formatter->setSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, $this->thousandSeparator);
$formatter->setSymbol(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, $this->thousandSeparator);
}
foreach ($this->numberFormatterSymbols as $name => $symbol) {
$formatter->setSymbol($name, $symbol);
}
return $formatter;
}
|
[
"protected",
"function",
"createNumberFormatter",
"(",
"$",
"style",
",",
"$",
"decimals",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"textOptions",
"=",
"[",
"]",
")",
"{",
"$",
"formatter",
"=",
"new",
"NumberFormatter",
"(",
"$",
"this",
"->",
"getLocale",
"(",
")",
",",
"$",
"style",
")",
";",
"// set text attributes",
"foreach",
"(",
"$",
"this",
"->",
"numberFormatterTextOptions",
"as",
"$",
"name",
"=>",
"$",
"attribute",
")",
"{",
"$",
"formatter",
"->",
"setTextAttribute",
"(",
"$",
"name",
",",
"$",
"attribute",
")",
";",
"}",
"foreach",
"(",
"$",
"textOptions",
"as",
"$",
"name",
"=>",
"$",
"attribute",
")",
"{",
"$",
"formatter",
"->",
"setTextAttribute",
"(",
"$",
"name",
",",
"$",
"attribute",
")",
";",
"}",
"// set attributes",
"foreach",
"(",
"$",
"this",
"->",
"numberFormatterOptions",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"formatter",
"->",
"setAttribute",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"foreach",
"(",
"$",
"options",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"formatter",
"->",
"setAttribute",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"decimals",
"!==",
"null",
")",
"{",
"$",
"formatter",
"->",
"setAttribute",
"(",
"NumberFormatter",
"::",
"MAX_FRACTION_DIGITS",
",",
"$",
"decimals",
")",
";",
"$",
"formatter",
"->",
"setAttribute",
"(",
"NumberFormatter",
"::",
"MIN_FRACTION_DIGITS",
",",
"$",
"decimals",
")",
";",
"}",
"// set symbols",
"if",
"(",
"$",
"this",
"->",
"decimalSeparator",
"!==",
"null",
")",
"{",
"$",
"formatter",
"->",
"setSymbol",
"(",
"NumberFormatter",
"::",
"DECIMAL_SEPARATOR_SYMBOL",
",",
"$",
"this",
"->",
"decimalSeparator",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"thousandSeparator",
"!==",
"null",
")",
"{",
"$",
"formatter",
"->",
"setSymbol",
"(",
"NumberFormatter",
"::",
"GROUPING_SEPARATOR_SYMBOL",
",",
"$",
"this",
"->",
"thousandSeparator",
")",
";",
"$",
"formatter",
"->",
"setSymbol",
"(",
"NumberFormatter",
"::",
"MONETARY_GROUPING_SEPARATOR_SYMBOL",
",",
"$",
"this",
"->",
"thousandSeparator",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"numberFormatterSymbols",
"as",
"$",
"name",
"=>",
"$",
"symbol",
")",
"{",
"$",
"formatter",
"->",
"setSymbol",
"(",
"$",
"name",
",",
"$",
"symbol",
")",
";",
"}",
"return",
"$",
"formatter",
";",
"}"
] |
Creates a number formatter based on the given type and format.
You may override this method to create a number formatter based on patterns.
@param int $style the type of the number formatter.
Values: NumberFormatter::DECIMAL, ::CURRENCY, ::PERCENT, ::SCIENTIFIC, ::SPELLOUT, ::ORDINAL
::DURATION, ::PATTERN_RULEBASED, ::DEFAULT_STYLE, ::IGNORE
@param int $decimals the number of digits after the decimal point.
@param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
@param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
@return NumberFormatter the created formatter instance
|
[
"Creates",
"a",
"number",
"formatter",
"based",
"on",
"the",
"given",
"type",
"and",
"format",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/Formatter.php#L1813-L1850
|
train
|
yiisoft/yii-core
|
src/i18n/Formatter.php
|
Formatter.normalizeNumericStringValue
|
protected function normalizeNumericStringValue($value)
{
$separatorPosition = strrpos($value, '.');
if ($separatorPosition !== false) {
$integerPart = substr($value, 0, $separatorPosition);
$fractionalPart = substr($value, $separatorPosition + 1);
} else {
$integerPart = $value;
$fractionalPart = null;
}
// truncate insignificant zeros, keep minus
$integerPart = preg_replace('/^\+?(-?)0*(\d+)$/', '$1$2', $integerPart);
// for zeros only leave one zero, keep minus
$integerPart = preg_replace('/^\+?(-?)0*$/', '${1}0', $integerPart);
if ($fractionalPart !== null) {
// truncate insignificant zeros
$fractionalPart = rtrim($fractionalPart, '0');
}
$normalizedValue = $integerPart;
if (!empty($fractionalPart)) {
$normalizedValue .= '.' . $fractionalPart;
} elseif ($normalizedValue === '-0') {
$normalizedValue = '0';
}
return $normalizedValue;
}
|
php
|
protected function normalizeNumericStringValue($value)
{
$separatorPosition = strrpos($value, '.');
if ($separatorPosition !== false) {
$integerPart = substr($value, 0, $separatorPosition);
$fractionalPart = substr($value, $separatorPosition + 1);
} else {
$integerPart = $value;
$fractionalPart = null;
}
// truncate insignificant zeros, keep minus
$integerPart = preg_replace('/^\+?(-?)0*(\d+)$/', '$1$2', $integerPart);
// for zeros only leave one zero, keep minus
$integerPart = preg_replace('/^\+?(-?)0*$/', '${1}0', $integerPart);
if ($fractionalPart !== null) {
// truncate insignificant zeros
$fractionalPart = rtrim($fractionalPart, '0');
}
$normalizedValue = $integerPart;
if (!empty($fractionalPart)) {
$normalizedValue .= '.' . $fractionalPart;
} elseif ($normalizedValue === '-0') {
$normalizedValue = '0';
}
return $normalizedValue;
}
|
[
"protected",
"function",
"normalizeNumericStringValue",
"(",
"$",
"value",
")",
"{",
"$",
"separatorPosition",
"=",
"strrpos",
"(",
"$",
"value",
",",
"'.'",
")",
";",
"if",
"(",
"$",
"separatorPosition",
"!==",
"false",
")",
"{",
"$",
"integerPart",
"=",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"$",
"separatorPosition",
")",
";",
"$",
"fractionalPart",
"=",
"substr",
"(",
"$",
"value",
",",
"$",
"separatorPosition",
"+",
"1",
")",
";",
"}",
"else",
"{",
"$",
"integerPart",
"=",
"$",
"value",
";",
"$",
"fractionalPart",
"=",
"null",
";",
"}",
"// truncate insignificant zeros, keep minus",
"$",
"integerPart",
"=",
"preg_replace",
"(",
"'/^\\+?(-?)0*(\\d+)$/'",
",",
"'$1$2'",
",",
"$",
"integerPart",
")",
";",
"// for zeros only leave one zero, keep minus",
"$",
"integerPart",
"=",
"preg_replace",
"(",
"'/^\\+?(-?)0*$/'",
",",
"'${1}0'",
",",
"$",
"integerPart",
")",
";",
"if",
"(",
"$",
"fractionalPart",
"!==",
"null",
")",
"{",
"// truncate insignificant zeros",
"$",
"fractionalPart",
"=",
"rtrim",
"(",
"$",
"fractionalPart",
",",
"'0'",
")",
";",
"}",
"$",
"normalizedValue",
"=",
"$",
"integerPart",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"fractionalPart",
")",
")",
"{",
"$",
"normalizedValue",
".=",
"'.'",
".",
"$",
"fractionalPart",
";",
"}",
"elseif",
"(",
"$",
"normalizedValue",
"===",
"'-0'",
")",
"{",
"$",
"normalizedValue",
"=",
"'0'",
";",
"}",
"return",
"$",
"normalizedValue",
";",
"}"
] |
Normalizes a numeric string value.
@param string $value
@return string the normalized number value as a string
@since 2.0.16
|
[
"Normalizes",
"a",
"numeric",
"string",
"value",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/Formatter.php#L1858-L1888
|
train
|
yiisoft/yii-core
|
src/base/Component.php
|
Component.on
|
public function on($name, $handler, array $params = [], $append = true)
{
$this->ensureBehaviors();
if (strpos($name, '*') !== false) {
if ($append || empty($this->_eventWildcards[$name])) {
$this->_eventWildcards[$name][] = [$handler, $params];
} else {
array_unshift($this->_eventWildcards[$name], [$handler, $params]);
}
return;
}
if ($append || empty($this->_events[$name])) {
$this->_events[$name][] = [$handler, $params];
} else {
array_unshift($this->_events[$name], [$handler, $params]);
}
}
|
php
|
public function on($name, $handler, array $params = [], $append = true)
{
$this->ensureBehaviors();
if (strpos($name, '*') !== false) {
if ($append || empty($this->_eventWildcards[$name])) {
$this->_eventWildcards[$name][] = [$handler, $params];
} else {
array_unshift($this->_eventWildcards[$name], [$handler, $params]);
}
return;
}
if ($append || empty($this->_events[$name])) {
$this->_events[$name][] = [$handler, $params];
} else {
array_unshift($this->_events[$name], [$handler, $params]);
}
}
|
[
"public",
"function",
"on",
"(",
"$",
"name",
",",
"$",
"handler",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"append",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"ensureBehaviors",
"(",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'*'",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"append",
"||",
"empty",
"(",
"$",
"this",
"->",
"_eventWildcards",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_eventWildcards",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"[",
"$",
"handler",
",",
"$",
"params",
"]",
";",
"}",
"else",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"_eventWildcards",
"[",
"$",
"name",
"]",
",",
"[",
"$",
"handler",
",",
"$",
"params",
"]",
")",
";",
"}",
"return",
";",
"}",
"if",
"(",
"$",
"append",
"||",
"empty",
"(",
"$",
"this",
"->",
"_events",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_events",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"[",
"$",
"handler",
",",
"$",
"params",
"]",
";",
"}",
"else",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"_events",
"[",
"$",
"name",
"]",
",",
"[",
"$",
"handler",
",",
"$",
"params",
"]",
")",
";",
"}",
"}"
] |
Attaches an event handler to an event.
The event handler must be a valid PHP callback. The following are
some examples:
```
function ($event) { ... } // anonymous function
[$object, 'handleClick'] // $object->handleClick()
['Page', 'handleClick'] // Page::handleClick()
'handleClick' // global function handleClick()
```
The event handler must be defined with the following signature,
```
function ($event)
```
where `$event` is an [[Event]] object which includes parameters associated with the event.
Since 2.0.14 you can specify event name as a wildcard pattern:
```php
$component->on('event.group.*', function ($event) {
Yii::debug($event->name . ' is triggered.');
});
```
@param string $name the event name
@param callable $handler the event handler
@param array $params the parameters to be passed to the event handler when the event is triggered.
When the event handler is invoked, this data can be accessed via [[Event::data]].
@param bool $append whether to append new event handler to the end of the existing
handler list. If false, the new handler will be inserted at the beginning of the existing
handler list.
@see off()
|
[
"Attaches",
"an",
"event",
"handler",
"to",
"an",
"event",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Component.php#L524-L542
|
train
|
yiisoft/yii-core
|
src/base/ErrorHandler.php
|
ErrorHandler.register
|
public function register()
{
ini_set('display_errors', false);
set_exception_handler([$this, 'handleException']);
set_error_handler([$this, 'handleError']);
if ($this->memoryReserveSize > 0) {
$this->_memoryReserve = str_repeat('x', $this->memoryReserveSize);
}
register_shutdown_function([$this, 'handleFatalError']);
}
|
php
|
public function register()
{
ini_set('display_errors', false);
set_exception_handler([$this, 'handleException']);
set_error_handler([$this, 'handleError']);
if ($this->memoryReserveSize > 0) {
$this->_memoryReserve = str_repeat('x', $this->memoryReserveSize);
}
register_shutdown_function([$this, 'handleFatalError']);
}
|
[
"public",
"function",
"register",
"(",
")",
"{",
"ini_set",
"(",
"'display_errors'",
",",
"false",
")",
";",
"set_exception_handler",
"(",
"[",
"$",
"this",
",",
"'handleException'",
"]",
")",
";",
"set_error_handler",
"(",
"[",
"$",
"this",
",",
"'handleError'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"memoryReserveSize",
">",
"0",
")",
"{",
"$",
"this",
"->",
"_memoryReserve",
"=",
"str_repeat",
"(",
"'x'",
",",
"$",
"this",
"->",
"memoryReserveSize",
")",
";",
"}",
"register_shutdown_function",
"(",
"[",
"$",
"this",
",",
"'handleFatalError'",
"]",
")",
";",
"}"
] |
Register this error handler.
|
[
"Register",
"this",
"error",
"handler",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/ErrorHandler.php#L74-L84
|
train
|
yiisoft/yii-core
|
src/base/ErrorHandler.php
|
ErrorHandler.flushLogger
|
protected function flushLogger()
{
if ($this->logger instanceof \Yiisoft\Log\Logger) {
$this->logger->flush(true);
// attempt to invoke logger destructor:
unset($this->logger);
}
// TODO how?
// Yii::setLogger(null);
}
|
php
|
protected function flushLogger()
{
if ($this->logger instanceof \Yiisoft\Log\Logger) {
$this->logger->flush(true);
// attempt to invoke logger destructor:
unset($this->logger);
}
// TODO how?
// Yii::setLogger(null);
}
|
[
"protected",
"function",
"flushLogger",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
"instanceof",
"\\",
"Yiisoft",
"\\",
"Log",
"\\",
"Logger",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"flush",
"(",
"true",
")",
";",
"// attempt to invoke logger destructor:",
"unset",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"// TODO how?",
"// Yii::setLogger(null);",
"}"
] |
Attempts to flush logger messages.
@since 3.0.0
|
[
"Attempts",
"to",
"flush",
"logger",
"messages",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/ErrorHandler.php#L328-L337
|
train
|
yiisoft/yii-core
|
src/base/Model.php
|
Model.validateMultiple
|
public static function validateMultiple($models, $attributeNames = null, $clearErrors = true)
{
$valid = true;
/* @var $model Model */
foreach ($models as $model) {
$valid = $model->validate($attributeNames, $clearErrors) && $valid;
}
return $valid;
}
|
php
|
public static function validateMultiple($models, $attributeNames = null, $clearErrors = true)
{
$valid = true;
/* @var $model Model */
foreach ($models as $model) {
$valid = $model->validate($attributeNames, $clearErrors) && $valid;
}
return $valid;
}
|
[
"public",
"static",
"function",
"validateMultiple",
"(",
"$",
"models",
",",
"$",
"attributeNames",
"=",
"null",
",",
"$",
"clearErrors",
"=",
"true",
")",
"{",
"$",
"valid",
"=",
"true",
";",
"/* @var $model Model */",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"valid",
"=",
"$",
"model",
"->",
"validate",
"(",
"$",
"attributeNames",
",",
"$",
"clearErrors",
")",
"&&",
"$",
"valid",
";",
"}",
"return",
"$",
"valid",
";",
"}"
] |
Validates multiple models.
This method will validate every model. The models being validated may
be of the same or different types.
@param array $models the models to be validated
@param array $attributeNames list of attribute names that should be validated.
If this parameter is empty, it means any attribute listed in the applicable
validation rules should be validated.
@param bool $clearErrors whether to call [[clearErrors()]] before performing validation. Default true
@return bool whether all models are valid. False will be returned if one
or multiple models have validation error.
|
[
"Validates",
"multiple",
"models",
".",
"This",
"method",
"will",
"validate",
"every",
"model",
".",
"The",
"models",
"being",
"validated",
"may",
"be",
"of",
"the",
"same",
"or",
"different",
"types",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/Model.php#L914-L923
|
train
|
yiisoft/yii-core
|
src/i18n/Translator.php
|
Translator.init
|
public function init()
{
parent::init();
if (!isset($this->translations['yii']) && !isset($this->translations['yii*'])) {
$this->translations['yii'] = [
'__class' => PhpMessageSource::class,
'sourceLanguage' => 'en-US',
'basePath' => '@yii/messages',
];
}
if (!isset($this->translations['app']) && !isset($this->translations['app*'])) {
$this->translations['app'] = [
'__class' => PhpMessageSource::class,
'sourceLanguage' => $this->app->sourceLanguage,
'basePath' => '@app/messages',
];
}
}
|
php
|
public function init()
{
parent::init();
if (!isset($this->translations['yii']) && !isset($this->translations['yii*'])) {
$this->translations['yii'] = [
'__class' => PhpMessageSource::class,
'sourceLanguage' => 'en-US',
'basePath' => '@yii/messages',
];
}
if (!isset($this->translations['app']) && !isset($this->translations['app*'])) {
$this->translations['app'] = [
'__class' => PhpMessageSource::class,
'sourceLanguage' => $this->app->sourceLanguage,
'basePath' => '@app/messages',
];
}
}
|
[
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"translations",
"[",
"'yii'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"translations",
"[",
"'yii*'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"translations",
"[",
"'yii'",
"]",
"=",
"[",
"'__class'",
"=>",
"PhpMessageSource",
"::",
"class",
",",
"'sourceLanguage'",
"=>",
"'en-US'",
",",
"'basePath'",
"=>",
"'@yii/messages'",
",",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"translations",
"[",
"'app'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"translations",
"[",
"'app*'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"translations",
"[",
"'app'",
"]",
"=",
"[",
"'__class'",
"=>",
"PhpMessageSource",
"::",
"class",
",",
"'sourceLanguage'",
"=>",
"$",
"this",
"->",
"app",
"->",
"sourceLanguage",
",",
"'basePath'",
"=>",
"'@app/messages'",
",",
"]",
";",
"}",
"}"
] |
Initializes the component by configuring the default message categories.
|
[
"Initializes",
"the",
"component",
"by",
"configuring",
"the",
"default",
"message",
"categories",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/Translator.php#L61-L79
|
train
|
yiisoft/yii-core
|
src/helpers/BaseHtmlPurifier.php
|
BaseHtmlPurifier.process
|
public static function process(string $content, $config = null): string
{
$configInstance = static::createConfig($config);
$configInstance->autoFinalize = false;
return \HTMLPurifier::instance($configInstance)->purify($content);
}
|
php
|
public static function process(string $content, $config = null): string
{
$configInstance = static::createConfig($config);
$configInstance->autoFinalize = false;
return \HTMLPurifier::instance($configInstance)->purify($content);
}
|
[
"public",
"static",
"function",
"process",
"(",
"string",
"$",
"content",
",",
"$",
"config",
"=",
"null",
")",
":",
"string",
"{",
"$",
"configInstance",
"=",
"static",
"::",
"createConfig",
"(",
"$",
"config",
")",
";",
"$",
"configInstance",
"->",
"autoFinalize",
"=",
"false",
";",
"return",
"\\",
"HTMLPurifier",
"::",
"instance",
"(",
"$",
"configInstance",
")",
"->",
"purify",
"(",
"$",
"content",
")",
";",
"}"
] |
Passes markup through HTMLPurifier making it safe to output to end user.
@param string $content The HTML content to purify
@param array|\Closure|null $config The config to use for HtmlPurifier.
If not specified or `null` the default config will be used.
You can use an array or an anonymous function to provide configuration options:
- An array will be passed to the `HTMLPurifier_Config::create()` method.
- An anonymous function will be called after the config was created.
The signature should be: `function($config)` where `$config` will be an
instance of `HTMLPurifier_Config`.
Here is a usage example of such a function:
```php
// Allow the HTML5 data attribute `data-type` on `img` elements.
$content = HtmlPurifier::process($content, function ($config) {
$config->getHTMLDefinition(true)
->addAttribute('img', 'data-type', 'Text');
});
```
@return string the purified HTML content.
@throws InvalidConfigException
|
[
"Passes",
"markup",
"through",
"HTMLPurifier",
"making",
"it",
"safe",
"to",
"output",
"to",
"end",
"user",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseHtmlPurifier.php#L56-L62
|
train
|
yiisoft/yii-core
|
src/helpers/BaseHtmlPurifier.php
|
BaseHtmlPurifier.truncateCharacters
|
public static function truncateCharacters(string $content, int $count, string $suffix = '...', string $encoding = 'utf-8', $config = null): string
{
$config = static::createConfig($config);
$tokens = \HTMLPurifier_Lexer::create($config)->tokenizeHTML($content, $config, new \HTMLPurifier_Context());
$openTokens = [];
$totalCount = 0;
$depth = 0;
$truncated = [];
foreach ($tokens as $token) {
if ($token instanceof \HTMLPurifier_Token_Start) { //Tag begins
$openTokens[$depth] = $token->name;
$truncated[] = $token;
++$depth;
} elseif ($token instanceof \HTMLPurifier_Token_Text && $totalCount <= $count) { //Text
$token->data = StringHelper::truncateCharacters($token->data, $count - $totalCount, '', $encoding);
$currentCount = mb_strlen($token->data, $encoding);
$totalCount += $currentCount;
$truncated[] = $token;
} elseif ($token instanceof \HTMLPurifier_Token_End) { //Tag ends
if ($token->name === $openTokens[$depth - 1]) {
--$depth;
unset($openTokens[$depth]);
$truncated[] = $token;
}
} elseif ($token instanceof \HTMLPurifier_Token_Empty) { //Self contained tags, i.e. <img/> etc.
$truncated[] = $token;
}
if ($totalCount >= $count) {
if (0 < count($openTokens)) {
krsort($openTokens);
foreach ($openTokens as $name) {
$truncated[] = new \HTMLPurifier_Token_End($name);
}
}
break;
}
}
$context = new \HTMLPurifier_Context();
$generator = new \HTMLPurifier_Generator($config, $context);
return $generator->generateFromTokens($truncated) . ($totalCount >= $count ? $suffix : '');
}
|
php
|
public static function truncateCharacters(string $content, int $count, string $suffix = '...', string $encoding = 'utf-8', $config = null): string
{
$config = static::createConfig($config);
$tokens = \HTMLPurifier_Lexer::create($config)->tokenizeHTML($content, $config, new \HTMLPurifier_Context());
$openTokens = [];
$totalCount = 0;
$depth = 0;
$truncated = [];
foreach ($tokens as $token) {
if ($token instanceof \HTMLPurifier_Token_Start) { //Tag begins
$openTokens[$depth] = $token->name;
$truncated[] = $token;
++$depth;
} elseif ($token instanceof \HTMLPurifier_Token_Text && $totalCount <= $count) { //Text
$token->data = StringHelper::truncateCharacters($token->data, $count - $totalCount, '', $encoding);
$currentCount = mb_strlen($token->data, $encoding);
$totalCount += $currentCount;
$truncated[] = $token;
} elseif ($token instanceof \HTMLPurifier_Token_End) { //Tag ends
if ($token->name === $openTokens[$depth - 1]) {
--$depth;
unset($openTokens[$depth]);
$truncated[] = $token;
}
} elseif ($token instanceof \HTMLPurifier_Token_Empty) { //Self contained tags, i.e. <img/> etc.
$truncated[] = $token;
}
if ($totalCount >= $count) {
if (0 < count($openTokens)) {
krsort($openTokens);
foreach ($openTokens as $name) {
$truncated[] = new \HTMLPurifier_Token_End($name);
}
}
break;
}
}
$context = new \HTMLPurifier_Context();
$generator = new \HTMLPurifier_Generator($config, $context);
return $generator->generateFromTokens($truncated) . ($totalCount >= $count ? $suffix : '');
}
|
[
"public",
"static",
"function",
"truncateCharacters",
"(",
"string",
"$",
"content",
",",
"int",
"$",
"count",
",",
"string",
"$",
"suffix",
"=",
"'...'",
",",
"string",
"$",
"encoding",
"=",
"'utf-8'",
",",
"$",
"config",
"=",
"null",
")",
":",
"string",
"{",
"$",
"config",
"=",
"static",
"::",
"createConfig",
"(",
"$",
"config",
")",
";",
"$",
"tokens",
"=",
"\\",
"HTMLPurifier_Lexer",
"::",
"create",
"(",
"$",
"config",
")",
"->",
"tokenizeHTML",
"(",
"$",
"content",
",",
"$",
"config",
",",
"new",
"\\",
"HTMLPurifier_Context",
"(",
")",
")",
";",
"$",
"openTokens",
"=",
"[",
"]",
";",
"$",
"totalCount",
"=",
"0",
";",
"$",
"depth",
"=",
"0",
";",
"$",
"truncated",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"tokens",
"as",
"$",
"token",
")",
"{",
"if",
"(",
"$",
"token",
"instanceof",
"\\",
"HTMLPurifier_Token_Start",
")",
"{",
"//Tag begins",
"$",
"openTokens",
"[",
"$",
"depth",
"]",
"=",
"$",
"token",
"->",
"name",
";",
"$",
"truncated",
"[",
"]",
"=",
"$",
"token",
";",
"++",
"$",
"depth",
";",
"}",
"elseif",
"(",
"$",
"token",
"instanceof",
"\\",
"HTMLPurifier_Token_Text",
"&&",
"$",
"totalCount",
"<=",
"$",
"count",
")",
"{",
"//Text",
"$",
"token",
"->",
"data",
"=",
"StringHelper",
"::",
"truncateCharacters",
"(",
"$",
"token",
"->",
"data",
",",
"$",
"count",
"-",
"$",
"totalCount",
",",
"''",
",",
"$",
"encoding",
")",
";",
"$",
"currentCount",
"=",
"mb_strlen",
"(",
"$",
"token",
"->",
"data",
",",
"$",
"encoding",
")",
";",
"$",
"totalCount",
"+=",
"$",
"currentCount",
";",
"$",
"truncated",
"[",
"]",
"=",
"$",
"token",
";",
"}",
"elseif",
"(",
"$",
"token",
"instanceof",
"\\",
"HTMLPurifier_Token_End",
")",
"{",
"//Tag ends",
"if",
"(",
"$",
"token",
"->",
"name",
"===",
"$",
"openTokens",
"[",
"$",
"depth",
"-",
"1",
"]",
")",
"{",
"--",
"$",
"depth",
";",
"unset",
"(",
"$",
"openTokens",
"[",
"$",
"depth",
"]",
")",
";",
"$",
"truncated",
"[",
"]",
"=",
"$",
"token",
";",
"}",
"}",
"elseif",
"(",
"$",
"token",
"instanceof",
"\\",
"HTMLPurifier_Token_Empty",
")",
"{",
"//Self contained tags, i.e. <img/> etc.",
"$",
"truncated",
"[",
"]",
"=",
"$",
"token",
";",
"}",
"if",
"(",
"$",
"totalCount",
">=",
"$",
"count",
")",
"{",
"if",
"(",
"0",
"<",
"count",
"(",
"$",
"openTokens",
")",
")",
"{",
"krsort",
"(",
"$",
"openTokens",
")",
";",
"foreach",
"(",
"$",
"openTokens",
"as",
"$",
"name",
")",
"{",
"$",
"truncated",
"[",
"]",
"=",
"new",
"\\",
"HTMLPurifier_Token_End",
"(",
"$",
"name",
")",
";",
"}",
"}",
"break",
";",
"}",
"}",
"$",
"context",
"=",
"new",
"\\",
"HTMLPurifier_Context",
"(",
")",
";",
"$",
"generator",
"=",
"new",
"\\",
"HTMLPurifier_Generator",
"(",
"$",
"config",
",",
"$",
"context",
")",
";",
"return",
"$",
"generator",
"->",
"generateFromTokens",
"(",
"$",
"truncated",
")",
".",
"(",
"$",
"totalCount",
">=",
"$",
"count",
"?",
"$",
"suffix",
":",
"''",
")",
";",
"}"
] |
Truncate a HTML string to count of characters specified.
@param string $content The string to be truncated.
@param int $count
@param string $suffix String to append to the end of the truncated string. Default is empty string.
@param string $encoding
@param array|\Closure|null $config The config to use for HtmlPurifier.
@return string
@throws InvalidConfigException
@throws \HTMLPurifier_Exception
|
[
"Truncate",
"a",
"HTML",
"string",
"to",
"count",
"of",
"characters",
"specified",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/helpers/BaseHtmlPurifier.php#L76-L118
|
train
|
yiisoft/yii-core
|
src/http/Uri.php
|
Uri.setComponent
|
protected function setComponent($name, $value)
{
if ($this->_string !== null) {
$this->_components = $this->parseUri($this->_string);
}
$this->_components[$name] = $value;
$this->_string = null;
}
|
php
|
protected function setComponent($name, $value)
{
if ($this->_string !== null) {
$this->_components = $this->parseUri($this->_string);
}
$this->_components[$name] = $value;
$this->_string = null;
}
|
[
"protected",
"function",
"setComponent",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_string",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_components",
"=",
"$",
"this",
"->",
"parseUri",
"(",
"$",
"this",
"->",
"_string",
")",
";",
"}",
"$",
"this",
"->",
"_components",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"_string",
"=",
"null",
";",
"}"
] |
Sets up particular URI component.
@param string $name URI component name.
@param mixed $value URI component value.
|
[
"Sets",
"up",
"particular",
"URI",
"component",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/http/Uri.php#L305-L312
|
train
|
yiisoft/yii-core
|
src/http/Uri.php
|
Uri.getComponents
|
protected function getComponents()
{
if ($this->_components === null) {
if ($this->_string === null) {
return [];
}
$this->_components = $this->parseUri($this->_string);
}
return $this->_components;
}
|
php
|
protected function getComponents()
{
if ($this->_components === null) {
if ($this->_string === null) {
return [];
}
$this->_components = $this->parseUri($this->_string);
}
return $this->_components;
}
|
[
"protected",
"function",
"getComponents",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_components",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_string",
"===",
"null",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"_components",
"=",
"$",
"this",
"->",
"parseUri",
"(",
"$",
"this",
"->",
"_string",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_components",
";",
"}"
] |
Returns URI components for this instance as an associative array.
@return array URI components in format: `[name => value]`
|
[
"Returns",
"URI",
"components",
"for",
"this",
"instance",
"as",
"an",
"associative",
"array",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/http/Uri.php#L332-L341
|
train
|
yiisoft/yii-core
|
src/http/Uri.php
|
Uri.composeUri
|
protected function composeUri(array $components)
{
$uri = '';
$scheme = empty($components['scheme']) ? 'http' : $components['scheme'];
if ($scheme !== '') {
$uri .= $scheme . ':';
}
$authority = $this->composeAuthority($components);
if ($authority !== '' || $scheme === 'file') {
// authority separator is added even when the authority is missing/empty for the "file" scheme
// while `file:///myfile` and `file:/myfile` are equivalent according to RFC 3986, `file:///` is more common
// PHP functions and Chrome, for example, use this format
$uri .= '//' . $authority;
}
if (!empty($components['path'])) {
$uri .= $components['path'];
}
if (!empty($components['query'])) {
$uri .= '?' . $components['query'];
}
if (!empty($components['fragment'])) {
$uri .= '#' . $components['fragment'];
}
return $uri;
}
|
php
|
protected function composeUri(array $components)
{
$uri = '';
$scheme = empty($components['scheme']) ? 'http' : $components['scheme'];
if ($scheme !== '') {
$uri .= $scheme . ':';
}
$authority = $this->composeAuthority($components);
if ($authority !== '' || $scheme === 'file') {
// authority separator is added even when the authority is missing/empty for the "file" scheme
// while `file:///myfile` and `file:/myfile` are equivalent according to RFC 3986, `file:///` is more common
// PHP functions and Chrome, for example, use this format
$uri .= '//' . $authority;
}
if (!empty($components['path'])) {
$uri .= $components['path'];
}
if (!empty($components['query'])) {
$uri .= '?' . $components['query'];
}
if (!empty($components['fragment'])) {
$uri .= '#' . $components['fragment'];
}
return $uri;
}
|
[
"protected",
"function",
"composeUri",
"(",
"array",
"$",
"components",
")",
"{",
"$",
"uri",
"=",
"''",
";",
"$",
"scheme",
"=",
"empty",
"(",
"$",
"components",
"[",
"'scheme'",
"]",
")",
"?",
"'http'",
":",
"$",
"components",
"[",
"'scheme'",
"]",
";",
"if",
"(",
"$",
"scheme",
"!==",
"''",
")",
"{",
"$",
"uri",
".=",
"$",
"scheme",
".",
"':'",
";",
"}",
"$",
"authority",
"=",
"$",
"this",
"->",
"composeAuthority",
"(",
"$",
"components",
")",
";",
"if",
"(",
"$",
"authority",
"!==",
"''",
"||",
"$",
"scheme",
"===",
"'file'",
")",
"{",
"// authority separator is added even when the authority is missing/empty for the \"file\" scheme",
"// while `file:///myfile` and `file:/myfile` are equivalent according to RFC 3986, `file:///` is more common",
"// PHP functions and Chrome, for example, use this format",
"$",
"uri",
".=",
"'//'",
".",
"$",
"authority",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"components",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"uri",
".=",
"$",
"components",
"[",
"'path'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"components",
"[",
"'query'",
"]",
")",
")",
"{",
"$",
"uri",
".=",
"'?'",
".",
"$",
"components",
"[",
"'query'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"components",
"[",
"'fragment'",
"]",
")",
")",
"{",
"$",
"uri",
".=",
"'#'",
".",
"$",
"components",
"[",
"'fragment'",
"]",
";",
"}",
"return",
"$",
"uri",
";",
"}"
] |
Composes URI string from given components.
@param array $components URI components.
@return string URI full string.
|
[
"Composes",
"URI",
"string",
"from",
"given",
"components",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/http/Uri.php#L363-L394
|
train
|
yiisoft/yii-core
|
src/http/Uri.php
|
Uri.isDefaultPort
|
protected function isDefaultPort($scheme, $port)
{
if (!isset(self::$defaultPorts[$scheme])) {
return false;
}
return self::$defaultPorts[$scheme] == $port;
}
|
php
|
protected function isDefaultPort($scheme, $port)
{
if (!isset(self::$defaultPorts[$scheme])) {
return false;
}
return self::$defaultPorts[$scheme] == $port;
}
|
[
"protected",
"function",
"isDefaultPort",
"(",
"$",
"scheme",
",",
"$",
"port",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"defaultPorts",
"[",
"$",
"scheme",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"self",
"::",
"$",
"defaultPorts",
"[",
"$",
"scheme",
"]",
"==",
"$",
"port",
";",
"}"
] |
Checks whether specified port is default one for the specified scheme.
@param string $scheme scheme.
@param int $port port number.
@return bool whether specified port is default for specified scheme
|
[
"Checks",
"whether",
"specified",
"port",
"is",
"default",
"one",
"for",
"the",
"specified",
"scheme",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/http/Uri.php#L447-L453
|
train
|
yiisoft/yii-core
|
src/mail/BaseMessage.php
|
BaseMessage.send
|
public function send(MailerInterface $mailer = null)
{
if ($mailer === null && $this->mailer === null) {
$mailer = Yii::getApp()->getMailer();
} elseif ($mailer === null) {
$mailer = $this->mailer;
}
return $mailer->send($this);
}
|
php
|
public function send(MailerInterface $mailer = null)
{
if ($mailer === null && $this->mailer === null) {
$mailer = Yii::getApp()->getMailer();
} elseif ($mailer === null) {
$mailer = $this->mailer;
}
return $mailer->send($this);
}
|
[
"public",
"function",
"send",
"(",
"MailerInterface",
"$",
"mailer",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"mailer",
"===",
"null",
"&&",
"$",
"this",
"->",
"mailer",
"===",
"null",
")",
"{",
"$",
"mailer",
"=",
"Yii",
"::",
"getApp",
"(",
")",
"->",
"getMailer",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"mailer",
"===",
"null",
")",
"{",
"$",
"mailer",
"=",
"$",
"this",
"->",
"mailer",
";",
"}",
"return",
"$",
"mailer",
"->",
"send",
"(",
"$",
"this",
")",
";",
"}"
] |
Sends this email message.
@param MailerInterface $mailer the mailer that should be used to send this message.
If no mailer is given it will first check if [[mailer]] is set and if not,
the "mail" application component will be used instead.
@return bool whether this message is sent successfully.
|
[
"Sends",
"this",
"email",
"message",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/mail/BaseMessage.php#L41-L50
|
train
|
yiisoft/yii-core
|
src/i18n/Locale.php
|
Locale.getFallbackLocale
|
public function getFallbackLocale(): self
{
if ($this->variant !== null) {
return $this->withVariant(null);
}
if ($this->region !== null) {
return $this->withRegion(null);
}
if ($this->script !== null) {
return $this->withScript(null);
}
return $this;
}
|
php
|
public function getFallbackLocale(): self
{
if ($this->variant !== null) {
return $this->withVariant(null);
}
if ($this->region !== null) {
return $this->withRegion(null);
}
if ($this->script !== null) {
return $this->withScript(null);
}
return $this;
}
|
[
"public",
"function",
"getFallbackLocale",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"variant",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"withVariant",
"(",
"null",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"region",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"withRegion",
"(",
"null",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"script",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"withScript",
"(",
"null",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Returns fallback locale
@return self fallback locale
|
[
"Returns",
"fallback",
"locale"
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/Locale.php#L461-L476
|
train
|
yiisoft/yii-core
|
src/data/Pagination.php
|
Pagination.createUrl
|
public function createUrl($page, $pageSize = null, $absolute = false)
{
$page = (int) $page;
$pageSize = (int) $pageSize;
if (($params = $this->params) === null) {
$request = Yii::getApp()->getRequest();
$params = $request instanceof Request ? $request->getQueryParams() : [];
}
if ($page > 0 || $page == 0 && $this->forcePageParam) {
$params[$this->pageParam] = $page + 1;
} else {
unset($params[$this->pageParam]);
}
if ($pageSize <= 0) {
$pageSize = $this->getPageSize();
}
if ($pageSize != $this->defaultPageSize) {
$params[$this->pageSizeParam] = $pageSize;
} else {
unset($params[$this->pageSizeParam]);
}
$params[0] = $this->route ?? Yii::getApp()->controller->getRoute();
$urlManager = $this->urlManager ?? Yii::getApp()->getUrlManager();
if ($absolute) {
return $urlManager->createAbsoluteUrl($params);
}
return $urlManager->createUrl($params);
}
|
php
|
public function createUrl($page, $pageSize = null, $absolute = false)
{
$page = (int) $page;
$pageSize = (int) $pageSize;
if (($params = $this->params) === null) {
$request = Yii::getApp()->getRequest();
$params = $request instanceof Request ? $request->getQueryParams() : [];
}
if ($page > 0 || $page == 0 && $this->forcePageParam) {
$params[$this->pageParam] = $page + 1;
} else {
unset($params[$this->pageParam]);
}
if ($pageSize <= 0) {
$pageSize = $this->getPageSize();
}
if ($pageSize != $this->defaultPageSize) {
$params[$this->pageSizeParam] = $pageSize;
} else {
unset($params[$this->pageSizeParam]);
}
$params[0] = $this->route ?? Yii::getApp()->controller->getRoute();
$urlManager = $this->urlManager ?? Yii::getApp()->getUrlManager();
if ($absolute) {
return $urlManager->createAbsoluteUrl($params);
}
return $urlManager->createUrl($params);
}
|
[
"public",
"function",
"createUrl",
"(",
"$",
"page",
",",
"$",
"pageSize",
"=",
"null",
",",
"$",
"absolute",
"=",
"false",
")",
"{",
"$",
"page",
"=",
"(",
"int",
")",
"$",
"page",
";",
"$",
"pageSize",
"=",
"(",
"int",
")",
"$",
"pageSize",
";",
"if",
"(",
"(",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
")",
"===",
"null",
")",
"{",
"$",
"request",
"=",
"Yii",
"::",
"getApp",
"(",
")",
"->",
"getRequest",
"(",
")",
";",
"$",
"params",
"=",
"$",
"request",
"instanceof",
"Request",
"?",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
":",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"page",
">",
"0",
"||",
"$",
"page",
"==",
"0",
"&&",
"$",
"this",
"->",
"forcePageParam",
")",
"{",
"$",
"params",
"[",
"$",
"this",
"->",
"pageParam",
"]",
"=",
"$",
"page",
"+",
"1",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"params",
"[",
"$",
"this",
"->",
"pageParam",
"]",
")",
";",
"}",
"if",
"(",
"$",
"pageSize",
"<=",
"0",
")",
"{",
"$",
"pageSize",
"=",
"$",
"this",
"->",
"getPageSize",
"(",
")",
";",
"}",
"if",
"(",
"$",
"pageSize",
"!=",
"$",
"this",
"->",
"defaultPageSize",
")",
"{",
"$",
"params",
"[",
"$",
"this",
"->",
"pageSizeParam",
"]",
"=",
"$",
"pageSize",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"params",
"[",
"$",
"this",
"->",
"pageSizeParam",
"]",
")",
";",
"}",
"$",
"params",
"[",
"0",
"]",
"=",
"$",
"this",
"->",
"route",
"??",
"Yii",
"::",
"getApp",
"(",
")",
"->",
"controller",
"->",
"getRoute",
"(",
")",
";",
"$",
"urlManager",
"=",
"$",
"this",
"->",
"urlManager",
"??",
"Yii",
"::",
"getApp",
"(",
")",
"->",
"getUrlManager",
"(",
")",
";",
"if",
"(",
"$",
"absolute",
")",
"{",
"return",
"$",
"urlManager",
"->",
"createAbsoluteUrl",
"(",
"$",
"params",
")",
";",
"}",
"return",
"$",
"urlManager",
"->",
"createUrl",
"(",
"$",
"params",
")",
";",
"}"
] |
Creates the URL suitable for pagination with the specified page number.
This method is mainly called by pagers when creating URLs used to perform pagination.
@param int $page the zero-based page number that the URL should point to.
@param int $pageSize the number of items on each page. If not set, the value of [[pageSize]] will be used.
@param bool $absolute whether to create an absolute URL. Defaults to `false`.
@return string the created URL
@see params
@see forcePageParam
|
[
"Creates",
"the",
"URL",
"suitable",
"for",
"pagination",
"with",
"the",
"specified",
"page",
"number",
".",
"This",
"method",
"is",
"mainly",
"called",
"by",
"pagers",
"when",
"creating",
"URLs",
"used",
"to",
"perform",
"pagination",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/data/Pagination.php#L259-L287
|
train
|
yiisoft/yii-core
|
src/base/BaseObject.php
|
BaseObject.__isset
|
public function __isset($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter() !== null;
}
return false;
}
|
php
|
public function __isset($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter() !== null;
}
return false;
}
|
[
"public",
"function",
"__isset",
"(",
"$",
"name",
")",
"{",
"$",
"getter",
"=",
"'get'",
".",
"$",
"name",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"getter",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
"!==",
"null",
";",
"}",
"return",
"false",
";",
"}"
] |
Checks if a property is set, i.e. defined and not null.
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing `isset($object->property)`.
Note that if the property is not defined, false will be returned.
@param string $name the property name or the event name
@return bool whether the named property is set (not null).
@see http://php.net/manual/en/function.isset.php
|
[
"Checks",
"if",
"a",
"property",
"is",
"set",
"i",
".",
"e",
".",
"defined",
"and",
"not",
"null",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/BaseObject.php#L140-L148
|
train
|
yiisoft/yii-core
|
src/base/BaseObject.php
|
BaseObject.canGetProperty
|
public function canGetProperty($name, $checkVars = true)
{
return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}
|
php
|
public function canGetProperty($name, $checkVars = true)
{
return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}
|
[
"public",
"function",
"canGetProperty",
"(",
"$",
"name",
",",
"$",
"checkVars",
"=",
"true",
")",
"{",
"return",
"method_exists",
"(",
"$",
"this",
",",
"'get'",
".",
"$",
"name",
")",
"||",
"$",
"checkVars",
"&&",
"property_exists",
"(",
"$",
"this",
",",
"$",
"name",
")",
";",
"}"
] |
Returns a value indicating whether a property can be read.
A property is readable if:
- the class has a getter method associated with the specified name
(in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when `$checkVars` is true);
@param string $name the property name
@param bool $checkVars whether to treat member variables as properties
@return bool whether the property can be read
@see canSetProperty()
|
[
"Returns",
"a",
"value",
"indicating",
"whether",
"a",
"property",
"can",
"be",
"read",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/base/BaseObject.php#L221-L224
|
train
|
yiisoft/yii-core
|
src/i18n/I18N.php
|
I18N.translate
|
public function translate(string $category, string $message, array $params = [], string $language = null)
{
return $this->translator->translate($category, $message, $params, $language ?: (string)$this->locale);
}
|
php
|
public function translate(string $category, string $message, array $params = [], string $language = null)
{
return $this->translator->translate($category, $message, $params, $language ?: (string)$this->locale);
}
|
[
"public",
"function",
"translate",
"(",
"string",
"$",
"category",
",",
"string",
"$",
"message",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"string",
"$",
"language",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"translator",
"->",
"translate",
"(",
"$",
"category",
",",
"$",
"message",
",",
"$",
"params",
",",
"$",
"language",
"?",
":",
"(",
"string",
")",
"$",
"this",
"->",
"locale",
")",
";",
"}"
] |
Translates a message to the specified language.
Drops in the current locale when language is not given.
@see Translator::translate()
|
[
"Translates",
"a",
"message",
"to",
"the",
"specified",
"language",
".",
"Drops",
"in",
"the",
"current",
"locale",
"when",
"language",
"is",
"not",
"given",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/I18N.php#L119-L122
|
train
|
yiisoft/yii-core
|
src/i18n/I18N.php
|
I18N.getCurrencySymbol
|
public function getCurrencySymbol($currencyCode = null): string
{
if (!extension_loaded('intl')) {
throw new InvalidConfigException('Locale component requires PHP intl extension to be installed.');
}
$locale = $this->locale;
if ($currencyCode !== null) {
$locale = $locale->withCurrency($currencyCode);
}
$formatter = new NumberFormatter((string)$locale, NumberFormatter::CURRENCY);
return $formatter->getSymbol(NumberFormatter::CURRENCY_SYMBOL);
}
|
php
|
public function getCurrencySymbol($currencyCode = null): string
{
if (!extension_loaded('intl')) {
throw new InvalidConfigException('Locale component requires PHP intl extension to be installed.');
}
$locale = $this->locale;
if ($currencyCode !== null) {
$locale = $locale->withCurrency($currencyCode);
}
$formatter = new NumberFormatter((string)$locale, NumberFormatter::CURRENCY);
return $formatter->getSymbol(NumberFormatter::CURRENCY_SYMBOL);
}
|
[
"public",
"function",
"getCurrencySymbol",
"(",
"$",
"currencyCode",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"!",
"extension_loaded",
"(",
"'intl'",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"'Locale component requires PHP intl extension to be installed.'",
")",
";",
"}",
"$",
"locale",
"=",
"$",
"this",
"->",
"locale",
";",
"if",
"(",
"$",
"currencyCode",
"!==",
"null",
")",
"{",
"$",
"locale",
"=",
"$",
"locale",
"->",
"withCurrency",
"(",
"$",
"currencyCode",
")",
";",
"}",
"$",
"formatter",
"=",
"new",
"NumberFormatter",
"(",
"(",
"string",
")",
"$",
"locale",
",",
"NumberFormatter",
"::",
"CURRENCY",
")",
";",
"return",
"$",
"formatter",
"->",
"getSymbol",
"(",
"NumberFormatter",
"::",
"CURRENCY_SYMBOL",
")",
";",
"}"
] |
Returns a currency symbol
@param string $currencyCode the 3-letter ISO 4217 currency code to get symbol for. If null,
method will attempt using currency code from current locale.
@return string
@throws InvalidConfigException
|
[
"Returns",
"a",
"currency",
"symbol"
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/I18N.php#L145-L159
|
train
|
yiisoft/yii-core
|
src/i18n/PhpMessageSource.php
|
PhpMessageSource.loadMessagesFromFile
|
protected function loadMessagesFromFile($messageFile)
{
if (is_file($messageFile)) {
$messages = include $messageFile;
if (!\is_array($messages)) {
$messages = [];
}
return $messages;
}
return null;
}
|
php
|
protected function loadMessagesFromFile($messageFile)
{
if (is_file($messageFile)) {
$messages = include $messageFile;
if (!\is_array($messages)) {
$messages = [];
}
return $messages;
}
return null;
}
|
[
"protected",
"function",
"loadMessagesFromFile",
"(",
"$",
"messageFile",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"messageFile",
")",
")",
"{",
"$",
"messages",
"=",
"include",
"$",
"messageFile",
";",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"messages",
")",
")",
"{",
"$",
"messages",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"messages",
";",
"}",
"return",
"null",
";",
"}"
] |
Loads the message translation for the specified language and category or returns null if file doesn't exist.
@param string $messageFile path to message file
@return array|null array of messages or null if file not found
|
[
"Loads",
"the",
"message",
"translation",
"for",
"the",
"specified",
"language",
"and",
"category",
"or",
"returns",
"null",
"if",
"file",
"doesn",
"t",
"exist",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/PhpMessageSource.php#L163-L175
|
train
|
yiisoft/yii-core
|
build/controllers/ClassmapController.php
|
ClassmapController.actionCreate
|
public function actionCreate($root = null, $mapFile = null)
{
if ($root === null) {
$root = YII_PATH;
}
$root = FileHelper::normalizePath($root);
if ($mapFile === null) {
$mapFile = YII_PATH . '/classes.php';
}
$options = [
'filter' => function ($path) {
if (is_file($path)) {
$file = basename($path);
if ($file[0] < 'A' || $file[0] > 'Z') {
return false;
}
}
return null;
},
'only' => ['*.php'],
'except' => [
'/Yii.php',
'/BaseYii.php',
'/console/',
'/requirements/',
],
];
$files = FileHelper::findFiles($root, $options);
$map = [];
foreach ($files as $file) {
if (strpos($file, $root) !== 0) {
throw new Exception("Something wrong: $file\n");
}
$path = str_replace('\\', '/', substr($file, \strlen($root)));
$map[$path] = " 'yii" . substr(str_replace('/', '\\', $path), 0, -4) . "' => YII_PATH . '$path',";
}
ksort($map);
$map = implode("\n", $map);
$output = <<<EOD
<?php
/**
* Yii core class map.
*
* This file is automatically generated by the "build classmap" command under the "build" folder.
* Do not modify it directly.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
return [
$map
];
EOD;
if (is_file($mapFile) && file_get_contents($mapFile) === $output) {
echo "Nothing changed.\n";
} else {
file_put_contents($mapFile, $output);
echo "Class map saved in $mapFile\n";
}
}
|
php
|
public function actionCreate($root = null, $mapFile = null)
{
if ($root === null) {
$root = YII_PATH;
}
$root = FileHelper::normalizePath($root);
if ($mapFile === null) {
$mapFile = YII_PATH . '/classes.php';
}
$options = [
'filter' => function ($path) {
if (is_file($path)) {
$file = basename($path);
if ($file[0] < 'A' || $file[0] > 'Z') {
return false;
}
}
return null;
},
'only' => ['*.php'],
'except' => [
'/Yii.php',
'/BaseYii.php',
'/console/',
'/requirements/',
],
];
$files = FileHelper::findFiles($root, $options);
$map = [];
foreach ($files as $file) {
if (strpos($file, $root) !== 0) {
throw new Exception("Something wrong: $file\n");
}
$path = str_replace('\\', '/', substr($file, \strlen($root)));
$map[$path] = " 'yii" . substr(str_replace('/', '\\', $path), 0, -4) . "' => YII_PATH . '$path',";
}
ksort($map);
$map = implode("\n", $map);
$output = <<<EOD
<?php
/**
* Yii core class map.
*
* This file is automatically generated by the "build classmap" command under the "build" folder.
* Do not modify it directly.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
return [
$map
];
EOD;
if (is_file($mapFile) && file_get_contents($mapFile) === $output) {
echo "Nothing changed.\n";
} else {
file_put_contents($mapFile, $output);
echo "Class map saved in $mapFile\n";
}
}
|
[
"public",
"function",
"actionCreate",
"(",
"$",
"root",
"=",
"null",
",",
"$",
"mapFile",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"root",
"===",
"null",
")",
"{",
"$",
"root",
"=",
"YII_PATH",
";",
"}",
"$",
"root",
"=",
"FileHelper",
"::",
"normalizePath",
"(",
"$",
"root",
")",
";",
"if",
"(",
"$",
"mapFile",
"===",
"null",
")",
"{",
"$",
"mapFile",
"=",
"YII_PATH",
".",
"'/classes.php'",
";",
"}",
"$",
"options",
"=",
"[",
"'filter'",
"=>",
"function",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"path",
")",
")",
"{",
"$",
"file",
"=",
"basename",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"file",
"[",
"0",
"]",
"<",
"'A'",
"||",
"$",
"file",
"[",
"0",
"]",
">",
"'Z'",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"null",
";",
"}",
",",
"'only'",
"=>",
"[",
"'*.php'",
"]",
",",
"'except'",
"=>",
"[",
"'/Yii.php'",
",",
"'/BaseYii.php'",
",",
"'/console/'",
",",
"'/requirements/'",
",",
"]",
",",
"]",
";",
"$",
"files",
"=",
"FileHelper",
"::",
"findFiles",
"(",
"$",
"root",
",",
"$",
"options",
")",
";",
"$",
"map",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"file",
",",
"$",
"root",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Something wrong: $file\\n\"",
")",
";",
"}",
"$",
"path",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"substr",
"(",
"$",
"file",
",",
"\\",
"strlen",
"(",
"$",
"root",
")",
")",
")",
";",
"$",
"map",
"[",
"$",
"path",
"]",
"=",
"\" 'yii\"",
".",
"substr",
"(",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"path",
")",
",",
"0",
",",
"-",
"4",
")",
".",
"\"' => YII_PATH . '$path',\"",
";",
"}",
"ksort",
"(",
"$",
"map",
")",
";",
"$",
"map",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"map",
")",
";",
"$",
"output",
"=",
" <<<EOD\n<?php\n/**\n * Yii core class map.\n *\n * This file is automatically generated by the \"build classmap\" command under the \"build\" folder.\n * Do not modify it directly.\n *\n * @link http://www.yiiframework.com/\n * @copyright Copyright (c) 2008 Yii Software LLC\n * @license http://www.yiiframework.com/license/\n */\n\nreturn [\n$map\n];\n\nEOD",
";",
"if",
"(",
"is_file",
"(",
"$",
"mapFile",
")",
"&&",
"file_get_contents",
"(",
"$",
"mapFile",
")",
"===",
"$",
"output",
")",
"{",
"echo",
"\"Nothing changed.\\n\"",
";",
"}",
"else",
"{",
"file_put_contents",
"(",
"$",
"mapFile",
",",
"$",
"output",
")",
";",
"echo",
"\"Class map saved in $mapFile\\n\"",
";",
"}",
"}"
] |
Creates a class map for the core Yii classes.
@param string $root the root path of Yii framework. Defaults to YII_PATH.
@param string $mapFile the file to contain the class map. Defaults to YII_PATH . '/classes.php'.
|
[
"Creates",
"a",
"class",
"map",
"for",
"the",
"core",
"Yii",
"classes",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/build/controllers/ClassmapController.php#L29-L92
|
train
|
yiisoft/yii-core
|
src/data/Sort.php
|
Sort.createSortParam
|
public function createSortParam($attribute)
{
if (!isset($this->attributes[$attribute])) {
throw new InvalidConfigException("Unknown attribute: $attribute");
}
$definition = $this->attributes[$attribute];
$directions = $this->getAttributeOrders();
if (isset($directions[$attribute])) {
$direction = $directions[$attribute] === SORT_DESC ? SORT_ASC : SORT_DESC;
unset($directions[$attribute]);
} else {
$direction = $definition['default'] ?? SORT_ASC;
}
if ($this->enableMultiSort) {
$directions = array_merge([$attribute => $direction], $directions);
} else {
$directions = [$attribute => $direction];
}
$sorts = [];
foreach ($directions as $attribute => $direction) {
$sorts[] = $direction === SORT_DESC ? '-' . $attribute : $attribute;
}
return implode($this->separator, $sorts);
}
|
php
|
public function createSortParam($attribute)
{
if (!isset($this->attributes[$attribute])) {
throw new InvalidConfigException("Unknown attribute: $attribute");
}
$definition = $this->attributes[$attribute];
$directions = $this->getAttributeOrders();
if (isset($directions[$attribute])) {
$direction = $directions[$attribute] === SORT_DESC ? SORT_ASC : SORT_DESC;
unset($directions[$attribute]);
} else {
$direction = $definition['default'] ?? SORT_ASC;
}
if ($this->enableMultiSort) {
$directions = array_merge([$attribute => $direction], $directions);
} else {
$directions = [$attribute => $direction];
}
$sorts = [];
foreach ($directions as $attribute => $direction) {
$sorts[] = $direction === SORT_DESC ? '-' . $attribute : $attribute;
}
return implode($this->separator, $sorts);
}
|
[
"public",
"function",
"createSortParam",
"(",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"$",
"attribute",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"\"Unknown attribute: $attribute\"",
")",
";",
"}",
"$",
"definition",
"=",
"$",
"this",
"->",
"attributes",
"[",
"$",
"attribute",
"]",
";",
"$",
"directions",
"=",
"$",
"this",
"->",
"getAttributeOrders",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"directions",
"[",
"$",
"attribute",
"]",
")",
")",
"{",
"$",
"direction",
"=",
"$",
"directions",
"[",
"$",
"attribute",
"]",
"===",
"SORT_DESC",
"?",
"SORT_ASC",
":",
"SORT_DESC",
";",
"unset",
"(",
"$",
"directions",
"[",
"$",
"attribute",
"]",
")",
";",
"}",
"else",
"{",
"$",
"direction",
"=",
"$",
"definition",
"[",
"'default'",
"]",
"??",
"SORT_ASC",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"enableMultiSort",
")",
"{",
"$",
"directions",
"=",
"array_merge",
"(",
"[",
"$",
"attribute",
"=>",
"$",
"direction",
"]",
",",
"$",
"directions",
")",
";",
"}",
"else",
"{",
"$",
"directions",
"=",
"[",
"$",
"attribute",
"=>",
"$",
"direction",
"]",
";",
"}",
"$",
"sorts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"directions",
"as",
"$",
"attribute",
"=>",
"$",
"direction",
")",
"{",
"$",
"sorts",
"[",
"]",
"=",
"$",
"direction",
"===",
"SORT_DESC",
"?",
"'-'",
".",
"$",
"attribute",
":",
"$",
"attribute",
";",
"}",
"return",
"implode",
"(",
"$",
"this",
"->",
"separator",
",",
"$",
"sorts",
")",
";",
"}"
] |
Creates the sort variable for the specified attribute.
The newly created sort variable can be used to create a URL that will lead to
sorting by the specified attribute.
@param string $attribute the attribute name
@return string the value of the sort variable
@throws InvalidConfigException if the specified attribute is not defined in [[attributes]]
|
[
"Creates",
"the",
"sort",
"variable",
"for",
"the",
"specified",
"attribute",
".",
"The",
"newly",
"created",
"sort",
"variable",
"can",
"be",
"used",
"to",
"create",
"a",
"URL",
"that",
"will",
"lead",
"to",
"sorting",
"by",
"the",
"specified",
"attribute",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/data/Sort.php#L437-L463
|
train
|
yiisoft/yii-core
|
src/i18n/TranslationEvent.php
|
TranslationEvent.missing
|
public static function missing(string $category, $message, string $language)
{
return new static(static::MISSING, $category, $message, $language);
}
|
php
|
public static function missing(string $category, $message, string $language)
{
return new static(static::MISSING, $category, $message, $language);
}
|
[
"public",
"static",
"function",
"missing",
"(",
"string",
"$",
"category",
",",
"$",
"message",
",",
"string",
"$",
"language",
")",
"{",
"return",
"new",
"static",
"(",
"static",
"::",
"MISSING",
",",
"$",
"category",
",",
"$",
"message",
",",
"$",
"language",
")",
";",
"}"
] |
Create MISSING translation event.
@param string $category message category
@param string $message the translated message
@param string $language the language ID e.g. en-US
|
[
"Create",
"MISSING",
"translation",
"event",
"."
] |
50c9eb923394c822d86bfc954cf026a7396bc95a
|
https://github.com/yiisoft/yii-core/blob/50c9eb923394c822d86bfc954cf026a7396bc95a/src/i18n/TranslationEvent.php#L64-L67
|
train
|
cweagans/composer-patches
|
src/PatchCollection.php
|
PatchCollection.fromJson
|
public static function fromJson($json)
{
if (!is_object($json)) {
$json = json_decode($json);
}
$collection = new static();
foreach ($json->patches as $package => $patches) {
foreach ($patches as $patch_json) {
$patch = Patch::fromJson($patch_json);
$collection->addPatch($patch);
}
}
return $collection;
}
|
php
|
public static function fromJson($json)
{
if (!is_object($json)) {
$json = json_decode($json);
}
$collection = new static();
foreach ($json->patches as $package => $patches) {
foreach ($patches as $patch_json) {
$patch = Patch::fromJson($patch_json);
$collection->addPatch($patch);
}
}
return $collection;
}
|
[
"public",
"static",
"function",
"fromJson",
"(",
"$",
"json",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"json",
")",
")",
"{",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"json",
")",
";",
"}",
"$",
"collection",
"=",
"new",
"static",
"(",
")",
";",
"foreach",
"(",
"$",
"json",
"->",
"patches",
"as",
"$",
"package",
"=>",
"$",
"patches",
")",
"{",
"foreach",
"(",
"$",
"patches",
"as",
"$",
"patch_json",
")",
"{",
"$",
"patch",
"=",
"Patch",
"::",
"fromJson",
"(",
"$",
"patch_json",
")",
";",
"$",
"collection",
"->",
"addPatch",
"(",
"$",
"patch",
")",
";",
"}",
"}",
"return",
"$",
"collection",
";",
"}"
] |
Create a PatchCollection from a serialized representation.
@param $json
A json_encode'd representation of a PatchCollection.
@return PatchCollection
A PatchCollection with all of the serialized patches included.
|
[
"Create",
"a",
"PatchCollection",
"from",
"a",
"serialized",
"representation",
"."
] |
7eda09d4049c62ad5750e4aadb8663db3dced384
|
https://github.com/cweagans/composer-patches/blob/7eda09d4049c62ad5750e4aadb8663db3dced384/src/PatchCollection.php#L54-L69
|
train
|
cweagans/composer-patches
|
src/Plugin/Patches.php
|
Patches.getPatchResolvers
|
public function getPatchResolvers()
{
$resolvers = [];
$plugin_manager = $this->composer->getPluginManager();
foreach ($plugin_manager->getPluginCapabilities(
'cweagans\Composer\Capability\ResolverProvider',
['composer' => $this->composer, 'io' => $this->io]
) as $capability) {
/** @var ResolverProvider $capability */
$newResolvers = $capability->getResolvers();
if (!is_array($newResolvers)) {
throw new \UnexpectedValueException(
'Plugin capability ' . get_class($capability) . ' failed to return an array from getResolvers().'
);
}
foreach ($newResolvers as $resolver) {
if (!$resolver instanceof ResolverBase) {
throw new \UnexpectedValueException(
'Plugin capability ' . get_class($capability) . ' returned an invalid value.'
);
}
}
$resolvers = array_merge($resolvers, $newResolvers);
}
return $resolvers;
}
|
php
|
public function getPatchResolvers()
{
$resolvers = [];
$plugin_manager = $this->composer->getPluginManager();
foreach ($plugin_manager->getPluginCapabilities(
'cweagans\Composer\Capability\ResolverProvider',
['composer' => $this->composer, 'io' => $this->io]
) as $capability) {
/** @var ResolverProvider $capability */
$newResolvers = $capability->getResolvers();
if (!is_array($newResolvers)) {
throw new \UnexpectedValueException(
'Plugin capability ' . get_class($capability) . ' failed to return an array from getResolvers().'
);
}
foreach ($newResolvers as $resolver) {
if (!$resolver instanceof ResolverBase) {
throw new \UnexpectedValueException(
'Plugin capability ' . get_class($capability) . ' returned an invalid value.'
);
}
}
$resolvers = array_merge($resolvers, $newResolvers);
}
return $resolvers;
}
|
[
"public",
"function",
"getPatchResolvers",
"(",
")",
"{",
"$",
"resolvers",
"=",
"[",
"]",
";",
"$",
"plugin_manager",
"=",
"$",
"this",
"->",
"composer",
"->",
"getPluginManager",
"(",
")",
";",
"foreach",
"(",
"$",
"plugin_manager",
"->",
"getPluginCapabilities",
"(",
"'cweagans\\Composer\\Capability\\ResolverProvider'",
",",
"[",
"'composer'",
"=>",
"$",
"this",
"->",
"composer",
",",
"'io'",
"=>",
"$",
"this",
"->",
"io",
"]",
")",
"as",
"$",
"capability",
")",
"{",
"/** @var ResolverProvider $capability */",
"$",
"newResolvers",
"=",
"$",
"capability",
"->",
"getResolvers",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"newResolvers",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Plugin capability '",
".",
"get_class",
"(",
"$",
"capability",
")",
".",
"' failed to return an array from getResolvers().'",
")",
";",
"}",
"foreach",
"(",
"$",
"newResolvers",
"as",
"$",
"resolver",
")",
"{",
"if",
"(",
"!",
"$",
"resolver",
"instanceof",
"ResolverBase",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Plugin capability '",
".",
"get_class",
"(",
"$",
"capability",
")",
".",
"' returned an invalid value.'",
")",
";",
"}",
"}",
"$",
"resolvers",
"=",
"array_merge",
"(",
"$",
"resolvers",
",",
"$",
"newResolvers",
")",
";",
"}",
"return",
"$",
"resolvers",
";",
"}"
] |
Gather a list of all patch resolvers from all enabled Composer plugins.
@return ResolverBase[]
A list of PatchResolvers to be run.
|
[
"Gather",
"a",
"list",
"of",
"all",
"patch",
"resolvers",
"from",
"all",
"enabled",
"Composer",
"plugins",
"."
] |
7eda09d4049c62ad5750e4aadb8663db3dced384
|
https://github.com/cweagans/composer-patches/blob/7eda09d4049c62ad5750e4aadb8663db3dced384/src/Plugin/Patches.php#L161-L187
|
train
|
cweagans/composer-patches
|
src/Plugin/Patches.php
|
Patches.resolvePatches
|
public function resolvePatches(PackageEvent $event)
{
// No need to resolve patches more than once.
if ($this->patchesResolved) {
return;
}
// Let each resolver discover patches and add them to the PatchCollection.
/** @var ResolverInterface $resolver */
foreach ($this->getPatchResolvers() as $resolver) {
if (!in_array(get_class($resolver), $this->getConfig('disable-resolvers'), true)) {
$resolver->resolve($this->patchCollection, $event);
} else {
if ($this->io->isVerbose()) {
$this->io->write('<info> - Skipping resolver ' . get_class($resolver) . '</info>');
}
}
}
// Make sure we only do this once.
$this->patchesResolved = true;
}
|
php
|
public function resolvePatches(PackageEvent $event)
{
// No need to resolve patches more than once.
if ($this->patchesResolved) {
return;
}
// Let each resolver discover patches and add them to the PatchCollection.
/** @var ResolverInterface $resolver */
foreach ($this->getPatchResolvers() as $resolver) {
if (!in_array(get_class($resolver), $this->getConfig('disable-resolvers'), true)) {
$resolver->resolve($this->patchCollection, $event);
} else {
if ($this->io->isVerbose()) {
$this->io->write('<info> - Skipping resolver ' . get_class($resolver) . '</info>');
}
}
}
// Make sure we only do this once.
$this->patchesResolved = true;
}
|
[
"public",
"function",
"resolvePatches",
"(",
"PackageEvent",
"$",
"event",
")",
"{",
"// No need to resolve patches more than once.",
"if",
"(",
"$",
"this",
"->",
"patchesResolved",
")",
"{",
"return",
";",
"}",
"// Let each resolver discover patches and add them to the PatchCollection.",
"/** @var ResolverInterface $resolver */",
"foreach",
"(",
"$",
"this",
"->",
"getPatchResolvers",
"(",
")",
"as",
"$",
"resolver",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"get_class",
"(",
"$",
"resolver",
")",
",",
"$",
"this",
"->",
"getConfig",
"(",
"'disable-resolvers'",
")",
",",
"true",
")",
")",
"{",
"$",
"resolver",
"->",
"resolve",
"(",
"$",
"this",
"->",
"patchCollection",
",",
"$",
"event",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"io",
"->",
"isVerbose",
"(",
")",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"write",
"(",
"'<info> - Skipping resolver '",
".",
"get_class",
"(",
"$",
"resolver",
")",
".",
"'</info>'",
")",
";",
"}",
"}",
"}",
"// Make sure we only do this once.",
"$",
"this",
"->",
"patchesResolved",
"=",
"true",
";",
"}"
] |
Gather patches that need to be applied to the current set of packages.
Note that this work is done unconditionally if this plugin is enabled,
even if patching is disabled in any way. The point where patches are applied
is where the work will be skipped. It's done this way to ensure that
patching can be disabled temporarily in a way that doesn't affect the
contents of composer.lock.
@param PackageEvent $event
The PackageEvent passed by Composer
|
[
"Gather",
"patches",
"that",
"need",
"to",
"be",
"applied",
"to",
"the",
"current",
"set",
"of",
"packages",
"."
] |
7eda09d4049c62ad5750e4aadb8663db3dced384
|
https://github.com/cweagans/composer-patches/blob/7eda09d4049c62ad5750e4aadb8663db3dced384/src/Plugin/Patches.php#L201-L222
|
train
|
cweagans/composer-patches
|
src/Plugin/Patches.php
|
Patches.checkPatches
|
public function checkPatches(Event $event)
{
if (!$this->isPatchingEnabled()) {
return;
}
try {
$repositoryManager = $this->composer->getRepositoryManager();
$localRepository = $repositoryManager->getLocalRepository();
$installationManager = $this->composer->getInstallationManager();
$packages = $localRepository->getPackages();
$tmp_patches = $this->grabPatches();
foreach ($packages as $package) {
$extra = $package->getExtra();
if (isset($extra['patches'])) {
$this->installedPatches[$package->getName()] = $extra['patches'];
}
$patches = isset($extra['patches']) ? $extra['patches'] : array();
$tmp_patches = Util::arrayMergeRecursiveDistinct($tmp_patches, $patches);
}
if ($tmp_patches === false) {
$this->io->write('<info>No patches supplied.</info>');
return;
}
// Remove packages for which the patch set has changed.
foreach ($packages as $package) {
if (!($package instanceof AliasPackage)) {
$package_name = $package->getName();
$extra = $package->getExtra();
$has_patches = isset($tmp_patches[$package_name]);
$has_applied_patches = isset($extra['patches_applied']);
if (($has_patches && !$has_applied_patches)
|| (!$has_patches && $has_applied_patches)
|| ($has_patches && $has_applied_patches &&
$tmp_patches[$package_name] !== $extra['patches_applied'])) {
$uninstallOperation = new UninstallOperation(
$package,
'Removing package so it can be re-installed and re-patched.'
);
$this->io->write('<info>Removing package ' .
$package_name .
' so that it can be re-installed and re-patched.</info>');
$installationManager->uninstall($localRepository, $uninstallOperation);
}
}
}
} catch (\LogicException $e) {
// If the Locker isn't available, then we don't need to do this.
// It's the first time packages have been installed.
return;
}
}
|
php
|
public function checkPatches(Event $event)
{
if (!$this->isPatchingEnabled()) {
return;
}
try {
$repositoryManager = $this->composer->getRepositoryManager();
$localRepository = $repositoryManager->getLocalRepository();
$installationManager = $this->composer->getInstallationManager();
$packages = $localRepository->getPackages();
$tmp_patches = $this->grabPatches();
foreach ($packages as $package) {
$extra = $package->getExtra();
if (isset($extra['patches'])) {
$this->installedPatches[$package->getName()] = $extra['patches'];
}
$patches = isset($extra['patches']) ? $extra['patches'] : array();
$tmp_patches = Util::arrayMergeRecursiveDistinct($tmp_patches, $patches);
}
if ($tmp_patches === false) {
$this->io->write('<info>No patches supplied.</info>');
return;
}
// Remove packages for which the patch set has changed.
foreach ($packages as $package) {
if (!($package instanceof AliasPackage)) {
$package_name = $package->getName();
$extra = $package->getExtra();
$has_patches = isset($tmp_patches[$package_name]);
$has_applied_patches = isset($extra['patches_applied']);
if (($has_patches && !$has_applied_patches)
|| (!$has_patches && $has_applied_patches)
|| ($has_patches && $has_applied_patches &&
$tmp_patches[$package_name] !== $extra['patches_applied'])) {
$uninstallOperation = new UninstallOperation(
$package,
'Removing package so it can be re-installed and re-patched.'
);
$this->io->write('<info>Removing package ' .
$package_name .
' so that it can be re-installed and re-patched.</info>');
$installationManager->uninstall($localRepository, $uninstallOperation);
}
}
}
} catch (\LogicException $e) {
// If the Locker isn't available, then we don't need to do this.
// It's the first time packages have been installed.
return;
}
}
|
[
"public",
"function",
"checkPatches",
"(",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isPatchingEnabled",
"(",
")",
")",
"{",
"return",
";",
"}",
"try",
"{",
"$",
"repositoryManager",
"=",
"$",
"this",
"->",
"composer",
"->",
"getRepositoryManager",
"(",
")",
";",
"$",
"localRepository",
"=",
"$",
"repositoryManager",
"->",
"getLocalRepository",
"(",
")",
";",
"$",
"installationManager",
"=",
"$",
"this",
"->",
"composer",
"->",
"getInstallationManager",
"(",
")",
";",
"$",
"packages",
"=",
"$",
"localRepository",
"->",
"getPackages",
"(",
")",
";",
"$",
"tmp_patches",
"=",
"$",
"this",
"->",
"grabPatches",
"(",
")",
";",
"foreach",
"(",
"$",
"packages",
"as",
"$",
"package",
")",
"{",
"$",
"extra",
"=",
"$",
"package",
"->",
"getExtra",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"extra",
"[",
"'patches'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"installedPatches",
"[",
"$",
"package",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"extra",
"[",
"'patches'",
"]",
";",
"}",
"$",
"patches",
"=",
"isset",
"(",
"$",
"extra",
"[",
"'patches'",
"]",
")",
"?",
"$",
"extra",
"[",
"'patches'",
"]",
":",
"array",
"(",
")",
";",
"$",
"tmp_patches",
"=",
"Util",
"::",
"arrayMergeRecursiveDistinct",
"(",
"$",
"tmp_patches",
",",
"$",
"patches",
")",
";",
"}",
"if",
"(",
"$",
"tmp_patches",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"write",
"(",
"'<info>No patches supplied.</info>'",
")",
";",
"return",
";",
"}",
"// Remove packages for which the patch set has changed.",
"foreach",
"(",
"$",
"packages",
"as",
"$",
"package",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"package",
"instanceof",
"AliasPackage",
")",
")",
"{",
"$",
"package_name",
"=",
"$",
"package",
"->",
"getName",
"(",
")",
";",
"$",
"extra",
"=",
"$",
"package",
"->",
"getExtra",
"(",
")",
";",
"$",
"has_patches",
"=",
"isset",
"(",
"$",
"tmp_patches",
"[",
"$",
"package_name",
"]",
")",
";",
"$",
"has_applied_patches",
"=",
"isset",
"(",
"$",
"extra",
"[",
"'patches_applied'",
"]",
")",
";",
"if",
"(",
"(",
"$",
"has_patches",
"&&",
"!",
"$",
"has_applied_patches",
")",
"||",
"(",
"!",
"$",
"has_patches",
"&&",
"$",
"has_applied_patches",
")",
"||",
"(",
"$",
"has_patches",
"&&",
"$",
"has_applied_patches",
"&&",
"$",
"tmp_patches",
"[",
"$",
"package_name",
"]",
"!==",
"$",
"extra",
"[",
"'patches_applied'",
"]",
")",
")",
"{",
"$",
"uninstallOperation",
"=",
"new",
"UninstallOperation",
"(",
"$",
"package",
",",
"'Removing package so it can be re-installed and re-patched.'",
")",
";",
"$",
"this",
"->",
"io",
"->",
"write",
"(",
"'<info>Removing package '",
".",
"$",
"package_name",
".",
"' so that it can be re-installed and re-patched.</info>'",
")",
";",
"$",
"installationManager",
"->",
"uninstall",
"(",
"$",
"localRepository",
",",
"$",
"uninstallOperation",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"\\",
"LogicException",
"$",
"e",
")",
"{",
"// If the Locker isn't available, then we don't need to do this.",
"// It's the first time packages have been installed.",
"return",
";",
"}",
"}"
] |
Before running composer install,
@param Event $event
|
[
"Before",
"running",
"composer",
"install"
] |
7eda09d4049c62ad5750e4aadb8663db3dced384
|
https://github.com/cweagans/composer-patches/blob/7eda09d4049c62ad5750e4aadb8663db3dced384/src/Plugin/Patches.php#L228-L282
|
train
|
cweagans/composer-patches
|
src/Plugin/Patches.php
|
Patches.getPackageFromOperation
|
protected function getPackageFromOperation(OperationInterface $operation)
{
if ($operation instanceof InstallOperation) {
$package = $operation->getPackage();
} elseif ($operation instanceof UpdateOperation) {
$package = $operation->getTargetPackage();
} else {
throw new \Exception('Unknown operation: ' . get_class($operation));
}
return $package;
}
|
php
|
protected function getPackageFromOperation(OperationInterface $operation)
{
if ($operation instanceof InstallOperation) {
$package = $operation->getPackage();
} elseif ($operation instanceof UpdateOperation) {
$package = $operation->getTargetPackage();
} else {
throw new \Exception('Unknown operation: ' . get_class($operation));
}
return $package;
}
|
[
"protected",
"function",
"getPackageFromOperation",
"(",
"OperationInterface",
"$",
"operation",
")",
"{",
"if",
"(",
"$",
"operation",
"instanceof",
"InstallOperation",
")",
"{",
"$",
"package",
"=",
"$",
"operation",
"->",
"getPackage",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"operation",
"instanceof",
"UpdateOperation",
")",
"{",
"$",
"package",
"=",
"$",
"operation",
"->",
"getTargetPackage",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Unknown operation: '",
".",
"get_class",
"(",
"$",
"operation",
")",
")",
";",
"}",
"return",
"$",
"package",
";",
"}"
] |
Get a Package object from an OperationInterface object.
@param OperationInterface $operation
@return PackageInterface
@throws \Exception
|
[
"Get",
"a",
"Package",
"object",
"from",
"an",
"OperationInterface",
"object",
"."
] |
7eda09d4049c62ad5750e4aadb8663db3dced384
|
https://github.com/cweagans/composer-patches/blob/7eda09d4049c62ad5750e4aadb8663db3dced384/src/Plugin/Patches.php#L352-L363
|
train
|
cweagans/composer-patches
|
src/Plugin/Patches.php
|
Patches.getAndApplyPatch
|
protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, $patch_url)
{
// Local patch file.
if (file_exists($patch_url)) {
$filename = realpath($patch_url);
} else {
// Generate random (but not cryptographically so) filename.
$filename = uniqid(sys_get_temp_dir() . '/') . ".patch";
// Download file from remote filesystem to this location.
$hostname = parse_url($patch_url, PHP_URL_HOST);
$downloader->copy($hostname, $patch_url, $filename, false);
}
// Modified from drush6:make.project.inc
$patched = false;
// The order here is intentional. p1 is most likely to apply with git apply.
// p0 is next likely. p2 is extremely unlikely, but for some special cases,
// it might be useful. p4 is useful for Magento 2 patches
$patch_levels = $this->getConfig('patch-levels');
foreach ($patch_levels as $patch_level) {
if ($this->io->isVerbose()) {
$comment = 'Testing ability to patch with git apply.';
$comment .= ' This command may produce errors that can be safely ignored.';
$this->io->write('<comment>' . $comment . '</comment>');
}
$checked = $this->executeCommand(
'git -C %s apply --check -v %s %s',
$install_path,
$patch_level,
$filename
);
$output = $this->executor->getErrorOutput();
if (substr($output, 0, 7) === 'Skipped') {
// Git will indicate success but silently skip patches in some scenarios.
//
// @see https://github.com/cweagans/composer-patches/pull/165
$checked = false;
}
if ($checked) {
// Apply the first successful style.
$patched = $this->executeCommand(
'git -C %s apply %s %s',
$install_path,
$patch_level,
$filename
);
break;
}
}
// In some rare cases, git will fail to apply a patch, fallback to using
// the 'patch' command.
if (!$patched) {
foreach ($patch_levels as $patch_level) {
// --no-backup-if-mismatch here is a hack that fixes some
// differences between how patch works on windows and unix.
if ($patched = $this->executeCommand(
"patch %s --no-backup-if-mismatch -d %s < %s",
$patch_level,
$install_path,
$filename
)
) {
break;
}
}
}
// Clean up the temporary patch file.
if (isset($hostname)) {
unlink($filename);
}
// If the patch *still* isn't applied, then give up and throw an Exception.
// Otherwise, let the user know it worked.
if (!$patched) {
throw new \Exception("Cannot apply patch $patch_url");
}
}
|
php
|
protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, $patch_url)
{
// Local patch file.
if (file_exists($patch_url)) {
$filename = realpath($patch_url);
} else {
// Generate random (but not cryptographically so) filename.
$filename = uniqid(sys_get_temp_dir() . '/') . ".patch";
// Download file from remote filesystem to this location.
$hostname = parse_url($patch_url, PHP_URL_HOST);
$downloader->copy($hostname, $patch_url, $filename, false);
}
// Modified from drush6:make.project.inc
$patched = false;
// The order here is intentional. p1 is most likely to apply with git apply.
// p0 is next likely. p2 is extremely unlikely, but for some special cases,
// it might be useful. p4 is useful for Magento 2 patches
$patch_levels = $this->getConfig('patch-levels');
foreach ($patch_levels as $patch_level) {
if ($this->io->isVerbose()) {
$comment = 'Testing ability to patch with git apply.';
$comment .= ' This command may produce errors that can be safely ignored.';
$this->io->write('<comment>' . $comment . '</comment>');
}
$checked = $this->executeCommand(
'git -C %s apply --check -v %s %s',
$install_path,
$patch_level,
$filename
);
$output = $this->executor->getErrorOutput();
if (substr($output, 0, 7) === 'Skipped') {
// Git will indicate success but silently skip patches in some scenarios.
//
// @see https://github.com/cweagans/composer-patches/pull/165
$checked = false;
}
if ($checked) {
// Apply the first successful style.
$patched = $this->executeCommand(
'git -C %s apply %s %s',
$install_path,
$patch_level,
$filename
);
break;
}
}
// In some rare cases, git will fail to apply a patch, fallback to using
// the 'patch' command.
if (!$patched) {
foreach ($patch_levels as $patch_level) {
// --no-backup-if-mismatch here is a hack that fixes some
// differences between how patch works on windows and unix.
if ($patched = $this->executeCommand(
"patch %s --no-backup-if-mismatch -d %s < %s",
$patch_level,
$install_path,
$filename
)
) {
break;
}
}
}
// Clean up the temporary patch file.
if (isset($hostname)) {
unlink($filename);
}
// If the patch *still* isn't applied, then give up and throw an Exception.
// Otherwise, let the user know it worked.
if (!$patched) {
throw new \Exception("Cannot apply patch $patch_url");
}
}
|
[
"protected",
"function",
"getAndApplyPatch",
"(",
"RemoteFilesystem",
"$",
"downloader",
",",
"$",
"install_path",
",",
"$",
"patch_url",
")",
"{",
"// Local patch file.",
"if",
"(",
"file_exists",
"(",
"$",
"patch_url",
")",
")",
"{",
"$",
"filename",
"=",
"realpath",
"(",
"$",
"patch_url",
")",
";",
"}",
"else",
"{",
"// Generate random (but not cryptographically so) filename.",
"$",
"filename",
"=",
"uniqid",
"(",
"sys_get_temp_dir",
"(",
")",
".",
"'/'",
")",
".",
"\".patch\"",
";",
"// Download file from remote filesystem to this location.",
"$",
"hostname",
"=",
"parse_url",
"(",
"$",
"patch_url",
",",
"PHP_URL_HOST",
")",
";",
"$",
"downloader",
"->",
"copy",
"(",
"$",
"hostname",
",",
"$",
"patch_url",
",",
"$",
"filename",
",",
"false",
")",
";",
"}",
"// Modified from drush6:make.project.inc",
"$",
"patched",
"=",
"false",
";",
"// The order here is intentional. p1 is most likely to apply with git apply.",
"// p0 is next likely. p2 is extremely unlikely, but for some special cases,",
"// it might be useful. p4 is useful for Magento 2 patches",
"$",
"patch_levels",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'patch-levels'",
")",
";",
"foreach",
"(",
"$",
"patch_levels",
"as",
"$",
"patch_level",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"io",
"->",
"isVerbose",
"(",
")",
")",
"{",
"$",
"comment",
"=",
"'Testing ability to patch with git apply.'",
";",
"$",
"comment",
".=",
"' This command may produce errors that can be safely ignored.'",
";",
"$",
"this",
"->",
"io",
"->",
"write",
"(",
"'<comment>'",
".",
"$",
"comment",
".",
"'</comment>'",
")",
";",
"}",
"$",
"checked",
"=",
"$",
"this",
"->",
"executeCommand",
"(",
"'git -C %s apply --check -v %s %s'",
",",
"$",
"install_path",
",",
"$",
"patch_level",
",",
"$",
"filename",
")",
";",
"$",
"output",
"=",
"$",
"this",
"->",
"executor",
"->",
"getErrorOutput",
"(",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"output",
",",
"0",
",",
"7",
")",
"===",
"'Skipped'",
")",
"{",
"// Git will indicate success but silently skip patches in some scenarios.",
"//",
"// @see https://github.com/cweagans/composer-patches/pull/165",
"$",
"checked",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"checked",
")",
"{",
"// Apply the first successful style.",
"$",
"patched",
"=",
"$",
"this",
"->",
"executeCommand",
"(",
"'git -C %s apply %s %s'",
",",
"$",
"install_path",
",",
"$",
"patch_level",
",",
"$",
"filename",
")",
";",
"break",
";",
"}",
"}",
"// In some rare cases, git will fail to apply a patch, fallback to using",
"// the 'patch' command.",
"if",
"(",
"!",
"$",
"patched",
")",
"{",
"foreach",
"(",
"$",
"patch_levels",
"as",
"$",
"patch_level",
")",
"{",
"// --no-backup-if-mismatch here is a hack that fixes some",
"// differences between how patch works on windows and unix.",
"if",
"(",
"$",
"patched",
"=",
"$",
"this",
"->",
"executeCommand",
"(",
"\"patch %s --no-backup-if-mismatch -d %s < %s\"",
",",
"$",
"patch_level",
",",
"$",
"install_path",
",",
"$",
"filename",
")",
")",
"{",
"break",
";",
"}",
"}",
"}",
"// Clean up the temporary patch file.",
"if",
"(",
"isset",
"(",
"$",
"hostname",
")",
")",
"{",
"unlink",
"(",
"$",
"filename",
")",
";",
"}",
"// If the patch *still* isn't applied, then give up and throw an Exception.",
"// Otherwise, let the user know it worked.",
"if",
"(",
"!",
"$",
"patched",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Cannot apply patch $patch_url\"",
")",
";",
"}",
"}"
] |
Apply a patch on code in the specified directory.
@param RemoteFilesystem $downloader
@param $install_path
@param $patch_url
@throws \Exception
|
[
"Apply",
"a",
"patch",
"on",
"code",
"in",
"the",
"specified",
"directory",
"."
] |
7eda09d4049c62ad5750e4aadb8663db3dced384
|
https://github.com/cweagans/composer-patches/blob/7eda09d4049c62ad5750e4aadb8663db3dced384/src/Plugin/Patches.php#L373-L452
|
train
|
cweagans/composer-patches
|
src/Plugin/Patches.php
|
Patches.isPatchingEnabled
|
protected function isPatchingEnabled()
{
$enabled = true;
$has_no_patches = empty($extra['patches']);
$has_no_patches_file = ($this->getConfig('patches-file') === '');
$patching_disabled = $this->getConfig('disable-patching');
if ($patching_disabled || !($has_no_patches && $has_no_patches_file)) {
$enabled = false;
}
return $enabled;
}
|
php
|
protected function isPatchingEnabled()
{
$enabled = true;
$has_no_patches = empty($extra['patches']);
$has_no_patches_file = ($this->getConfig('patches-file') === '');
$patching_disabled = $this->getConfig('disable-patching');
if ($patching_disabled || !($has_no_patches && $has_no_patches_file)) {
$enabled = false;
}
return $enabled;
}
|
[
"protected",
"function",
"isPatchingEnabled",
"(",
")",
"{",
"$",
"enabled",
"=",
"true",
";",
"$",
"has_no_patches",
"=",
"empty",
"(",
"$",
"extra",
"[",
"'patches'",
"]",
")",
";",
"$",
"has_no_patches_file",
"=",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'patches-file'",
")",
"===",
"''",
")",
";",
"$",
"patching_disabled",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'disable-patching'",
")",
";",
"if",
"(",
"$",
"patching_disabled",
"||",
"!",
"(",
"$",
"has_no_patches",
"&&",
"$",
"has_no_patches_file",
")",
")",
"{",
"$",
"enabled",
"=",
"false",
";",
"}",
"return",
"$",
"enabled",
";",
"}"
] |
Checks if the root package enables patching.
@return bool
Whether patching is enabled. Defaults to true.
|
[
"Checks",
"if",
"the",
"root",
"package",
"enables",
"patching",
"."
] |
7eda09d4049c62ad5750e4aadb8663db3dced384
|
https://github.com/cweagans/composer-patches/blob/7eda09d4049c62ad5750e4aadb8663db3dced384/src/Plugin/Patches.php#L460-L473
|
train
|
cweagans/composer-patches
|
src/Patch.php
|
Patch.fromJson
|
public static function fromJson($json)
{
if (!is_object($json)) {
$json = json_decode($json);
}
$properties = ['package', 'description', 'url', 'sha1', 'depth'];
$patch = new static();
foreach ($properties as $property) {
if (isset($json->{$property})) {
$patch->{$property} = $json->{$property};
}
}
return $patch;
}
|
php
|
public static function fromJson($json)
{
if (!is_object($json)) {
$json = json_decode($json);
}
$properties = ['package', 'description', 'url', 'sha1', 'depth'];
$patch = new static();
foreach ($properties as $property) {
if (isset($json->{$property})) {
$patch->{$property} = $json->{$property};
}
}
return $patch;
}
|
[
"public",
"static",
"function",
"fromJson",
"(",
"$",
"json",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"json",
")",
")",
"{",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"json",
")",
";",
"}",
"$",
"properties",
"=",
"[",
"'package'",
",",
"'description'",
",",
"'url'",
",",
"'sha1'",
",",
"'depth'",
"]",
";",
"$",
"patch",
"=",
"new",
"static",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"json",
"->",
"{",
"$",
"property",
"}",
")",
")",
"{",
"$",
"patch",
"->",
"{",
"$",
"property",
"}",
"=",
"$",
"json",
"->",
"{",
"$",
"property",
"}",
";",
"}",
"}",
"return",
"$",
"patch",
";",
"}"
] |
Create a Patch from a serialized representation.
@param $json
A json_encode'd representation of a Patch.
@return Patch
A Patch with all of the serialized properties set.
|
[
"Create",
"a",
"Patch",
"from",
"a",
"serialized",
"representation",
"."
] |
7eda09d4049c62ad5750e4aadb8663db3dced384
|
https://github.com/cweagans/composer-patches/blob/7eda09d4049c62ad5750e4aadb8663db3dced384/src/Patch.php#L51-L66
|
train
|
cweagans/composer-patches
|
src/Resolvers/ResolverBase.php
|
ResolverBase.findPatchesInJson
|
public function findPatchesInJson($patches)
{
// Given an array of patch data (pulled directly from the root composer.json
// or a patches file), figure out what patch format each package is using and
// marshall everything into Patch objects.
foreach ($patches as $package => $patch_defs) {
if (isset($patch_defs[0]) && is_array($patch_defs[0])) {
$this->io->write("<info>Using expanded definition format for package {$package}</info>");
foreach ($patch_defs as $index => $def) {
$patch = new Patch();
$patch->package = $package;
$patch->url = $def["url"];
$patch->description = $def["description"];
$patches[$package][$index] = $patch;
}
} else {
$this->io->write("<info>Using compact definition format for package {$package}</info>");
$temporary_patch_list = [];
foreach ($patch_defs as $description => $url) {
$patch = new Patch();
$patch->package = $package;
$patch->url = $url;
$patch->description = $description;
$temporary_patch_list[] = $patch;
}
$patches[$package] = $temporary_patch_list;
}
}
return $patches;
}
|
php
|
public function findPatchesInJson($patches)
{
// Given an array of patch data (pulled directly from the root composer.json
// or a patches file), figure out what patch format each package is using and
// marshall everything into Patch objects.
foreach ($patches as $package => $patch_defs) {
if (isset($patch_defs[0]) && is_array($patch_defs[0])) {
$this->io->write("<info>Using expanded definition format for package {$package}</info>");
foreach ($patch_defs as $index => $def) {
$patch = new Patch();
$patch->package = $package;
$patch->url = $def["url"];
$patch->description = $def["description"];
$patches[$package][$index] = $patch;
}
} else {
$this->io->write("<info>Using compact definition format for package {$package}</info>");
$temporary_patch_list = [];
foreach ($patch_defs as $description => $url) {
$patch = new Patch();
$patch->package = $package;
$patch->url = $url;
$patch->description = $description;
$temporary_patch_list[] = $patch;
}
$patches[$package] = $temporary_patch_list;
}
}
return $patches;
}
|
[
"public",
"function",
"findPatchesInJson",
"(",
"$",
"patches",
")",
"{",
"// Given an array of patch data (pulled directly from the root composer.json",
"// or a patches file), figure out what patch format each package is using and",
"// marshall everything into Patch objects.",
"foreach",
"(",
"$",
"patches",
"as",
"$",
"package",
"=>",
"$",
"patch_defs",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"patch_defs",
"[",
"0",
"]",
")",
"&&",
"is_array",
"(",
"$",
"patch_defs",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"write",
"(",
"\"<info>Using expanded definition format for package {$package}</info>\"",
")",
";",
"foreach",
"(",
"$",
"patch_defs",
"as",
"$",
"index",
"=>",
"$",
"def",
")",
"{",
"$",
"patch",
"=",
"new",
"Patch",
"(",
")",
";",
"$",
"patch",
"->",
"package",
"=",
"$",
"package",
";",
"$",
"patch",
"->",
"url",
"=",
"$",
"def",
"[",
"\"url\"",
"]",
";",
"$",
"patch",
"->",
"description",
"=",
"$",
"def",
"[",
"\"description\"",
"]",
";",
"$",
"patches",
"[",
"$",
"package",
"]",
"[",
"$",
"index",
"]",
"=",
"$",
"patch",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"io",
"->",
"write",
"(",
"\"<info>Using compact definition format for package {$package}</info>\"",
")",
";",
"$",
"temporary_patch_list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"patch_defs",
"as",
"$",
"description",
"=>",
"$",
"url",
")",
"{",
"$",
"patch",
"=",
"new",
"Patch",
"(",
")",
";",
"$",
"patch",
"->",
"package",
"=",
"$",
"package",
";",
"$",
"patch",
"->",
"url",
"=",
"$",
"url",
";",
"$",
"patch",
"->",
"description",
"=",
"$",
"description",
";",
"$",
"temporary_patch_list",
"[",
"]",
"=",
"$",
"patch",
";",
"}",
"$",
"patches",
"[",
"$",
"package",
"]",
"=",
"$",
"temporary_patch_list",
";",
"}",
"}",
"return",
"$",
"patches",
";",
"}"
] |
Handles the different patch definition formats and returns a list of Patches.
@param array $patches
An array of patch defs from composer.json or a patches file.
@return array $patches
An array of Patch objects grouped by package name.
|
[
"Handles",
"the",
"different",
"patch",
"definition",
"formats",
"and",
"returns",
"a",
"list",
"of",
"Patches",
"."
] |
7eda09d4049c62ad5750e4aadb8663db3dced384
|
https://github.com/cweagans/composer-patches/blob/7eda09d4049c62ad5750e4aadb8663db3dced384/src/Resolvers/ResolverBase.php#L56-L92
|
train
|
cweagans/composer-patches
|
src/Resolvers/PatchesFile.php
|
PatchesFile.readPatchesFile
|
protected function readPatchesFile($patches_file)
{
$patches = file_get_contents($patches_file);
$patches = json_decode($patches, true);
// First, check for JSON syntax issues.
$json_error = json_last_error_msg();
if ($json_error !== "No error") {
throw new \InvalidArgumentException($json_error);
}
// Next, make sure there is a patches key in the file.
if (!array_key_exists('patches', $patches)) {
throw new \InvalidArgumentException('No patches found.');
}
// If nothing is wrong at this point, we can return the list of patches.
return $patches['patches'];
}
|
php
|
protected function readPatchesFile($patches_file)
{
$patches = file_get_contents($patches_file);
$patches = json_decode($patches, true);
// First, check for JSON syntax issues.
$json_error = json_last_error_msg();
if ($json_error !== "No error") {
throw new \InvalidArgumentException($json_error);
}
// Next, make sure there is a patches key in the file.
if (!array_key_exists('patches', $patches)) {
throw new \InvalidArgumentException('No patches found.');
}
// If nothing is wrong at this point, we can return the list of patches.
return $patches['patches'];
}
|
[
"protected",
"function",
"readPatchesFile",
"(",
"$",
"patches_file",
")",
"{",
"$",
"patches",
"=",
"file_get_contents",
"(",
"$",
"patches_file",
")",
";",
"$",
"patches",
"=",
"json_decode",
"(",
"$",
"patches",
",",
"true",
")",
";",
"// First, check for JSON syntax issues.",
"$",
"json_error",
"=",
"json_last_error_msg",
"(",
")",
";",
"if",
"(",
"$",
"json_error",
"!==",
"\"No error\"",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"json_error",
")",
";",
"}",
"// Next, make sure there is a patches key in the file.",
"if",
"(",
"!",
"array_key_exists",
"(",
"'patches'",
",",
"$",
"patches",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'No patches found.'",
")",
";",
"}",
"// If nothing is wrong at this point, we can return the list of patches.",
"return",
"$",
"patches",
"[",
"'patches'",
"]",
";",
"}"
] |
Read a patches file.
@param $patches_file
A URI to a file. Can be anything accepted by file_get_contents().
@return array
A list of patches.
@throws \InvalidArgumentException
|
[
"Read",
"a",
"patches",
"file",
"."
] |
7eda09d4049c62ad5750e4aadb8663db3dced384
|
https://github.com/cweagans/composer-patches/blob/7eda09d4049c62ad5750e4aadb8663db3dced384/src/Resolvers/PatchesFile.php#L53-L71
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.interval
|
public static function interval(int $interval, AsyncSchedulerInterface $scheduler = null): IntervalObservable
{
return new IntervalObservable($interval, $scheduler ?: Scheduler::getAsync());
}
|
php
|
public static function interval(int $interval, AsyncSchedulerInterface $scheduler = null): IntervalObservable
{
return new IntervalObservable($interval, $scheduler ?: Scheduler::getAsync());
}
|
[
"public",
"static",
"function",
"interval",
"(",
"int",
"$",
"interval",
",",
"AsyncSchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"IntervalObservable",
"{",
"return",
"new",
"IntervalObservable",
"(",
"$",
"interval",
",",
"$",
"scheduler",
"?",
":",
"Scheduler",
"::",
"getAsync",
"(",
")",
")",
";",
"}"
] |
Returns an Observable that emits an infinite sequence of ascending integers starting at 0, with a constant interval of time of your choosing between emissions.
@param $interval int Period for producing the values in the resulting sequence (specified as an integer denoting milliseconds).
@param null|AsyncSchedulerInterface|SchedulerInterface $scheduler
@return IntervalObservable An observable sequence that produces a value after each period.
@demo interval/interval.php
@operator
@reactivex interval
|
[
"Returns",
"an",
"Observable",
"that",
"emits",
"an",
"infinite",
"sequence",
"of",
"ascending",
"integers",
"starting",
"at",
"0",
"with",
"a",
"constant",
"interval",
"of",
"time",
"of",
"your",
"choosing",
"between",
"emissions",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L170-L173
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.of
|
public static function of($value, SchedulerInterface $scheduler = null): ReturnObservable
{
return new ReturnObservable($value, $scheduler ?: Scheduler::getDefault());
}
|
php
|
public static function of($value, SchedulerInterface $scheduler = null): ReturnObservable
{
return new ReturnObservable($value, $scheduler ?: Scheduler::getDefault());
}
|
[
"public",
"static",
"function",
"of",
"(",
"$",
"value",
",",
"SchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"ReturnObservable",
"{",
"return",
"new",
"ReturnObservable",
"(",
"$",
"value",
",",
"$",
"scheduler",
"?",
":",
"Scheduler",
"::",
"getDefault",
"(",
")",
")",
";",
"}"
] |
Returns an observable sequence that contains a single element.
@param mixed $value Single element in the resulting observable sequence.
@param SchedulerInterface $scheduler
@return ReturnObservable An observable sequence with the single element.
@demo of/of.php
@operator
@reactivex just
|
[
"Returns",
"an",
"observable",
"sequence",
"that",
"contains",
"a",
"single",
"element",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L186-L189
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.error
|
public static function error(\Throwable $error, SchedulerInterface $scheduler = null): ErrorObservable
{
return new ErrorObservable($error, $scheduler ?: Scheduler::getImmediate());
}
|
php
|
public static function error(\Throwable $error, SchedulerInterface $scheduler = null): ErrorObservable
{
return new ErrorObservable($error, $scheduler ?: Scheduler::getImmediate());
}
|
[
"public",
"static",
"function",
"error",
"(",
"\\",
"Throwable",
"$",
"error",
",",
"SchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"ErrorObservable",
"{",
"return",
"new",
"ErrorObservable",
"(",
"$",
"error",
",",
"$",
"scheduler",
"?",
":",
"Scheduler",
"::",
"getImmediate",
"(",
")",
")",
";",
"}"
] |
Returns an observable sequence that terminates with an exception.
@param \Throwable $error
@param SchedulerInterface $scheduler
@return ErrorObservable The observable sequence that terminates exceptionally with the specified exception object.
@demo error-observable/error-observable.php
@operator
@reactivex empty-never-throw
|
[
"Returns",
"an",
"observable",
"sequence",
"that",
"terminates",
"with",
"an",
"exception",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L256-L259
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.merge
|
public function merge(ObservableInterface $otherObservable): Observable
{
return (new AnonymousObservable(function (ObserverInterface $observer) use ($otherObservable) {
$observer->onNext($this);
$observer->onNext($otherObservable);
$observer->onCompleted();
}))->mergeAll();
}
|
php
|
public function merge(ObservableInterface $otherObservable): Observable
{
return (new AnonymousObservable(function (ObserverInterface $observer) use ($otherObservable) {
$observer->onNext($this);
$observer->onNext($otherObservable);
$observer->onCompleted();
}))->mergeAll();
}
|
[
"public",
"function",
"merge",
"(",
"ObservableInterface",
"$",
"otherObservable",
")",
":",
"Observable",
"{",
"return",
"(",
"new",
"AnonymousObservable",
"(",
"function",
"(",
"ObserverInterface",
"$",
"observer",
")",
"use",
"(",
"$",
"otherObservable",
")",
"{",
"$",
"observer",
"->",
"onNext",
"(",
"$",
"this",
")",
";",
"$",
"observer",
"->",
"onNext",
"(",
"$",
"otherObservable",
")",
";",
"$",
"observer",
"->",
"onCompleted",
"(",
")",
";",
"}",
")",
")",
"->",
"mergeAll",
"(",
")",
";",
"}"
] |
Combine an Observable together with another Observable by merging their emissions into a single Observable.
@param ObservableInterface $otherObservable
@return Observable
@demo merge/merge.php
@operator
@reactivex merge
|
[
"Combine",
"an",
"Observable",
"together",
"with",
"another",
"Observable",
"by",
"merging",
"their",
"emissions",
"into",
"a",
"single",
"Observable",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L271-L278
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.fromIterator
|
public static function fromIterator(\Iterator $iterator, SchedulerInterface $scheduler = null): IteratorObservable
{
return new IteratorObservable($iterator, $scheduler ?: Scheduler::getDefault());
}
|
php
|
public static function fromIterator(\Iterator $iterator, SchedulerInterface $scheduler = null): IteratorObservable
{
return new IteratorObservable($iterator, $scheduler ?: Scheduler::getDefault());
}
|
[
"public",
"static",
"function",
"fromIterator",
"(",
"\\",
"Iterator",
"$",
"iterator",
",",
"SchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"IteratorObservable",
"{",
"return",
"new",
"IteratorObservable",
"(",
"$",
"iterator",
",",
"$",
"scheduler",
"?",
":",
"Scheduler",
"::",
"getDefault",
"(",
")",
")",
";",
"}"
] |
Converts an Iterator into an observable sequence
@param \Iterator $iterator
@param SchedulerInterface $scheduler
@return IteratorObservable
@demo iterator/iterator.php
@operator
@reactivex from
|
[
"Converts",
"an",
"Iterator",
"into",
"an",
"observable",
"sequence"
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L323-L326
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.range
|
public static function range(int $start, int $count, SchedulerInterface $scheduler = null): RangeObservable
{
return new RangeObservable($start, $count, $scheduler ?: Scheduler::getDefault());
}
|
php
|
public static function range(int $start, int $count, SchedulerInterface $scheduler = null): RangeObservable
{
return new RangeObservable($start, $count, $scheduler ?: Scheduler::getDefault());
}
|
[
"public",
"static",
"function",
"range",
"(",
"int",
"$",
"start",
",",
"int",
"$",
"count",
",",
"SchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"RangeObservable",
"{",
"return",
"new",
"RangeObservable",
"(",
"$",
"start",
",",
"$",
"count",
",",
"$",
"scheduler",
"?",
":",
"Scheduler",
"::",
"getDefault",
"(",
")",
")",
";",
"}"
] |
Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to
send out observer messages.
@param $start
@param $count
@param SchedulerInterface $scheduler
@return RangeObservable
@throws \InvalidArgumentException
@demo range/range.php
@operator
@reactivex range
|
[
"Generates",
"an",
"observable",
"sequence",
"of",
"integral",
"numbers",
"within",
"a",
"specified",
"range",
"using",
"the",
"specified",
"scheduler",
"to",
"send",
"out",
"observer",
"messages",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L361-L364
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.mapWithIndex
|
public function mapWithIndex(callable $selector): Observable
{
$index = 0;
return $this->map(function ($value) use ($selector, &$index) {
return $selector($index++, $value);
});
}
|
php
|
public function mapWithIndex(callable $selector): Observable
{
$index = 0;
return $this->map(function ($value) use ($selector, &$index) {
return $selector($index++, $value);
});
}
|
[
"public",
"function",
"mapWithIndex",
"(",
"callable",
"$",
"selector",
")",
":",
"Observable",
"{",
"$",
"index",
"=",
"0",
";",
"return",
"$",
"this",
"->",
"map",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"selector",
",",
"&",
"$",
"index",
")",
"{",
"return",
"$",
"selector",
"(",
"$",
"index",
"++",
",",
"$",
"value",
")",
";",
"}",
")",
";",
"}"
] |
Maps operator variant that calls the map selector with the index and value
@param callable $selector
@return Observable
@demo map/mapWithIndex.php
@operator
@reactivex map
|
[
"Maps",
"operator",
"variant",
"that",
"calls",
"the",
"map",
"selector",
"with",
"the",
"index",
"and",
"value"
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L425-L431
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.skipWhileWithIndex
|
public function skipWhileWithIndex(callable $predicate): Observable
{
$index = 0;
return $this->skipWhile(function ($value) use ($predicate, &$index) {
return $predicate($index++, $value);
});
}
|
php
|
public function skipWhileWithIndex(callable $predicate): Observable
{
$index = 0;
return $this->skipWhile(function ($value) use ($predicate, &$index) {
return $predicate($index++, $value);
});
}
|
[
"public",
"function",
"skipWhileWithIndex",
"(",
"callable",
"$",
"predicate",
")",
":",
"Observable",
"{",
"$",
"index",
"=",
"0",
";",
"return",
"$",
"this",
"->",
"skipWhile",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"predicate",
",",
"&",
"$",
"index",
")",
"{",
"return",
"$",
"predicate",
"(",
"$",
"index",
"++",
",",
"$",
"value",
")",
";",
"}",
")",
";",
"}"
] |
Bypasses elements in an observable sequence as long as a specified condition is true and then returns the
remaining elements. The element's index is used in the logic of the predicate function.
@param callable $predicate A function to test each element for a condition; the first parameter of the
function represents the index of the source element, the second parameter is the value.
@return Observable An observable sequence that contains the elements from the input sequence starting
at the first element in the linear series that does not pass the test specified by predicate.
@demo skip/skipWhileWithIndex.php
@operator
@reactivex skipWhile
|
[
"Bypasses",
"elements",
"in",
"an",
"observable",
"sequence",
"as",
"long",
"as",
"a",
"specified",
"condition",
"is",
"true",
"and",
"then",
"returns",
"the",
"remaining",
"elements",
".",
"The",
"element",
"s",
"index",
"is",
"used",
"in",
"the",
"logic",
"of",
"the",
"predicate",
"function",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L618-L624
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.take
|
public function take(int $count): Observable
{
if ($count === 0) {
return self::empty();
}
return $this->lift(function () use ($count) {
return new TakeOperator($count);
});
}
|
php
|
public function take(int $count): Observable
{
if ($count === 0) {
return self::empty();
}
return $this->lift(function () use ($count) {
return new TakeOperator($count);
});
}
|
[
"public",
"function",
"take",
"(",
"int",
"$",
"count",
")",
":",
"Observable",
"{",
"if",
"(",
"$",
"count",
"===",
"0",
")",
"{",
"return",
"self",
"::",
"empty",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"count",
")",
"{",
"return",
"new",
"TakeOperator",
"(",
"$",
"count",
")",
";",
"}",
")",
";",
"}"
] |
Returns a specified number of contiguous elements from the start of an observable sequence
@param integer $count
@return Observable|EmptyObservable
@demo take/take.php
@operator
@reactivex take
|
[
"Returns",
"a",
"specified",
"number",
"of",
"contiguous",
"elements",
"from",
"the",
"start",
"of",
"an",
"observable",
"sequence"
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L636-L645
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.takeWhileWithIndex
|
public function takeWhileWithIndex(callable $predicate): Observable
{
$index = 0;
return $this->takeWhile(function ($value) use ($predicate, &$index) {
return $predicate($index++, $value);
});
}
|
php
|
public function takeWhileWithIndex(callable $predicate): Observable
{
$index = 0;
return $this->takeWhile(function ($value) use ($predicate, &$index) {
return $predicate($index++, $value);
});
}
|
[
"public",
"function",
"takeWhileWithIndex",
"(",
"callable",
"$",
"predicate",
")",
":",
"Observable",
"{",
"$",
"index",
"=",
"0",
";",
"return",
"$",
"this",
"->",
"takeWhile",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"predicate",
",",
"&",
"$",
"index",
")",
"{",
"return",
"$",
"predicate",
"(",
"$",
"index",
"++",
",",
"$",
"value",
")",
";",
"}",
")",
";",
"}"
] |
Returns elements from an observable sequence as long as a specified condition is true. It takes as a parameter a
a callback to test each source element for a condition. The callback predicate is called with the index and the
value of the element.
@param callable $predicate
@return Observable
@demo take/takeWhileWithIndex.php
@operator
@reactivex takeWhile
|
[
"Returns",
"elements",
"from",
"an",
"observable",
"sequence",
"as",
"long",
"as",
"a",
"specified",
"condition",
"is",
"true",
".",
"It",
"takes",
"as",
"a",
"parameter",
"a",
"a",
"callback",
"to",
"test",
"each",
"source",
"element",
"for",
"a",
"condition",
".",
"The",
"callback",
"predicate",
"is",
"called",
"with",
"the",
"index",
"and",
"the",
"value",
"of",
"the",
"element",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L697-L703
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.groupBy
|
public function groupBy(callable $keySelector, callable $elementSelector = null, callable $keySerializer = null): Observable
{
return $this->groupByUntil($keySelector, $elementSelector, function () {
return static::never();
}, $keySerializer);
}
|
php
|
public function groupBy(callable $keySelector, callable $elementSelector = null, callable $keySerializer = null): Observable
{
return $this->groupByUntil($keySelector, $elementSelector, function () {
return static::never();
}, $keySerializer);
}
|
[
"public",
"function",
"groupBy",
"(",
"callable",
"$",
"keySelector",
",",
"callable",
"$",
"elementSelector",
"=",
"null",
",",
"callable",
"$",
"keySerializer",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"groupByUntil",
"(",
"$",
"keySelector",
",",
"$",
"elementSelector",
",",
"function",
"(",
")",
"{",
"return",
"static",
"::",
"never",
"(",
")",
";",
"}",
",",
"$",
"keySerializer",
")",
";",
"}"
] |
Groups the elements of an observable sequence according to a specified key selector function and comparer and selects the resulting elements by using a specified function.
@param callable $keySelector
@param callable|null $elementSelector
@param callable|null $keySerializer
@return Observable
@demo groupBy/groupBy.php
@operator
@reactivex groupBy
|
[
"Groups",
"the",
"elements",
"of",
"an",
"observable",
"sequence",
"according",
"to",
"a",
"specified",
"key",
"selector",
"function",
"and",
"comparer",
"and",
"selects",
"the",
"resulting",
"elements",
"by",
"using",
"a",
"specified",
"function",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L734-L739
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.reduce
|
public function reduce(callable $accumulator, $seed = null): Observable
{
return $this->lift(function () use ($accumulator, $seed) {
return new ReduceOperator($accumulator, $seed);
});
}
|
php
|
public function reduce(callable $accumulator, $seed = null): Observable
{
return $this->lift(function () use ($accumulator, $seed) {
return new ReduceOperator($accumulator, $seed);
});
}
|
[
"public",
"function",
"reduce",
"(",
"callable",
"$",
"accumulator",
",",
"$",
"seed",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"accumulator",
",",
"$",
"seed",
")",
"{",
"return",
"new",
"ReduceOperator",
"(",
"$",
"accumulator",
",",
"$",
"seed",
")",
";",
"}",
")",
";",
"}"
] |
Applies an accumulator function over an observable sequence,
returning the result of the aggregation as a single element in the result sequence.
The specified seed value is used as the initial accumulator value.
@param callable $accumulator - An accumulator function to be invoked on each element.
@param mixed $seed [optional] - The initial accumulator value.
@return Observable - An observable sequence containing a single element with the final
accumulator value.
@demo reduce/reduce.php
@demo reduce/reduce-with-seed.php
@operator
@reactivex reduce
|
[
"Applies",
"an",
"accumulator",
"function",
"over",
"an",
"observable",
"sequence",
"returning",
"the",
"result",
"of",
"the",
"aggregation",
"as",
"a",
"single",
"element",
"in",
"the",
"result",
"sequence",
".",
"The",
"specified",
"seed",
"value",
"is",
"used",
"as",
"the",
"initial",
"accumulator",
"value",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L819-L824
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.distinct
|
public function distinct(callable $comparer = null): Observable
{
return $this->lift(function () use ($comparer) {
return new DistinctOperator(null, $comparer);
});
}
|
php
|
public function distinct(callable $comparer = null): Observable
{
return $this->lift(function () use ($comparer) {
return new DistinctOperator(null, $comparer);
});
}
|
[
"public",
"function",
"distinct",
"(",
"callable",
"$",
"comparer",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"comparer",
")",
"{",
"return",
"new",
"DistinctOperator",
"(",
"null",
",",
"$",
"comparer",
")",
";",
"}",
")",
";",
"}"
] |
Returns an observable sequence that contains only distinct elements according to the keySelector and the
comparer. Usage of this operator should be considered carefully due to the maintenance of an internal lookup
structure which can grow large.
@param callable|null $comparer
@return Observable
@demo distinct/distinct.php
@operator
@reactivex distinct
|
[
"Returns",
"an",
"observable",
"sequence",
"that",
"contains",
"only",
"distinct",
"elements",
"according",
"to",
"the",
"keySelector",
"and",
"the",
"comparer",
".",
"Usage",
"of",
"this",
"operator",
"should",
"be",
"considered",
"carefully",
"due",
"to",
"the",
"maintenance",
"of",
"an",
"internal",
"lookup",
"structure",
"which",
"can",
"grow",
"large",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L838-L843
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.distinctKey
|
public function distinctKey(callable $keySelector, callable $comparer = null): Observable
{
return $this->lift(function () use ($keySelector, $comparer) {
return new DistinctOperator($keySelector, $comparer);
});
}
|
php
|
public function distinctKey(callable $keySelector, callable $comparer = null): Observable
{
return $this->lift(function () use ($keySelector, $comparer) {
return new DistinctOperator($keySelector, $comparer);
});
}
|
[
"public",
"function",
"distinctKey",
"(",
"callable",
"$",
"keySelector",
",",
"callable",
"$",
"comparer",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"keySelector",
",",
"$",
"comparer",
")",
"{",
"return",
"new",
"DistinctOperator",
"(",
"$",
"keySelector",
",",
"$",
"comparer",
")",
";",
"}",
")",
";",
"}"
] |
Variant of distinct that takes a key selector
@param callable|null $keySelector
@param callable|null $comparer
@return Observable
@demo distinct/distinctKey.php
@operator
@reactivex distinct
|
[
"Variant",
"of",
"distinct",
"that",
"takes",
"a",
"key",
"selector"
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L856-L861
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.distinctUntilChanged
|
public function distinctUntilChanged(callable $comparer = null): Observable
{
return $this->lift(function () use ($comparer) {
return new DistinctUntilChangedOperator(null, $comparer);
});
}
|
php
|
public function distinctUntilChanged(callable $comparer = null): Observable
{
return $this->lift(function () use ($comparer) {
return new DistinctUntilChangedOperator(null, $comparer);
});
}
|
[
"public",
"function",
"distinctUntilChanged",
"(",
"callable",
"$",
"comparer",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"comparer",
")",
"{",
"return",
"new",
"DistinctUntilChangedOperator",
"(",
"null",
",",
"$",
"comparer",
")",
";",
"}",
")",
";",
"}"
] |
A variant of distinct that only compares emitted items from the source Observable against their immediate predecessors in order to determine whether or not they are distinct.
@param callable $comparer
@return Observable
@demo distinct/distinctUntilChanged.php
@operator
@reactivex distinct
|
[
"A",
"variant",
"of",
"distinct",
"that",
"only",
"compares",
"emitted",
"items",
"from",
"the",
"source",
"Observable",
"against",
"their",
"immediate",
"predecessors",
"in",
"order",
"to",
"determine",
"whether",
"or",
"not",
"they",
"are",
"distinct",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L873-L878
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.distinctUntilKeyChanged
|
public function distinctUntilKeyChanged(callable $keySelector = null, callable $comparer = null): Observable
{
return $this->lift(function () use ($keySelector, $comparer) {
return new DistinctUntilChangedOperator($keySelector, $comparer);
});
}
|
php
|
public function distinctUntilKeyChanged(callable $keySelector = null, callable $comparer = null): Observable
{
return $this->lift(function () use ($keySelector, $comparer) {
return new DistinctUntilChangedOperator($keySelector, $comparer);
});
}
|
[
"public",
"function",
"distinctUntilKeyChanged",
"(",
"callable",
"$",
"keySelector",
"=",
"null",
",",
"callable",
"$",
"comparer",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"keySelector",
",",
"$",
"comparer",
")",
"{",
"return",
"new",
"DistinctUntilChangedOperator",
"(",
"$",
"keySelector",
",",
"$",
"comparer",
")",
";",
"}",
")",
";",
"}"
] |
Variant of distinctUntilChanged that takes a key selector
and the comparer.
@param callable $keySelector
@param callable $comparer
@return Observable
@demo distinct/distinctUntilKeyChanged.php
@operator
@reactivex distinct
|
[
"Variant",
"of",
"distinctUntilChanged",
"that",
"takes",
"a",
"key",
"selector",
"and",
"the",
"comparer",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L892-L897
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.do
|
public function do($onNextOrObserver = null, callable $onError = null, callable $onCompleted = null): Observable
{
if ($onNextOrObserver instanceof ObserverInterface) {
$observer = $onNextOrObserver;
} elseif (is_callable($onNextOrObserver)) {
$observer = new DoObserver($onNextOrObserver, $onError, $onCompleted);
} else {
throw new \InvalidArgumentException('The first argument needs to be a "callable" or "Observer"');
}
return $this->lift(function () use ($observer) {
return new DoOnEachOperator($observer);
});
}
|
php
|
public function do($onNextOrObserver = null, callable $onError = null, callable $onCompleted = null): Observable
{
if ($onNextOrObserver instanceof ObserverInterface) {
$observer = $onNextOrObserver;
} elseif (is_callable($onNextOrObserver)) {
$observer = new DoObserver($onNextOrObserver, $onError, $onCompleted);
} else {
throw new \InvalidArgumentException('The first argument needs to be a "callable" or "Observer"');
}
return $this->lift(function () use ($observer) {
return new DoOnEachOperator($observer);
});
}
|
[
"public",
"function",
"do",
"(",
"$",
"onNextOrObserver",
"=",
"null",
",",
"callable",
"$",
"onError",
"=",
"null",
",",
"callable",
"$",
"onCompleted",
"=",
"null",
")",
":",
"Observable",
"{",
"if",
"(",
"$",
"onNextOrObserver",
"instanceof",
"ObserverInterface",
")",
"{",
"$",
"observer",
"=",
"$",
"onNextOrObserver",
";",
"}",
"elseif",
"(",
"is_callable",
"(",
"$",
"onNextOrObserver",
")",
")",
"{",
"$",
"observer",
"=",
"new",
"DoObserver",
"(",
"$",
"onNextOrObserver",
",",
"$",
"onError",
",",
"$",
"onCompleted",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The first argument needs to be a \"callable\" or \"Observer\"'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"observer",
")",
"{",
"return",
"new",
"DoOnEachOperator",
"(",
"$",
"observer",
")",
";",
"}",
")",
";",
"}"
] |
Invokes an action for each element in the observable sequence and invokes an action upon graceful
or exceptional termination of the observable sequence.
This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to
run arbitrary actions for messages on the pipeline.
When using do, it is important to note that the Observer may receive additional
events after a stream has completed or errored (such as when using a repeat or resubscribing).
If you are using an Observable that extends the AbstractObservable, you will not receive these
events. For this special case, use the DoObserver.
doOnNext, doOnError, and doOnCompleted uses the DoObserver internally and will receive these
additional events.
@param callable|ObserverInterface $onNextOrObserver
@param callable $onError
@param callable $onCompleted
@return Observable
@throws \InvalidArgumentException
@demo do/do.php
@operator
@reactivex do
|
[
"Invokes",
"an",
"action",
"for",
"each",
"element",
"in",
"the",
"observable",
"sequence",
"and",
"invokes",
"an",
"action",
"upon",
"graceful",
"or",
"exceptional",
"termination",
"of",
"the",
"observable",
"sequence",
".",
"This",
"method",
"can",
"be",
"used",
"for",
"debugging",
"logging",
"etc",
".",
"of",
"query",
"behavior",
"by",
"intercepting",
"the",
"message",
"stream",
"to",
"run",
"arbitrary",
"actions",
"for",
"messages",
"on",
"the",
"pipeline",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L923-L936
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.timer
|
public static function timer(int $dueTime, AsyncSchedulerInterface $scheduler = null): TimerObservable
{
return new TimerObservable($dueTime, $scheduler ?: Scheduler::getAsync());
}
|
php
|
public static function timer(int $dueTime, AsyncSchedulerInterface $scheduler = null): TimerObservable
{
return new TimerObservable($dueTime, $scheduler ?: Scheduler::getAsync());
}
|
[
"public",
"static",
"function",
"timer",
"(",
"int",
"$",
"dueTime",
",",
"AsyncSchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"TimerObservable",
"{",
"return",
"new",
"TimerObservable",
"(",
"$",
"dueTime",
",",
"$",
"scheduler",
"?",
":",
"Scheduler",
"::",
"getAsync",
"(",
")",
")",
";",
"}"
] |
Returns an observable sequence that produces a value after dueTime has elapsed.
@param integer $dueTime - milliseconds
@param AsyncSchedulerInterface $scheduler
@return TimerObservable
@demo timer/timer.php
@operator
@reactivex timer
|
[
"Returns",
"an",
"observable",
"sequence",
"that",
"produces",
"a",
"value",
"after",
"dueTime",
"has",
"elapsed",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1087-L1090
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.concatMap
|
public function concatMap(callable $selector, callable $resultSelector = null): Observable
{
return $this->lift(function () use ($selector, $resultSelector) {
return new ConcatMapOperator(new ObservableFactoryWrapper($selector), $resultSelector);
});
}
|
php
|
public function concatMap(callable $selector, callable $resultSelector = null): Observable
{
return $this->lift(function () use ($selector, $resultSelector) {
return new ConcatMapOperator(new ObservableFactoryWrapper($selector), $resultSelector);
});
}
|
[
"public",
"function",
"concatMap",
"(",
"callable",
"$",
"selector",
",",
"callable",
"$",
"resultSelector",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"selector",
",",
"$",
"resultSelector",
")",
"{",
"return",
"new",
"ConcatMapOperator",
"(",
"new",
"ObservableFactoryWrapper",
"(",
"$",
"selector",
")",
",",
"$",
"resultSelector",
")",
";",
"}",
")",
";",
"}"
] |
Projects each element of an observable sequence to an observable sequence and concatenates the resulting
observable sequences into one observable sequence.
@param callable $selector A transform function to apply to each element from the source sequence onto.
The selector is called with the following information:
- the value of the element
- the index of the element
- the Observable object being subscribed
@param callable $resultSelector A transform function to apply to each element of the intermediate sequence.
The resultSelector is called with the following information:
- the value of the outer element
- the value of the inner element
- the index of the outer element
- the index of the inner element
@return Observable - An observable sequence whose elements are the result of invoking the one-to-many
transform function collectionSelector on each element of the input sequence and then mapping each of those
sequence elements and their corresponding source element to a result element.
@demo concat/concatMap.php
@operator
@reactivex flatMap
|
[
"Projects",
"each",
"element",
"of",
"an",
"observable",
"sequence",
"to",
"an",
"observable",
"sequence",
"and",
"concatenates",
"the",
"resulting",
"observable",
"sequences",
"into",
"one",
"observable",
"sequence",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1150-L1155
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.concatMapTo
|
public function concatMapTo(ObservableInterface $observable, callable $resultSelector = null): Observable
{
return $this->concatMap(function () use ($observable) {
return $observable;
}, $resultSelector);
}
|
php
|
public function concatMapTo(ObservableInterface $observable, callable $resultSelector = null): Observable
{
return $this->concatMap(function () use ($observable) {
return $observable;
}, $resultSelector);
}
|
[
"public",
"function",
"concatMapTo",
"(",
"ObservableInterface",
"$",
"observable",
",",
"callable",
"$",
"resultSelector",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"concatMap",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"observable",
")",
"{",
"return",
"$",
"observable",
";",
"}",
",",
"$",
"resultSelector",
")",
";",
"}"
] |
Projects each element of the source observable sequence to the other observable sequence and merges the
resulting observable sequences into one observable sequence.
@param ObservableInterface $observable - An an observable sequence to project each element from the source
sequence onto.
@param callable $resultSelector A transform function to apply to each element of the intermediate sequence.
The resultSelector is called with the following information:
- the value of the outer element
- the value of the inner element
- the index of the outer element
- the index of the inner element
@return Observable An observable sequence whose elements are the result of invoking the one-to-many
transform function collectionSelector on each element of the input sequence and then mapping each of those
sequence elements and their corresponding source element to a result element.
@demo concat/concatMapTo.php
@operator
@reactivex flatMap
|
[
"Projects",
"each",
"element",
"of",
"the",
"source",
"observable",
"sequence",
"to",
"the",
"other",
"observable",
"sequence",
"and",
"merges",
"the",
"resulting",
"observable",
"sequences",
"into",
"one",
"observable",
"sequence",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1179-L1184
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.publishValue
|
public function publishValue($initialValue, callable $selector = null): Observable
{
return $this->multicast(new BehaviorSubject($initialValue), $selector);
}
|
php
|
public function publishValue($initialValue, callable $selector = null): Observable
{
return $this->multicast(new BehaviorSubject($initialValue), $selector);
}
|
[
"public",
"function",
"publishValue",
"(",
"$",
"initialValue",
",",
"callable",
"$",
"selector",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"multicast",
"(",
"new",
"BehaviorSubject",
"(",
"$",
"initialValue",
")",
",",
"$",
"selector",
")",
";",
"}"
] |
Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence
that shares a single subscription to the underlying sequence and starts with initialValue.
This operator is a specialization of Multicast using a BehaviorSubject.
@param mixed $initialValue
@param callable $selector
@return \Rx\Observable\ConnectableObservable|\Rx\Observable\MulticastObservable
@demo publish/publishValue.php
@operator
@reactivex publish
|
[
"Returns",
"an",
"observable",
"sequence",
"that",
"is",
"the",
"result",
"of",
"invoking",
"the",
"selector",
"on",
"a",
"connectable",
"observable",
"sequence",
"that",
"shares",
"a",
"single",
"subscription",
"to",
"the",
"underlying",
"sequence",
"and",
"starts",
"with",
"initialValue",
".",
"This",
"operator",
"is",
"a",
"specialization",
"of",
"Multicast",
"using",
"a",
"BehaviorSubject",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1308-L1311
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.singleInstance
|
public function singleInstance(): Observable
{
$hasObservable = false;
$observable = null;
$source = $this;
$getObservable = function () use (&$hasObservable, &$observable, $source): Observable {
if (!$hasObservable) {
$hasObservable = true;
$observable = $source
->finally(function () use (&$hasObservable) {
$hasObservable = false;
})
->publish()
->refCount();
}
return $observable;
};
return new Observable\AnonymousObservable(function (ObserverInterface $o) use ($getObservable) {
return $getObservable()->subscribe($o);
});
}
|
php
|
public function singleInstance(): Observable
{
$hasObservable = false;
$observable = null;
$source = $this;
$getObservable = function () use (&$hasObservable, &$observable, $source): Observable {
if (!$hasObservable) {
$hasObservable = true;
$observable = $source
->finally(function () use (&$hasObservable) {
$hasObservable = false;
})
->publish()
->refCount();
}
return $observable;
};
return new Observable\AnonymousObservable(function (ObserverInterface $o) use ($getObservable) {
return $getObservable()->subscribe($o);
});
}
|
[
"public",
"function",
"singleInstance",
"(",
")",
":",
"Observable",
"{",
"$",
"hasObservable",
"=",
"false",
";",
"$",
"observable",
"=",
"null",
";",
"$",
"source",
"=",
"$",
"this",
";",
"$",
"getObservable",
"=",
"function",
"(",
")",
"use",
"(",
"&",
"$",
"hasObservable",
",",
"&",
"$",
"observable",
",",
"$",
"source",
")",
":",
"Observable",
"{",
"if",
"(",
"!",
"$",
"hasObservable",
")",
"{",
"$",
"hasObservable",
"=",
"true",
";",
"$",
"observable",
"=",
"$",
"source",
"->",
"finally",
"(",
"function",
"(",
")",
"use",
"(",
"&",
"$",
"hasObservable",
")",
"{",
"$",
"hasObservable",
"=",
"false",
";",
"}",
")",
"->",
"publish",
"(",
")",
"->",
"refCount",
"(",
")",
";",
"}",
"return",
"$",
"observable",
";",
"}",
";",
"return",
"new",
"Observable",
"\\",
"AnonymousObservable",
"(",
"function",
"(",
"ObserverInterface",
"$",
"o",
")",
"use",
"(",
"$",
"getObservable",
")",
"{",
"return",
"$",
"getObservable",
"(",
")",
"->",
"subscribe",
"(",
"$",
"o",
")",
";",
"}",
")",
";",
"}"
] |
Returns an observable sequence that shares a single subscription to the underlying sequence. This observable sequence
can be resubscribed to, even if all prior subscriptions have ended.
This operator behaves like share() in RxJS 5
@return \Rx\Observable An observable sequence that contains the elements of a sequence
produced by multicasting the source sequence.
@demo share/singleInstance.php
@operator
@reactivex refcount
|
[
"Returns",
"an",
"observable",
"sequence",
"that",
"shares",
"a",
"single",
"subscription",
"to",
"the",
"underlying",
"sequence",
".",
"This",
"observable",
"sequence",
"can",
"be",
"resubscribed",
"to",
"even",
"if",
"all",
"prior",
"subscriptions",
"have",
"ended",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1345-L1367
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.shareReplay
|
public function shareReplay(int $bufferSize, int $windowSize = null, SchedulerInterface $scheduler = null): RefCountObservable
{
return $this->replay(null, $bufferSize, $windowSize, $scheduler)->refCount();
}
|
php
|
public function shareReplay(int $bufferSize, int $windowSize = null, SchedulerInterface $scheduler = null): RefCountObservable
{
return $this->replay(null, $bufferSize, $windowSize, $scheduler)->refCount();
}
|
[
"public",
"function",
"shareReplay",
"(",
"int",
"$",
"bufferSize",
",",
"int",
"$",
"windowSize",
"=",
"null",
",",
"SchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"RefCountObservable",
"{",
"return",
"$",
"this",
"->",
"replay",
"(",
"null",
",",
"$",
"bufferSize",
",",
"$",
"windowSize",
",",
"$",
"scheduler",
")",
"->",
"refCount",
"(",
")",
";",
"}"
] |
Returns an observable sequence that shares a single subscription to the underlying sequence replaying
notifications subject to a maximum time length for the replay buffer.
This operator is a specialization of replay which creates a subscription when the number of observers goes from
zero to one, then shares that subscription with all subsequent observers until the number of observers returns
to zero, at which point the subscription is disposed.
@param integer $bufferSize
@param integer $windowSize
@param $scheduler
@return \Rx\Observable\RefCountObservable
@demo share/shareReplay.php
@operator
@reactivex replay
|
[
"Returns",
"an",
"observable",
"sequence",
"that",
"shares",
"a",
"single",
"subscription",
"to",
"the",
"underlying",
"sequence",
"replaying",
"notifications",
"subject",
"to",
"a",
"maximum",
"time",
"length",
"for",
"the",
"replay",
"buffer",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1428-L1431
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.repeat
|
public function repeat(int $count = -1): Observable
{
if ($count === 0) {
return self::empty();
}
return $this->lift(function () use ($count) {
return new RepeatOperator($count);
});
}
|
php
|
public function repeat(int $count = -1): Observable
{
if ($count === 0) {
return self::empty();
}
return $this->lift(function () use ($count) {
return new RepeatOperator($count);
});
}
|
[
"public",
"function",
"repeat",
"(",
"int",
"$",
"count",
"=",
"-",
"1",
")",
":",
"Observable",
"{",
"if",
"(",
"$",
"count",
"===",
"0",
")",
"{",
"return",
"self",
"::",
"empty",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"count",
")",
"{",
"return",
"new",
"RepeatOperator",
"(",
"$",
"count",
")",
";",
"}",
")",
";",
"}"
] |
Generates an observable sequence that repeats the given element the specified number of times.
@param int $count
@return Observable|EmptyObservable
@demo repeat/repeat.php
@operator
@reactivex repeat
|
[
"Generates",
"an",
"observable",
"sequence",
"that",
"repeats",
"the",
"given",
"element",
"the",
"specified",
"number",
"of",
"times",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1573-L1582
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.timeout
|
public function timeout(int $timeout, ObservableInterface $timeoutObservable = null, AsyncSchedulerInterface $scheduler = null): Observable
{
return $this->lift(function () use ($timeout, $timeoutObservable, $scheduler) {
return new TimeoutOperator($timeout, $timeoutObservable, $scheduler ?: Scheduler::getAsync());
});
}
|
php
|
public function timeout(int $timeout, ObservableInterface $timeoutObservable = null, AsyncSchedulerInterface $scheduler = null): Observable
{
return $this->lift(function () use ($timeout, $timeoutObservable, $scheduler) {
return new TimeoutOperator($timeout, $timeoutObservable, $scheduler ?: Scheduler::getAsync());
});
}
|
[
"public",
"function",
"timeout",
"(",
"int",
"$",
"timeout",
",",
"ObservableInterface",
"$",
"timeoutObservable",
"=",
"null",
",",
"AsyncSchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"timeout",
",",
"$",
"timeoutObservable",
",",
"$",
"scheduler",
")",
"{",
"return",
"new",
"TimeoutOperator",
"(",
"$",
"timeout",
",",
"$",
"timeoutObservable",
",",
"$",
"scheduler",
"?",
":",
"Scheduler",
"::",
"getAsync",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] |
Errors the observable sequence if no item is emitted in the specified time.
When a timeout occurs, this operator errors with an instance of Rx\Exception\TimeoutException
@param $timeout
@param ObservableInterface $timeoutObservable
@param AsyncSchedulerInterface $scheduler
@return Observable
@demo timeout/timeout.php
@operator
@reactivex timeout
|
[
"Errors",
"the",
"observable",
"sequence",
"if",
"no",
"item",
"is",
"emitted",
"in",
"the",
"specified",
"time",
".",
"When",
"a",
"timeout",
"occurs",
"this",
"operator",
"errors",
"with",
"an",
"instance",
"of",
"Rx",
"\\",
"Exception",
"\\",
"TimeoutException"
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1649-L1654
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.bufferWithCount
|
public function bufferWithCount(int $count, int $skip = null): Observable
{
return $this->lift(function () use ($count, $skip) {
return new BufferWithCountOperator($count, $skip);
});
}
|
php
|
public function bufferWithCount(int $count, int $skip = null): Observable
{
return $this->lift(function () use ($count, $skip) {
return new BufferWithCountOperator($count, $skip);
});
}
|
[
"public",
"function",
"bufferWithCount",
"(",
"int",
"$",
"count",
",",
"int",
"$",
"skip",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"count",
",",
"$",
"skip",
")",
"{",
"return",
"new",
"BufferWithCountOperator",
"(",
"$",
"count",
",",
"$",
"skip",
")",
";",
"}",
")",
";",
"}"
] |
Projects each element of an observable sequence into zero or more buffers which are produced based on
element count information.
@param $count
@param int $skip
@return Observable
@throws \InvalidArgumentException
@demo bufferWithCount/bufferWithCount.php
@demo bufferWithCount/bufferWithCountAndSkip.php
@operator
@reactivex buffer
|
[
"Projects",
"each",
"element",
"of",
"an",
"observable",
"sequence",
"into",
"zero",
"or",
"more",
"buffers",
"which",
"are",
"produced",
"based",
"on",
"element",
"count",
"information",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1670-L1675
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.startWith
|
public function startWith($startValue, SchedulerInterface $scheduler = null): Observable
{
return $this->startWithArray([$startValue], $scheduler);
}
|
php
|
public function startWith($startValue, SchedulerInterface $scheduler = null): Observable
{
return $this->startWithArray([$startValue], $scheduler);
}
|
[
"public",
"function",
"startWith",
"(",
"$",
"startValue",
",",
"SchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"startWithArray",
"(",
"[",
"$",
"startValue",
"]",
",",
"$",
"scheduler",
")",
";",
"}"
] |
Prepends a value to an observable sequence with an argument of a signal value to prepend.
@param mixed $startValue
@param SchedulerInterface $scheduler
@return Observable
@demo startWith/startWith.php
@operator
@reactivex startwith
|
[
"Prepends",
"a",
"value",
"to",
"an",
"observable",
"sequence",
"with",
"an",
"argument",
"of",
"a",
"signal",
"value",
"to",
"prepend",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1717-L1720
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.startWithArray
|
public function startWithArray(array $startArray, SchedulerInterface $scheduler = null): Observable
{
return $this->lift(function () use ($startArray, $scheduler) {
return new StartWithArrayOperator($startArray, $scheduler ?: Scheduler::getDefault());
});
}
|
php
|
public function startWithArray(array $startArray, SchedulerInterface $scheduler = null): Observable
{
return $this->lift(function () use ($startArray, $scheduler) {
return new StartWithArrayOperator($startArray, $scheduler ?: Scheduler::getDefault());
});
}
|
[
"public",
"function",
"startWithArray",
"(",
"array",
"$",
"startArray",
",",
"SchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"startArray",
",",
"$",
"scheduler",
")",
"{",
"return",
"new",
"StartWithArrayOperator",
"(",
"$",
"startArray",
",",
"$",
"scheduler",
"?",
":",
"Scheduler",
"::",
"getDefault",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] |
Prepends a sequence of values to an observable sequence with an argument of an array of values to prepend.
@param array $startArray
@param SchedulerInterface $scheduler
@return Observable
@demo startWith/startWithArray.php
@operator
@reactivex startwith
|
[
"Prepends",
"a",
"sequence",
"of",
"values",
"to",
"an",
"observable",
"sequence",
"with",
"an",
"argument",
"of",
"an",
"array",
"of",
"values",
"to",
"prepend",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1733-L1738
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.timestamp
|
public function timestamp(SchedulerInterface $scheduler = null): Observable
{
return $this->lift(function () use ($scheduler) {
return new TimestampOperator($scheduler ?: Scheduler::getDefault());
});
}
|
php
|
public function timestamp(SchedulerInterface $scheduler = null): Observable
{
return $this->lift(function () use ($scheduler) {
return new TimestampOperator($scheduler ?: Scheduler::getDefault());
});
}
|
[
"public",
"function",
"timestamp",
"(",
"SchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"scheduler",
")",
"{",
"return",
"new",
"TimestampOperator",
"(",
"$",
"scheduler",
"?",
":",
"Scheduler",
"::",
"getDefault",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] |
Records the timestamp for each value in an observable sequence.
@param SchedulerInterface|null $scheduler
@return Observable
@demo timestamp/timestamp.php
@operator
@reactivex timestamp
|
[
"Records",
"the",
"timestamp",
"for",
"each",
"value",
"in",
"an",
"observable",
"sequence",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1816-L1821
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.partition
|
public function partition(callable $predicate): array
{
return [
$this->filter($predicate),
$this->filter(function () use ($predicate) {
return !call_user_func_array($predicate, func_get_args());
})
];
}
|
php
|
public function partition(callable $predicate): array
{
return [
$this->filter($predicate),
$this->filter(function () use ($predicate) {
return !call_user_func_array($predicate, func_get_args());
})
];
}
|
[
"public",
"function",
"partition",
"(",
"callable",
"$",
"predicate",
")",
":",
"array",
"{",
"return",
"[",
"$",
"this",
"->",
"filter",
"(",
"$",
"predicate",
")",
",",
"$",
"this",
"->",
"filter",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"predicate",
")",
"{",
"return",
"!",
"call_user_func_array",
"(",
"$",
"predicate",
",",
"func_get_args",
"(",
")",
")",
";",
"}",
")",
"]",
";",
"}"
] |
Returns two observables which partition the observations of the source by the given function.
The first will trigger observations for those values for which the predicate returns true.
The second will trigger observations for those values where the predicate returns false.
The predicate is executed once for each subscribed observer.
Both also propagate all error observations arising from the source and each completes
when the source completes.
@param callable $predicate
@return Observable[]
@demo partition/partition.php
@operator
@reactivex groupBy
|
[
"Returns",
"two",
"observables",
"which",
"partition",
"the",
"observations",
"of",
"the",
"source",
"by",
"the",
"given",
"function",
".",
"The",
"first",
"will",
"trigger",
"observations",
"for",
"those",
"values",
"for",
"which",
"the",
"predicate",
"returns",
"true",
".",
"The",
"second",
"will",
"trigger",
"observations",
"for",
"those",
"values",
"where",
"the",
"predicate",
"returns",
"false",
".",
"The",
"predicate",
"is",
"executed",
"once",
"for",
"each",
"subscribed",
"observer",
".",
"Both",
"also",
"propagate",
"all",
"error",
"observations",
"arising",
"from",
"the",
"source",
"and",
"each",
"completes",
"when",
"the",
"source",
"completes",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1889-L1897
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.race
|
public static function race(array $observables, SchedulerInterface $scheduler = null): Observable
{
if (count($observables) === 1) {
return $observables[0];
}
return static::fromArray($observables, $scheduler)->lift(function () {
return new RaceOperator();
});
}
|
php
|
public static function race(array $observables, SchedulerInterface $scheduler = null): Observable
{
if (count($observables) === 1) {
return $observables[0];
}
return static::fromArray($observables, $scheduler)->lift(function () {
return new RaceOperator();
});
}
|
[
"public",
"static",
"function",
"race",
"(",
"array",
"$",
"observables",
",",
"SchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"Observable",
"{",
"if",
"(",
"count",
"(",
"$",
"observables",
")",
"===",
"1",
")",
"{",
"return",
"$",
"observables",
"[",
"0",
"]",
";",
"}",
"return",
"static",
"::",
"fromArray",
"(",
"$",
"observables",
",",
"$",
"scheduler",
")",
"->",
"lift",
"(",
"function",
"(",
")",
"{",
"return",
"new",
"RaceOperator",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Propagates the observable sequence that reacts first. Also known as 'amb'.
@param Observable[] $observables
@param SchedulerInterface $scheduler
@return Observable
@demo race/race.php
@operator
@reactivex amb
|
[
"Propagates",
"the",
"observable",
"sequence",
"that",
"reacts",
"first",
".",
"Also",
"known",
"as",
"amb",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1910-L1919
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.average
|
public function average(): Observable
{
return $this
->defaultIfEmpty(Observable::error(new \UnderflowException()))
->reduce(function ($a, $x) {
static $count = 0;
static $total = 0;
$count++;
$total += $x;
return $total / $count;
}, 0);
}
|
php
|
public function average(): Observable
{
return $this
->defaultIfEmpty(Observable::error(new \UnderflowException()))
->reduce(function ($a, $x) {
static $count = 0;
static $total = 0;
$count++;
$total += $x;
return $total / $count;
}, 0);
}
|
[
"public",
"function",
"average",
"(",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"defaultIfEmpty",
"(",
"Observable",
"::",
"error",
"(",
"new",
"\\",
"UnderflowException",
"(",
")",
")",
")",
"->",
"reduce",
"(",
"function",
"(",
"$",
"a",
",",
"$",
"x",
")",
"{",
"static",
"$",
"count",
"=",
"0",
";",
"static",
"$",
"total",
"=",
"0",
";",
"$",
"count",
"++",
";",
"$",
"total",
"+=",
"$",
"x",
";",
"return",
"$",
"total",
"/",
"$",
"count",
";",
"}",
",",
"0",
")",
";",
"}"
] |
Computes the average of an observable sequence of values.
@return Observable
@demo average/average.php
@operator
@reactivex average
|
[
"Computes",
"the",
"average",
"of",
"an",
"observable",
"sequence",
"of",
"values",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L1947-L1960
|
train
|
ReactiveX/RxPHP
|
src/Observable.php
|
Observable.throttle
|
public function throttle(int $throttleDuration, SchedulerInterface $scheduler = null): Observable
{
return $this->lift(function () use ($throttleDuration, $scheduler) {
return new ThrottleOperator($throttleDuration, $scheduler ?: Scheduler::getDefault());
});
}
|
php
|
public function throttle(int $throttleDuration, SchedulerInterface $scheduler = null): Observable
{
return $this->lift(function () use ($throttleDuration, $scheduler) {
return new ThrottleOperator($throttleDuration, $scheduler ?: Scheduler::getDefault());
});
}
|
[
"public",
"function",
"throttle",
"(",
"int",
"$",
"throttleDuration",
",",
"SchedulerInterface",
"$",
"scheduler",
"=",
"null",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"lift",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"throttleDuration",
",",
"$",
"scheduler",
")",
"{",
"return",
"new",
"ThrottleOperator",
"(",
"$",
"throttleDuration",
",",
"$",
"scheduler",
"?",
":",
"Scheduler",
"::",
"getDefault",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] |
Returns an Observable that emits only the first item emitted by the source Observable during
sequential time windows of a specified duration.
If items are emitted on the source observable prior to the expiration of the time period,
the last item emitted on the source observable will be emitted.
@param $throttleDuration
@param SchedulerInterface $scheduler
@return Observable
@demo throttle/throttle.php
@operator
@reactivex debounce
|
[
"Returns",
"an",
"Observable",
"that",
"emits",
"only",
"the",
"first",
"item",
"emitted",
"by",
"the",
"source",
"Observable",
"during",
"sequential",
"time",
"windows",
"of",
"a",
"specified",
"duration",
"."
] |
fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4
|
https://github.com/ReactiveX/RxPHP/blob/fd74a0cd2b5edd4a48e4ff12aaa44cc6cdc4a9b4/src/Observable.php#L2007-L2012
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.