code
stringlengths
17
247k
docstring
stringlengths
30
30.3k
func_name
stringlengths
1
89
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
153
url
stringlengths
51
209
license
stringclasses
4 values
public static function __set_state($state) { if (!isset($state['id'])) { throw new InvalidConfigException('Failed to instantiate class "Instance". Required parameter "id" is missing'); } return new self($state['id']); }
Restores class state after using `var_export()`. @param array $state @return Instance @throws InvalidConfigException when $state property does not contain `id` parameter @see https://www.php.net/manual/en/function.var-export.php @since 2.0.12
__set_state
php
yiisoft/yii2
framework/di/Instance.php
https://github.com/yiisoft/yii2/blob/master/framework/di/Instance.php
BSD-3-Clause
public function registerClientScript() { $id = $this->grid->options['id']; $options = Json::encode([ 'name' => $this->name, 'class' => $this->cssClass, 'multiple' => $this->multiple, 'checkAll' => $this->grid->showHeader ? $this->getHeaderCheckBoxName() : null, ]); $this->grid->getView()->registerJs("jQuery('#$id').yiiGridView('setSelectionColumn', $options);"); }
Registers the needed JavaScript. @since 2.0.8
registerClientScript
php
yiisoft/yii2
framework/grid/CheckboxColumn.php
https://github.com/yiisoft/yii2/blob/master/framework/grid/CheckboxColumn.php
BSD-3-Clause
public static function getParam($name, $default = null) { if (static::$params === null) { static::$params = require __DIR__ . '/data/config.php'; } return isset(static::$params[$name]) ? static::$params[$name] : $default; }
Returns a test configuration param from /data/config.php. @param string $name params name @param mixed $default default value to use when param is not set. @return mixed the value of the configuration param
getParam
php
yiisoft/yii2
tests/TestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/TestCase.php
BSD-3-Clause
protected function assertEqualsWithoutLE($expected, $actual, $message = '') { $expected = str_replace("\r\n", "\n", $expected); $actual = str_replace("\r\n", "\n", $actual); $this->assertEquals($expected, $actual, $message); }
Asserting two strings equality ignoring line endings. @param string $expected @param string $actual @param string $message
assertEqualsWithoutLE
php
yiisoft/yii2
tests/TestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/TestCase.php
BSD-3-Clause
protected function assertEqualsAnyWhitespace($expected, $actual, $message = ''){ $expected = $this->sanitizeWhitespaces($expected); $actual = $this->sanitizeWhitespaces($actual); $this->assertEquals($expected, $actual, $message); }
Asserting two strings equality ignoring unicode whitespaces. @param string $expected @param string $actual @param string $message
assertEqualsAnyWhitespace
php
yiisoft/yii2
tests/TestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/TestCase.php
BSD-3-Clause
protected function assertSameAnyWhitespace($expected, $actual, $message = ''){ if (is_string($expected)) { $expected = $this->sanitizeWhitespaces($expected); } if (is_string($actual)) { $actual = $this->sanitizeWhitespaces($actual); } $this->assertSame($expected, $actual, $message); }
Asserts that two variables have the same type and value and sanitizes value if it is a string. Used on objects, it asserts that two variables reference the same object. @param mixed $expected @param mixed $actual @param string $message
assertSameAnyWhitespace
php
yiisoft/yii2
tests/TestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/TestCase.php
BSD-3-Clause
protected function assertContainsWithoutLE($needle, $haystack, $message = '') { $needle = str_replace("\r\n", "\n", $needle); $haystack = str_replace("\r\n", "\n", $haystack); $this->assertStringContainsString($needle, $haystack, $message); }
Asserts that a haystack contains a needle ignoring line endings. @param mixed $needle @param mixed $haystack @param string $message
assertContainsWithoutLE
php
yiisoft/yii2
tests/TestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/TestCase.php
BSD-3-Clause
protected function sanitizeWhitespaces($string){ return preg_replace("/[\pZ\pC]/u", " ", $string); }
Replaces unicode whitespaces with standard whitespace @see https://github.com/yiisoft/yii2/issues/19868 (ICU 72 changes) @param $string @return string
sanitizeWhitespaces
php
yiisoft/yii2
tests/TestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/TestCase.php
BSD-3-Clause
protected function setInaccessibleProperty($object, $propertyName, $value, $revoke = true) { $class = new \ReflectionClass($object); while (!$class->hasProperty($propertyName)) { $class = $class->getParentClass(); } $property = $class->getProperty($propertyName); $property->setAccessible(true); $property->setValue($object, $value); if ($revoke) { $property->setAccessible(false); } }
Sets an inaccessible object property to a designated value. @param $object @param $propertyName @param $value @param bool $revoke whether to make property inaccessible after setting @since 2.0.11
setInaccessibleProperty
php
yiisoft/yii2
tests/TestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/TestCase.php
BSD-3-Clause
protected function getInaccessibleProperty($object, $propertyName, $revoke = true) { $class = new \ReflectionClass($object); while (!$class->hasProperty($propertyName)) { $class = $class->getParentClass(); } $property = $class->getProperty($propertyName); $property->setAccessible(true); $result = $property->getValue($object); if ($revoke) { $property->setAccessible(false); } return $result; }
Gets an inaccessible object property. @param $object @param $propertyName @param bool $revoke whether to make property inaccessible after getting @return mixed
getInaccessibleProperty
php
yiisoft/yii2
tests/TestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/TestCase.php
BSD-3-Clause
public function assertIsOneOf($actual, array $expected, $message = '') { self::assertThat($actual, new IsOneOfAssert($expected), $message); }
Asserts that value is one of expected values. @param mixed $actual @param array $expected @param string $message
assertIsOneOf
php
yiisoft/yii2
tests/TestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/TestCase.php
BSD-3-Clause
public function ignoredOptionsProvider() { return [ [false, false], [true, false], [false, true], [true, true], ]; }
$showScriptName and $enableStrictParsing should have no effect in default format. Passing these options ensures that.
ignoredOptionsProvider
php
yiisoft/yii2
tests/framework/web/UrlManagerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/web/UrlManagerTest.php
BSD-3-Clause
function time() { return \yiiunit\framework\web\UserTest::$time ?: \time(); }
Mock for the time() function for web classes. @return int
time
php
yiisoft/yii2
tests/framework/web/UserTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/web/UserTest.php
BSD-3-Clause
protected function reset() { static $server; if (!isset($server)) { $server = $_SERVER; } $_SERVER = $server; Yii::$app->set('response', ['class' => 'yii\web\Response']); Yii::$app->set('request', [ 'class' => 'yii\web\Request', 'scriptFile' => __DIR__ . '/index.php', 'scriptUrl' => '/index.php', 'url' => '', ]); Yii::$app->user->setReturnUrl(null); }
Resets request, response and $_SERVER.
reset
php
yiisoft/yii2
tests/framework/web/UserTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/web/UserTest.php
BSD-3-Clause
protected function getView(array $config = []) { $this->mockApplication(); $view = new View(); $config = array_merge([ 'basePath' => '@testAssetsPath', 'baseUrl' => '@testAssetsUrl', ], $config); $view->setAssetManager(new AssetManager($config)); return $view; }
Returns View with configured AssetManager. @param array $config may be used to override default AssetManager config @return View
getView
php
yiisoft/yii2
tests/framework/web/AssetBundleTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/web/AssetBundleTest.php
BSD-3-Clause
private function getCSRFTokenValue($html) { if (!preg_match('~<meta name="csrf-token" content="([^"]+)">~', $html, $matches)) { $this->fail("No CSRF-token meta tag found. HTML was:\n$html"); } return $matches[1]; }
Parses CSRF token from page HTML. @param string $html @return string CSRF token
getCSRFTokenValue
php
yiisoft/yii2
tests/framework/web/ViewTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/web/ViewTest.php
BSD-3-Clause
public function export() { // throw exception if message limit is reached throw new Exception('More than 1000000 messages logged.'); }
Exports log [[messages]] to a specific destination.
export
php
yiisoft/yii2
tests/framework/log/ArrayTarget.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/log/ArrayTarget.php
BSD-3-Clause
public function export() { TargetTest::$messages = array_merge(TargetTest::$messages, $this->messages); $this->messages = []; }
Exports log [[messages]] to a specific destination. Child classes must implement this method.
export
php
yiisoft/yii2
tests/framework/log/TargetTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/log/TargetTest.php
BSD-3-Clause
protected function mockAction($controllerId, $actionID, $moduleID = null, $params = []) { \Yii::$app->controller = $controller = new Controller($controllerId, \Yii::$app); $controller->actionParams = $params; $controller->action = new Action($actionID, $controller); if ($moduleID !== null) { $controller->module = new Module($moduleID); } }
Mocks controller action with parameters. @param string $controllerId @param string $actionID @param string $moduleID @param array $params
mockAction
php
yiisoft/yii2
tests/framework/helpers/UrlTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/UrlTest.php
BSD-3-Clause
protected function setupStreams() { ConsoleStub::$inputStream = fopen('php://memory', 'w+'); ConsoleStub::$outputStream = fopen('php://memory', 'w+'); ConsoleStub::$errorStream = fopen('php://memory', 'w+'); }
Set up streams for Console helper stub
setupStreams
php
yiisoft/yii2
tests/framework/helpers/ConsoleTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/ConsoleTest.php
BSD-3-Clause
protected function truncateStreams() { ftruncate(ConsoleStub::$inputStream, 0); rewind(ConsoleStub::$inputStream); ftruncate(ConsoleStub::$outputStream, 0); rewind(ConsoleStub::$outputStream); ftruncate(ConsoleStub::$errorStream, 0); rewind(ConsoleStub::$errorStream); }
Clean streams in Console helper stub
truncateStreams
php
yiisoft/yii2
tests/framework/helpers/ConsoleTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/ConsoleTest.php
BSD-3-Clause
protected function readOutput($stream = null) { if ($stream === null) { $stream = ConsoleStub::$outputStream; } rewind($stream); $output = ''; while (!feof($stream) && ($buffer = fread($stream, 1024)) !== false) { $output .= $buffer; } return $output; }
Read data from Console helper stream, defaults to output stream @param resource $stream @return string
readOutput
php
yiisoft/yii2
tests/framework/helpers/ConsoleTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/ConsoleTest.php
BSD-3-Clause
protected function sendInput() { fwrite(ConsoleStub::$inputStream, implode(PHP_EOL, func_get_args()) . PHP_EOL); rewind(ConsoleStub::$inputStream); }
Write passed arguments to Console helper input stream and rewind the position of a input stream pointer
sendInput
php
yiisoft/yii2
tests/framework/helpers/ConsoleTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/ConsoleTest.php
BSD-3-Clause
public function dataProviderBeginFormSimulateViaPost() { return [ ['<form action="/foo" method="GET">', 'GET'], ['<form action="/foo" method="POST">', 'POST'], ['<form action="/foo" method="post">%A<input type="hidden" name="_method" value="DELETE">', 'DELETE'], ['<form action="/foo" method="post">%A<input type="hidden" name="_method" value="GETFOO">', 'GETFOO'], ['<form action="/foo" method="post">%A<input type="hidden" name="_method" value="POSTFOO">', 'POSTFOO'], ['<form action="/foo" method="post">%A<input type="hidden" name="_method" value="POSTFOOPOST">', 'POSTFOOPOST'], ]; }
Data provider for [[testBeginFormSimulateViaPost()]]. @return array test data
dataProviderBeginFormSimulateViaPost
php
yiisoft/yii2
tests/framework/helpers/HtmlTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/HtmlTest.php
BSD-3-Clause
public function dataProviderActiveTextInput() { return [ [ 'some text', [], '<input type="text" id="htmltestmodel-name" name="HtmlTestModel[name]" value="some text">', ], [ '', [ 'maxlength' => true, ], '<input type="text" id="htmltestmodel-name" name="HtmlTestModel[name]" value="" maxlength="100">', ], [ '', [ 'maxlength' => 99, ], '<input type="text" id="htmltestmodel-name" name="HtmlTestModel[name]" value="" maxlength="99">', ], ]; }
Data provider for [[testActiveTextInput()]]. @return array test data
dataProviderActiveTextInput
php
yiisoft/yii2
tests/framework/helpers/HtmlTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/HtmlTest.php
BSD-3-Clause
public function dataProviderActiveTextInputMaxLength() { return [ [ 'some text', [], '<input type="text" id="htmltestmodel-title" name="HtmlTestModel[title]" value="some text">', '<input type="text" id="htmltestmodel-alias" name="HtmlTestModel[alias]" value="some text">', ], [ '', [ 'maxlength' => true, ], '<input type="text" id="htmltestmodel-title" name="HtmlTestModel[title]" value="" maxlength="10">', '<input type="text" id="htmltestmodel-alias" name="HtmlTestModel[alias]" value="" maxlength="20">', ], [ '', [ 'maxlength' => 99, ], '<input type="text" id="htmltestmodel-title" name="HtmlTestModel[title]" value="" maxlength="99">', '<input type="text" id="htmltestmodel-alias" name="HtmlTestModel[alias]" value="" maxlength="99">', ], ]; }
Data provider for [[testActiveTextInputMaxLength]]. @return array test data
dataProviderActiveTextInputMaxLength
php
yiisoft/yii2
tests/framework/helpers/HtmlTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/HtmlTest.php
BSD-3-Clause
public function dataProviderActivePasswordInput() { return [ [ 'some text', [], '<input type="password" id="htmltestmodel-name" name="HtmlTestModel[name]" value="some text">', ], [ '', [ 'maxlength' => true, ], '<input type="password" id="htmltestmodel-name" name="HtmlTestModel[name]" value="" maxlength="100">', ], [ '', [ 'maxlength' => 99, ], '<input type="password" id="htmltestmodel-name" name="HtmlTestModel[name]" value="" maxlength="99">', ], ]; }
Data provider for [[testActivePasswordInput()]]. @return array test data
dataProviderActivePasswordInput
php
yiisoft/yii2
tests/framework/helpers/HtmlTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/HtmlTest.php
BSD-3-Clause
public function dataProviderActiveInput_TypeText() { return [ [ 'some text', [], '<input type="text" id="htmltestmodel-name" name="HtmlTestModel[name]" value="some text">', ], [ '', [ 'maxlength' => true, ], '<input type="text" id="htmltestmodel-name" name="HtmlTestModel[name]" value="" maxlength="100">', ], [ '', [ 'maxlength' => 99, ], '<input type="text" id="htmltestmodel-name" name="HtmlTestModel[name]" value="" maxlength="99">', ], ]; }
Data provider for [[testActiveInput_TypeText]]. @return array test data
dataProviderActiveInput_TypeText
php
yiisoft/yii2
tests/framework/helpers/HtmlTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/HtmlTest.php
BSD-3-Clause
public function dataProviderActiveTextArea() { return [ [ 'some text', [], '<textarea id="htmltestmodel-description" name="HtmlTestModel[description]">some text</textarea>', ], [ 'some text', [ 'maxlength' => true, ], '<textarea id="htmltestmodel-description" name="HtmlTestModel[description]" maxlength="500">some text</textarea>', ], [ 'some text', [ 'maxlength' => 99, ], '<textarea id="htmltestmodel-description" name="HtmlTestModel[description]" maxlength="99">some text</textarea>', ], [ 'some text', [ 'value' => 'override text', ], '<textarea id="htmltestmodel-description" name="HtmlTestModel[description]">override text</textarea>', ], ]; }
Data provider for [[testActiveTextArea()]]. @return array test data
dataProviderActiveTextArea
php
yiisoft/yii2
tests/framework/helpers/HtmlTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/HtmlTest.php
BSD-3-Clause
public function validAttributeNamesProvider() { $data = [ ['asd]asdf.asdfa[asdfa', 'asdf.asdfa'], ['a', 'a'], ['[0]a', 'a'], ['a[0]', 'a'], ['[0]a[0]', 'a'], ['[0]a.[0]', 'a.'], ['ä', 'ä'], ['ä', 'ä'], ['asdf]öáöio..[asdfasdf', 'öáöio..'], ['öáöio', 'öáöio'], ['[0]test.ööößß.d', 'test.ööößß.d'], ['ИІК', 'ИІК'], [']ИІК[', 'ИІК'], ['[0]ИІК[0]', 'ИІК'], ]; return $data; }
Data provider for [[testAttributeNameValidation()]]. @return array test data
validAttributeNamesProvider
php
yiisoft/yii2
tests/framework/helpers/HtmlTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/HtmlTest.php
BSD-3-Clause
public function dataProviderExport() { // Regular : $data = [ [ 'test string', var_export('test string', true), ], [ 75, var_export(75, true), ], [ 7.5, var_export(7.5, true), ], [ null, 'null', ], [ true, 'true', ], [ false, 'false', ], [ [], '[]', ], ]; // Arrays : $var = [ 'key1' => 'value1', 'key2' => 'value2', ]; $expectedResult = <<<'RESULT' [ 'key1' => 'value1', 'key2' => 'value2', ] RESULT; $data[] = [$var, $expectedResult]; $var = [ 'value1', 'value2', ]; $expectedResult = <<<'RESULT' [ 'value1', 'value2', ] RESULT; $data[] = [$var, $expectedResult]; $var = [ 'key1' => [ 'subkey1' => 'value2', ], 'key2' => [ 'subkey2' => 'value3', ], ]; $expectedResult = <<<'RESULT' [ 'key1' => [ 'subkey1' => 'value2', ], 'key2' => [ 'subkey2' => 'value3', ], ] RESULT; $data[] = [$var, $expectedResult]; // Objects : $var = new \StdClass(); $var->testField = 'Test Value'; $expectedResult = "unserialize('" . serialize($var) . "')"; $data[] = [$var, $expectedResult]; $var = function () {return 2;}; $expectedResult = 'function () {return 2;}'; $data[] = [$var, $expectedResult]; return $data; }
Data provider for [[testExport()]]. @return array test data
dataProviderExport
php
yiisoft/yii2
tests/framework/helpers/VarDumperTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/VarDumperTest.php
BSD-3-Clause
private function isChmodReliable() { $dir = $this->testFilePath . DIRECTORY_SEPARATOR . 'test_chmod'; mkdir($dir); chmod($dir, 0700); $mode = $this->getMode($dir); rmdir($dir); return $mode === '0700'; }
Check if chmod works as expected On remote file systems and vagrant mounts chmod returns true but file permissions are not set properly.
isChmodReliable
php
yiisoft/yii2
tests/framework/helpers/FileHelperTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/FileHelperTest.php
BSD-3-Clause
protected function createFileStructure(array $items, $basePath = '') { if (empty($basePath)) { $basePath = $this->testFilePath; } foreach ($items as $name => $content) { $itemName = $basePath . DIRECTORY_SEPARATOR . $name; if (is_array($content)) { if (isset($content[0], $content[1]) && $content[0] === 'symlink') { symlink($content[1], $itemName); } else { mkdir($itemName, 0777, true); $this->createFileStructure($content, $itemName); } } else { file_put_contents($itemName, $content); } } }
Creates test files structure. @param array $items file system objects to be created in format: objectName => objectContent Arrays specifies directories, other values - files. @param string $basePath structure base file path.
createFileStructure
php
yiisoft/yii2
tests/framework/helpers/FileHelperTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/FileHelperTest.php
BSD-3-Clause
protected function assertFileMode($expectedMode, $fileName, $message = '') { $expectedMode = sprintf('%04o', $expectedMode); $this->assertEquals($expectedMode, $this->getMode($fileName), $message); }
Asserts that file has specific permission mode. @param int $expectedMode expected file permission mode. @param string $fileName file name. @param string $message error message
assertFileMode
php
yiisoft/yii2
tests/framework/helpers/FileHelperTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/FileHelperTest.php
BSD-3-Clause
public function providerStartsWith() { return [ // positive check [true, '', ''], [true, '', null], [true, 'string', ''], [true, ' string', ' '], [true, 'abc', 'abc'], [true, 'Bürger', 'Bürger'], [true, '我Я multibyte', '我Я'], [true, 'Qנטשופ צרכנות', 'Qנ'], [true, 'ไทย.idn.icann.org', 'ไ'], [true, '!?+', "\x21\x3F"], [true, "\x21?+", '!?'], // false-positive check [false, '', ' '], [false, ' ', ' '], [false, 'Abc', 'Abcde'], [false, 'abc', 'abe'], [false, 'abc', 'b'], [false, 'abc', 'c'], ]; }
Rules that should work the same for case-sensitive and case-insensitive `startsWith()`.
providerStartsWith
php
yiisoft/yii2
tests/framework/helpers/StringHelperTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/StringHelperTest.php
BSD-3-Clause
public function providerEndsWith() { return [ // positive check [true, '', ''], [true, '', null], [true, 'string', ''], [true, 'string ', ' '], [true, 'string', 'g'], [true, 'abc', 'abc'], [true, 'Bürger', 'Bürger'], [true, 'Я multibyte строка我!', ' строка我!'], [true, '+!?', "\x21\x3F"], [true, "+\x21?", "!\x3F"], [true, 'נטשופ צרכנות', 'ת'], // false-positive check [false, '', ' '], [false, ' ', ' '], [false, 'aaa', 'aaaa'], [false, 'abc', 'abe'], [false, 'abc', 'a'], [false, 'abc', 'b'], ]; }
Rules that should work the same for case-sensitive and case-insensitive `endsWith()`.
providerEndsWith
php
yiisoft/yii2
tests/framework/helpers/StringHelperTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/helpers/StringHelperTest.php
BSD-3-Clause
public function matchRoleProvider() { return [ ['create', true, 'user1', [], true], ['create', true, 'user2', [], true], ['create', true, 'user3', [], null], ['create', true, 'unknown', [], null], ['create', false, 'user1', [], false], ['create', false, 'user2', [], false], ['create', false, 'user3', [], null], ['create', false, 'unknown', [], null], // user2 is author, can only edit own posts ['update', true, 'user2', ['authorID' => 'user2'], true], ['update', true, 'user2', ['authorID' => 'user1'], null], // user1 is admin, can update all posts ['update', true, 'user1', ['authorID' => 'user1'], true], ['update', true, 'user1', ['authorID' => 'user2'], true], // unknown user can not edit anything ['update', true, 'unknown', ['authorID' => 'user1'], null], ['update', true, 'unknown', ['authorID' => 'user2'], null], // user2 is author, can only edit own posts ['update', true, 'user2', function () { return ['authorID' => 'user2']; }, true], ['update', true, 'user2', function () { return ['authorID' => 'user1']; }, null], // user1 is admin, can update all posts ['update', true, 'user1', function () { return ['authorID' => 'user1']; }, true], ['update', true, 'user1', function () { return ['authorID' => 'user2']; }, true], // unknown user can not edit anything ['update', true, 'unknown', function () { return ['authorID' => 'user1']; }, null], ['update', true, 'unknown', function () { return ['authorID' => 'user2']; }, null], ]; }
Data provider for testMatchRole. @return array or arrays the id of the action should the action allow (true) or disallow (false) test user id expected match result (true, false, null)
matchRoleProvider
php
yiisoft/yii2
tests/framework/filters/AccessRuleTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/filters/AccessRuleTest.php
BSD-3-Clause
protected function createFilter($authenticateCallback) { $filter = $this->getMockBuilder(AuthMethod::className()) ->setMethods(['authenticate']) ->getMock(); $filter->method('authenticate')->willReturnCallback($authenticateCallback); return $filter; }
Creates mock for [[AuthMethod]] filter. @param callable $authenticateCallback callback, which result should [[authenticate()]] method return. @return AuthMethod filter instance.
createFilter
php
yiisoft/yii2
tests/framework/filters/auth/AuthMethodTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/filters/auth/AuthMethodTest.php
BSD-3-Clause
function filemtime($file) { return \yiiunit\framework\rbac\PhpManagerTest::$filemtime ?: \filemtime($file); }
Mock for the filemtime() function for rbac classes. Avoid random test fails. @param string $file @return int
filemtime
php
yiisoft/yii2
tests/framework/rbac/PhpManagerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/rbac/PhpManagerTest.php
BSD-3-Clause
function time() { return \yiiunit\framework\rbac\PhpManagerTest::$time ?: \time(); }
Mock for the time() function for rbac classes. Avoid random test fails. @return int
time
php
yiisoft/yii2
tests/framework/rbac/PhpManagerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/rbac/PhpManagerTest.php
BSD-3-Clause
private function createRBACItem($RBACItemType, $name) { if ($RBACItemType === Item::TYPE_ROLE) { return $this->auth->createRole($name); } if ($RBACItemType === Item::TYPE_PERMISSION) { return $this->auth->createPermission($name); } throw new \InvalidArgumentException(); }
Create Role or Permission RBAC item. @param int $RBACItemType @param string $name @return Permission|Role
createRBACItem
php
yiisoft/yii2
tests/framework/rbac/ManagerTestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/rbac/ManagerTestCase.php
BSD-3-Clause
private function getRBACItem($RBACItemType, $name) { if ($RBACItemType === Item::TYPE_ROLE) { return $this->auth->getRole($name); } if ($RBACItemType === Item::TYPE_PERMISSION) { return $this->auth->getPermission($name); } throw new \InvalidArgumentException(); }
Get Role or Permission RBAC item. @param int $RBACItemType @param string $name @return Permission|Role
getRBACItem
php
yiisoft/yii2
tests/framework/rbac/ManagerTestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/rbac/ManagerTestCase.php
BSD-3-Clause
private function initializeApplicationMock() { $this->mockApplication([ 'components' => [ 'cache' => [ 'class' => '\yii\caching\ArrayCache', ], ], 'params' => [ // Counter for dynamic contents testing. 'counter' => 0, ], ]); }
Initializes a mock application.
initializeApplicationMock
php
yiisoft/yii2
tests/framework/behaviors/CacheableWidgetBehaviorTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/behaviors/CacheableWidgetBehaviorTest.php
BSD-3-Clause
function time() { return \yiiunit\framework\caching\CacheTestCase::$time ?: \time(); }
Mock for the time() function for caching classes. @return int
time
php
yiisoft/yii2
tests/framework/caching/CacheTestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/caching/CacheTestCase.php
BSD-3-Clause
function microtime($float = false) { return \yiiunit\framework\caching\CacheTestCase::$microtime ?: \microtime($float); }
Mock for the microtime() function for caching classes. @param bool $float @return float
microtime
php
yiisoft/yii2
tests/framework/caching/CacheTestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/caching/CacheTestCase.php
BSD-3-Clause
public function getClientOptions() { return ($this->getClientOptionsEmpty) ? [] : parent::getClientOptions(); }
Useful to test other methods from ActiveField, that call ActiveField::getClientOptions() but it's return value is not relevant for the test being run.
getClientOptions
php
yiisoft/yii2
tests/framework/widgets/ActiveFieldTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/widgets/ActiveFieldTest.php
BSD-3-Clause
private function checkOldIcuBug() { $date = '14'; $formatter = new IntlDateFormatter('en-US', IntlDateFormatter::NONE, IntlDateFormatter::NONE, null, null, 'yyyy'); $parsePos = 0; $parsedDate = @$formatter->parse($date, $parsePos); if (is_int($parsedDate) && $parsedDate > 0) { return true; } return false; }
Returns true if the version of ICU is old and has a bug that makes it impossible to parse two digit years properly. @see https://unicode-org.atlassian.net/browse/ICU-9836 @return bool
checkOldIcuBug
php
yiisoft/yii2
tests/framework/validators/DateValidatorTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/validators/DateValidatorTest.php
BSD-3-Clause
protected function replaceQuotes($sql) { switch ($this->driverName) { case 'mysql': case 'sqlite': return str_replace(['[[', ']]'], '`', $sql); case 'cubrid': case 'oci': return str_replace(['[[', ']]'], '"', $sql); case 'pgsql': // more complex replacement needed to not conflict with postgres array syntax return str_replace(['\\[', '\\]'], ['[', ']'], preg_replace('/(\[\[)|((?<!(\[))\]\])/', '"', $sql)); case 'sqlsrv': return str_replace(['[[', ']]'], ['[', ']'], $sql); default: return $sql; } }
Adjust dbms specific escaping. @param $sql @return mixed
replaceQuotes
php
yiisoft/yii2
tests/framework/db/DatabaseTestCase.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/db/DatabaseTestCase.php
BSD-3-Clause
public function invalidSelectColumns() { return [ [[]], ['*'], [['*']], ]; }
Data provider for testInsertSelectFailed. @return array
invalidSelectColumns
php
yiisoft/yii2
tests/framework/db/CommandTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/db/CommandTest.php
BSD-3-Clause
public function columnTypes() { $items = [ [ Schema::TYPE_BIGINT, $this->bigInteger(), [ 'mysql' => 'bigint(20)', 'pgsql' => 'bigint', 'sqlite' => 'bigint', 'oci' => 'NUMBER(20)', 'sqlsrv' => 'bigint', 'cubrid' => 'bigint', ], ], [ Schema::TYPE_BIGINT . ' NOT NULL', $this->bigInteger()->notNull(), [ 'mysql' => 'bigint(20) NOT NULL', 'pgsql' => 'bigint NOT NULL', 'sqlite' => 'bigint NOT NULL', 'oci' => 'NUMBER(20) NOT NULL', 'sqlsrv' => 'bigint NOT NULL', 'cubrid' => 'bigint NOT NULL', ], ], [ Schema::TYPE_BIGINT . ' CHECK (value > 5)', $this->bigInteger()->check('value > 5'), [ 'mysql' => 'bigint(20) CHECK (value > 5)', 'pgsql' => 'bigint CHECK (value > 5)', 'sqlite' => 'bigint CHECK (value > 5)', 'oci' => 'NUMBER(20) CHECK (value > 5)', 'sqlsrv' => 'bigint CHECK (value > 5)', 'cubrid' => 'bigint CHECK (value > 5)', ], ], [ Schema::TYPE_BIGINT . '(8)', $this->bigInteger(8), [ 'mysql' => 'bigint(8)', 'pgsql' => 'bigint', 'sqlite' => 'bigint', 'oci' => 'NUMBER(8)', 'sqlsrv' => 'bigint', 'cubrid' => 'bigint', ], ], [ Schema::TYPE_BIGINT . '(8) CHECK (value > 5)', $this->bigInteger(8)->check('value > 5'), [ 'mysql' => 'bigint(8) CHECK (value > 5)', 'pgsql' => 'bigint CHECK (value > 5)', 'sqlite' => 'bigint CHECK (value > 5)', 'oci' => 'NUMBER(8) CHECK (value > 5)', 'sqlsrv' => 'bigint CHECK (value > 5)', 'cubrid' => 'bigint CHECK (value > 5)', ], ], [ Schema::TYPE_BIGPK, $this->bigPrimaryKey(), [ 'mysql' => 'bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY', 'pgsql' => 'bigserial NOT NULL PRIMARY KEY', 'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', ], ], [ Schema::TYPE_BINARY, $this->binary(), [ 'mysql' => 'blob', 'pgsql' => 'bytea', 'sqlite' => 'blob', 'oci' => 'BLOB', 'sqlsrv' => 'varbinary(max)', 'cubrid' => 'blob', ], ], [ Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', $this->boolean()->notNull()->defaultValue(1), [ 'mysql' => 'tinyint(1) NOT NULL DEFAULT 1', 'sqlite' => 'boolean NOT NULL DEFAULT 1', 'sqlsrv' => 'bit NOT NULL DEFAULT 1', 'cubrid' => 'smallint NOT NULL DEFAULT 1', ], ], [ Schema::TYPE_BOOLEAN, $this->boolean(), [ 'mysql' => 'tinyint(1)', 'pgsql' => 'boolean', 'sqlite' => 'boolean', 'oci' => 'NUMBER(1)', 'sqlsrv' => 'bit', 'cubrid' => 'smallint', ], ], [ Schema::TYPE_CHAR . ' CHECK (value LIKE "test%")', $this->char()->check('value LIKE "test%"'), [ 'mysql' => 'char(1) CHECK (value LIKE "test%")', 'sqlite' => 'char(1) CHECK (value LIKE "test%")', 'cubrid' => 'char(1) CHECK (value LIKE "test%")', ], ], [ Schema::TYPE_CHAR . ' NOT NULL', $this->char()->notNull(), [ 'mysql' => 'char(1) NOT NULL', 'pgsql' => 'char(1) NOT NULL', 'sqlite' => 'char(1) NOT NULL', 'oci' => 'CHAR(1) NOT NULL', 'cubrid' => 'char(1) NOT NULL', ], ], [ Schema::TYPE_CHAR . '(6) CHECK (value LIKE "test%")', $this->char(6)->check('value LIKE "test%"'), [ 'mysql' => 'char(6) CHECK (value LIKE "test%")', 'sqlite' => 'char(6) CHECK (value LIKE "test%")', 'cubrid' => 'char(6) CHECK (value LIKE "test%")', ], ], [ Schema::TYPE_CHAR . '(6)', $this->char(6), [ 'mysql' => 'char(6)', 'pgsql' => 'char(6)', 'sqlite' => 'char(6)', 'oci' => 'CHAR(6)', 'cubrid' => 'char(6)', ], ], [ Schema::TYPE_CHAR, $this->char(), [ 'mysql' => 'char(1)', 'pgsql' => 'char(1)', 'sqlite' => 'char(1)', 'oci' => 'CHAR(1)', 'cubrid' => 'char(1)', ], ], //[ // Schema::TYPE_DATE . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", // $this->date()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), // [ // 'mysql' => , // 'pgsql' => , // 'sqlite' => , // 'sqlsrv' => , // 'cubrid' => , // ], //], [ Schema::TYPE_DATE . ' NOT NULL', $this->date()->notNull(), [ 'mysql' => 'date NOT NULL', 'pgsql' => 'date NOT NULL', 'sqlite' => 'date NOT NULL', 'oci' => 'DATE NOT NULL', 'sqlsrv' => 'date NOT NULL', 'cubrid' => 'date NOT NULL', ], ], [ Schema::TYPE_DATE, $this->date(), [ 'mysql' => 'date', 'pgsql' => 'date', 'sqlite' => 'date', 'oci' => 'DATE', 'sqlsrv' => 'date', 'cubrid' => 'date', ], ], //[ // Schema::TYPE_DATETIME . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", // $this->dateTime()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), // [ // 'mysql' => , // 'pgsql' => , // 'sqlite' => , // 'sqlsrv' => , // 'cubrid' => , // ], //], [ Schema::TYPE_DATETIME . ' NOT NULL', $this->dateTime()->notNull(), [ 'pgsql' => 'timestamp(0) NOT NULL', 'sqlite' => 'datetime NOT NULL', 'oci' => 'TIMESTAMP NOT NULL', 'sqlsrv' => 'datetime NOT NULL', 'cubrid' => 'datetime NOT NULL', ], ], [ Schema::TYPE_DATETIME, $this->dateTime(), [ 'pgsql' => 'timestamp(0)', 'sqlite' => 'datetime', 'oci' => 'TIMESTAMP', 'sqlsrv' => 'datetime', 'cubrid' => 'datetime', ], ], [ Schema::TYPE_DECIMAL . ' CHECK (value > 5.6)', $this->decimal()->check('value > 5.6'), [ 'mysql' => 'decimal(10,0) CHECK (value > 5.6)', 'pgsql' => 'numeric(10,0) CHECK (value > 5.6)', 'sqlite' => 'decimal(10,0) CHECK (value > 5.6)', 'oci' => 'NUMBER CHECK (value > 5.6)', 'sqlsrv' => 'decimal(18,0) CHECK (value > 5.6)', 'cubrid' => 'decimal(10,0) CHECK (value > 5.6)', ], ], [ Schema::TYPE_DECIMAL . ' NOT NULL', $this->decimal()->notNull(), [ 'mysql' => 'decimal(10,0) NOT NULL', 'pgsql' => 'numeric(10,0) NOT NULL', 'sqlite' => 'decimal(10,0) NOT NULL', 'oci' => 'NUMBER NOT NULL', 'sqlsrv' => 'decimal(18,0) NOT NULL', 'cubrid' => 'decimal(10,0) NOT NULL', ], ], [ Schema::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)', $this->decimal(12, 4)->check('value > 5.6'), [ 'mysql' => 'decimal(12,4) CHECK (value > 5.6)', 'pgsql' => 'numeric(12,4) CHECK (value > 5.6)', 'sqlite' => 'decimal(12,4) CHECK (value > 5.6)', 'oci' => 'NUMBER CHECK (value > 5.6)', 'sqlsrv' => 'decimal(12,4) CHECK (value > 5.6)', 'cubrid' => 'decimal(12,4) CHECK (value > 5.6)', ], ], [ Schema::TYPE_DECIMAL . '(12,4)', $this->decimal(12, 4), [ 'mysql' => 'decimal(12,4)', 'pgsql' => 'numeric(12,4)', 'sqlite' => 'decimal(12,4)', 'oci' => 'NUMBER', 'sqlsrv' => 'decimal(12,4)', 'cubrid' => 'decimal(12,4)', ], ], [ Schema::TYPE_DECIMAL, $this->decimal(), [ 'mysql' => 'decimal(10,0)', 'pgsql' => 'numeric(10,0)', 'sqlite' => 'decimal(10,0)', 'oci' => 'NUMBER', 'sqlsrv' => 'decimal(18,0)', 'cubrid' => 'decimal(10,0)', ], ], [ Schema::TYPE_DOUBLE . ' CHECK (value > 5.6)', $this->double()->check('value > 5.6'), [ 'mysql' => 'double CHECK (value > 5.6)', 'pgsql' => 'double precision CHECK (value > 5.6)', 'sqlite' => 'double CHECK (value > 5.6)', 'oci' => 'NUMBER CHECK (value > 5.6)', 'sqlsrv' => 'float CHECK (value > 5.6)', 'cubrid' => 'double(15) CHECK (value > 5.6)', ], ], [ Schema::TYPE_DOUBLE . ' NOT NULL', $this->double()->notNull(), [ 'mysql' => 'double NOT NULL', 'pgsql' => 'double precision NOT NULL', 'sqlite' => 'double NOT NULL', 'oci' => 'NUMBER NOT NULL', 'sqlsrv' => 'float NOT NULL', 'cubrid' => 'double(15) NOT NULL', ], ], [ Schema::TYPE_DOUBLE . '(16) CHECK (value > 5.6)', $this->double(16)->check('value > 5.6'), [ 'mysql' => 'double CHECK (value > 5.6)', 'pgsql' => 'double precision CHECK (value > 5.6)', 'sqlite' => 'double CHECK (value > 5.6)', 'oci' => 'NUMBER CHECK (value > 5.6)', 'sqlsrv' => 'float CHECK (value > 5.6)', 'cubrid' => 'double(16) CHECK (value > 5.6)', ], ], [ Schema::TYPE_DOUBLE . '(16)', $this->double(16), [ 'mysql' => 'double', 'sqlite' => 'double', 'oci' => 'NUMBER', 'sqlsrv' => 'float', 'cubrid' => 'double(16)', ], ], [ Schema::TYPE_DOUBLE, $this->double(), [ 'mysql' => 'double', 'pgsql' => 'double precision', 'sqlite' => 'double', 'oci' => 'NUMBER', 'sqlsrv' => 'float', 'cubrid' => 'double(15)', ], ], [ Schema::TYPE_FLOAT . ' CHECK (value > 5.6)', $this->float()->check('value > 5.6'), [ 'mysql' => 'float CHECK (value > 5.6)', 'pgsql' => 'double precision CHECK (value > 5.6)', 'sqlite' => 'float CHECK (value > 5.6)', 'oci' => 'NUMBER CHECK (value > 5.6)', 'sqlsrv' => 'float CHECK (value > 5.6)', 'cubrid' => 'float(7) CHECK (value > 5.6)', ], ], [ Schema::TYPE_FLOAT . ' NOT NULL', $this->float()->notNull(), [ 'mysql' => 'float NOT NULL', 'pgsql' => 'double precision NOT NULL', 'sqlite' => 'float NOT NULL', 'oci' => 'NUMBER NOT NULL', 'sqlsrv' => 'float NOT NULL', 'cubrid' => 'float(7) NOT NULL', ], ], [ Schema::TYPE_FLOAT . '(16) CHECK (value > 5.6)', $this->float(16)->check('value > 5.6'), [ 'mysql' => 'float CHECK (value > 5.6)', 'pgsql' => 'double precision CHECK (value > 5.6)', 'sqlite' => 'float CHECK (value > 5.6)', 'oci' => 'NUMBER CHECK (value > 5.6)', 'sqlsrv' => 'float CHECK (value > 5.6)', 'cubrid' => 'float(16) CHECK (value > 5.6)', ], ], [ Schema::TYPE_FLOAT . '(16)', $this->float(16), [ 'mysql' => 'float', 'sqlite' => 'float', 'oci' => 'NUMBER', 'sqlsrv' => 'float', 'cubrid' => 'float(16)', ], ], [ Schema::TYPE_FLOAT, $this->float(), [ 'mysql' => 'float', 'pgsql' => 'double precision', 'sqlite' => 'float', 'oci' => 'NUMBER', 'sqlsrv' => 'float', 'cubrid' => 'float(7)', ], ], [ Schema::TYPE_INTEGER . ' CHECK (value > 5)', $this->integer()->check('value > 5'), [ 'mysql' => 'int(11) CHECK (value > 5)', 'pgsql' => 'integer CHECK (value > 5)', 'sqlite' => 'integer CHECK (value > 5)', 'oci' => 'NUMBER(10) CHECK (value > 5)', 'sqlsrv' => 'int CHECK (value > 5)', 'cubrid' => 'int CHECK (value > 5)', ], ], [ Schema::TYPE_INTEGER . ' NOT NULL', $this->integer()->notNull(), [ 'mysql' => 'int(11) NOT NULL', 'pgsql' => 'integer NOT NULL', 'sqlite' => 'integer NOT NULL', 'oci' => 'NUMBER(10) NOT NULL', 'sqlsrv' => 'int NOT NULL', 'cubrid' => 'int NOT NULL', ], ], [ Schema::TYPE_INTEGER . '(8) CHECK (value > 5)', $this->integer(8)->check('value > 5'), [ 'mysql' => 'int(8) CHECK (value > 5)', 'pgsql' => 'integer CHECK (value > 5)', 'sqlite' => 'integer CHECK (value > 5)', 'oci' => 'NUMBER(8) CHECK (value > 5)', 'sqlsrv' => 'int CHECK (value > 5)', 'cubrid' => 'int CHECK (value > 5)', ], ], [ Schema::TYPE_INTEGER . '(8)', $this->integer(8), [ 'mysql' => 'int(8)', 'pgsql' => 'integer', 'sqlite' => 'integer', 'oci' => 'NUMBER(8)', 'sqlsrv' => 'int', 'cubrid' => 'int', ], ], [ Schema::TYPE_INTEGER, $this->integer(), [ 'mysql' => 'int(11)', 'pgsql' => 'integer', 'sqlite' => 'integer', 'oci' => 'NUMBER(10)', 'sqlsrv' => 'int', 'cubrid' => 'int', ], ], [ Schema::TYPE_MONEY . ' CHECK (value > 0.0)', $this->money()->check('value > 0.0'), [ 'mysql' => 'decimal(19,4) CHECK (value > 0.0)', 'pgsql' => 'numeric(19,4) CHECK (value > 0.0)', 'sqlite' => 'decimal(19,4) CHECK (value > 0.0)', 'oci' => 'NUMBER(19,4) CHECK (value > 0.0)', 'sqlsrv' => 'decimal(19,4) CHECK (value > 0.0)', 'cubrid' => 'decimal(19,4) CHECK (value > 0.0)', ], ], [ Schema::TYPE_MONEY . ' NOT NULL', $this->money()->notNull(), [ 'mysql' => 'decimal(19,4) NOT NULL', 'pgsql' => 'numeric(19,4) NOT NULL', 'sqlite' => 'decimal(19,4) NOT NULL', 'oci' => 'NUMBER(19,4) NOT NULL', 'sqlsrv' => 'decimal(19,4) NOT NULL', 'cubrid' => 'decimal(19,4) NOT NULL', ], ], [ Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)', $this->money(16, 2)->check('value > 0.0'), [ 'mysql' => 'decimal(16,2) CHECK (value > 0.0)', 'pgsql' => 'numeric(16,2) CHECK (value > 0.0)', 'sqlite' => 'decimal(16,2) CHECK (value > 0.0)', 'oci' => 'NUMBER(16,2) CHECK (value > 0.0)', 'sqlsrv' => 'decimal(16,2) CHECK (value > 0.0)', 'cubrid' => 'decimal(16,2) CHECK (value > 0.0)', ], ], [ Schema::TYPE_MONEY . '(16,2)', $this->money(16, 2), [ 'mysql' => 'decimal(16,2)', 'pgsql' => 'numeric(16,2)', 'sqlite' => 'decimal(16,2)', 'oci' => 'NUMBER(16,2)', 'sqlsrv' => 'decimal(16,2)', 'cubrid' => 'decimal(16,2)', ], ], [ Schema::TYPE_MONEY, $this->money(), [ 'mysql' => 'decimal(19,4)', 'pgsql' => 'numeric(19,4)', 'sqlite' => 'decimal(19,4)', 'oci' => 'NUMBER(19,4)', 'sqlsrv' => 'decimal(19,4)', 'cubrid' => 'decimal(19,4)', ], ], [ Schema::TYPE_PK . ' CHECK (value > 5)', $this->primaryKey()->check('value > 5'), [ 'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)', 'pgsql' => 'serial NOT NULL PRIMARY KEY CHECK (value > 5)', 'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL CHECK (value > 5)', 'oci' => 'NUMBER(10) NOT NULL PRIMARY KEY CHECK (value > 5)', 'sqlsrv' => 'int IDENTITY PRIMARY KEY CHECK (value > 5)', 'cubrid' => 'int NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)', ], ], [ Schema::TYPE_PK . '(8) CHECK (value > 5)', $this->primaryKey(8)->check('value > 5'), [ 'mysql' => 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)', 'oci' => 'NUMBER(8) NOT NULL PRIMARY KEY CHECK (value > 5)', ], ], [ Schema::TYPE_PK . '(8)', $this->primaryKey(8), [ 'mysql' => 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY', 'oci' => 'NUMBER(8) NOT NULL PRIMARY KEY', ], ], [ Schema::TYPE_PK, $this->primaryKey(), [ 'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY', 'pgsql' => 'serial NOT NULL PRIMARY KEY', 'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', 'oci' => 'NUMBER(10) NOT NULL PRIMARY KEY', 'sqlsrv' => 'int IDENTITY PRIMARY KEY', 'cubrid' => 'int NOT NULL AUTO_INCREMENT PRIMARY KEY', ], ], [ Schema::TYPE_TINYINT . '(2)', $this->tinyInteger(2), [ 'mysql' => 'tinyint(2)', 'pgsql' => 'smallint', 'sqlite' => 'tinyint', 'oci' => 'NUMBER(2)', 'sqlsrv' => 'tinyint', 'cubrid' => 'smallint', ], ], [ Schema::TYPE_TINYINT . ' UNSIGNED', $this->tinyInteger()->unsigned(), [ 'mysql' => 'tinyint(3) UNSIGNED', 'sqlite' => 'tinyint UNSIGNED', 'cubrid' => 'smallint UNSIGNED', ] ], [ Schema::TYPE_TINYINT, $this->tinyInteger(), [ 'mysql' => 'tinyint(3)', 'pgsql' => 'smallint', 'sqlite' => 'tinyint', 'oci' => 'NUMBER(3)', 'sqlsrv' => 'tinyint', 'cubrid' => 'smallint', ], ], [ Schema::TYPE_SMALLINT . '(8)', $this->smallInteger(8), [ 'mysql' => 'smallint(8)', 'pgsql' => 'smallint', 'sqlite' => 'smallint', 'oci' => 'NUMBER(8)', 'sqlsrv' => 'smallint', 'cubrid' => 'smallint', ], ], [ Schema::TYPE_SMALLINT, $this->smallInteger(), [ 'mysql' => 'smallint(6)', 'pgsql' => 'smallint', 'sqlite' => 'smallint', 'oci' => 'NUMBER(5)', 'sqlsrv' => 'smallint', 'cubrid' => 'smallint', ], ], [ Schema::TYPE_STRING . " CHECK (value LIKE 'test%')", $this->string()->check("value LIKE 'test%'"), [ 'mysql' => "varchar(255) CHECK (value LIKE 'test%')", 'sqlite' => "varchar(255) CHECK (value LIKE 'test%')", 'sqlsrv' => "nvarchar(255) CHECK (value LIKE 'test%')", 'cubrid' => "varchar(255) CHECK (value LIKE 'test%')", ], ], [ Schema::TYPE_STRING . ' CHECK (value LIKE \'test%\')', $this->string()->check('value LIKE \'test%\''), [ 'pgsql' => 'varchar(255) CHECK (value LIKE \'test%\')', 'oci' => 'VARCHAR2(255) CHECK (value LIKE \'test%\')', ], ], [ Schema::TYPE_STRING . ' NOT NULL', $this->string()->notNull(), [ 'mysql' => 'varchar(255) NOT NULL', 'pgsql' => 'varchar(255) NOT NULL', 'sqlite' => 'varchar(255) NOT NULL', 'oci' => 'VARCHAR2(255) NOT NULL', 'sqlsrv' => 'nvarchar(255) NOT NULL', 'cubrid' => 'varchar(255) NOT NULL', ], ], [ Schema::TYPE_STRING . "(32) CHECK (value LIKE 'test%')", $this->string(32)->check("value LIKE 'test%'"), [ 'mysql' => "varchar(32) CHECK (value LIKE 'test%')", 'sqlite' => "varchar(32) CHECK (value LIKE 'test%')", 'sqlsrv' => "nvarchar(32) CHECK (value LIKE 'test%')", 'cubrid' => "varchar(32) CHECK (value LIKE 'test%')", ], ], [ Schema::TYPE_STRING . '(32) CHECK (value LIKE \'test%\')', $this->string(32)->check('value LIKE \'test%\''), [ 'pgsql' => 'varchar(32) CHECK (value LIKE \'test%\')', 'oci' => 'VARCHAR2(32) CHECK (value LIKE \'test%\')', ], ], [ Schema::TYPE_STRING . '(32)', $this->string(32), [ 'mysql' => 'varchar(32)', 'pgsql' => 'varchar(32)', 'sqlite' => 'varchar(32)', 'oci' => 'VARCHAR2(32)', 'sqlsrv' => 'nvarchar(32)', 'cubrid' => 'varchar(32)', ], ], [ Schema::TYPE_STRING, $this->string(), [ 'mysql' => 'varchar(255)', 'pgsql' => 'varchar(255)', 'sqlite' => 'varchar(255)', 'oci' => 'VARCHAR2(255)', 'sqlsrv' => 'nvarchar(255)', 'cubrid' => 'varchar(255)', ], ], [ Schema::TYPE_TEXT . " CHECK (value LIKE 'test%')", $this->text()->check("value LIKE 'test%'"), [ 'mysql' => "text CHECK (value LIKE 'test%')", 'sqlite' => "text CHECK (value LIKE 'test%')", 'sqlsrv' => "nvarchar(max) CHECK (value LIKE 'test%')", 'cubrid' => "varchar CHECK (value LIKE 'test%')", ], ], [ Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')', $this->text()->check('value LIKE \'test%\''), [ 'pgsql' => 'text CHECK (value LIKE \'test%\')', 'oci' => 'CLOB CHECK (value LIKE \'test%\')', ], ], [ Schema::TYPE_TEXT . ' NOT NULL', $this->text()->notNull(), [ 'mysql' => 'text NOT NULL', 'pgsql' => 'text NOT NULL', 'sqlite' => 'text NOT NULL', 'oci' => 'CLOB NOT NULL', 'sqlsrv' => 'nvarchar(max) NOT NULL', 'cubrid' => 'varchar NOT NULL', ], ], [ Schema::TYPE_TEXT . " CHECK (value LIKE 'test%')", $this->text()->check("value LIKE 'test%'"), [ 'mysql' => "text CHECK (value LIKE 'test%')", 'sqlite' => "text CHECK (value LIKE 'test%')", 'sqlsrv' => "nvarchar(max) CHECK (value LIKE 'test%')", 'cubrid' => "varchar CHECK (value LIKE 'test%')", ], Schema::TYPE_TEXT . " CHECK (value LIKE 'test%')", ], [ Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')', $this->text()->check('value LIKE \'test%\''), [ 'pgsql' => 'text CHECK (value LIKE \'test%\')', 'oci' => 'CLOB CHECK (value LIKE \'test%\')', ], Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')', ], [ Schema::TYPE_TEXT . ' NOT NULL', $this->text()->notNull(), [ 'mysql' => 'text NOT NULL', 'pgsql' => 'text NOT NULL', 'sqlite' => 'text NOT NULL', 'oci' => 'CLOB NOT NULL', 'sqlsrv' => 'nvarchar(max) NOT NULL', 'cubrid' => 'varchar NOT NULL', ], Schema::TYPE_TEXT . ' NOT NULL', ], [ Schema::TYPE_TEXT, $this->text(), [ 'mysql' => 'text', 'pgsql' => 'text', 'sqlite' => 'text', 'oci' => 'CLOB', 'sqlsrv' => 'nvarchar(max)', 'cubrid' => 'varchar', ], Schema::TYPE_TEXT, ], [ Schema::TYPE_TEXT, $this->text(), [ 'mysql' => 'text', 'pgsql' => 'text', 'sqlite' => 'text', 'oci' => 'CLOB', 'sqlsrv' => 'nvarchar(max)', 'cubrid' => 'varchar', ], ], //[ // Schema::TYPE_TIME . " CHECK (value BETWEEN '12:00:00' AND '13:01:01')", // $this->time()->check("value BETWEEN '12:00:00' AND '13:01:01'"), // [ // 'mysql' => , // 'pgsql' => , // 'sqlite' => , // 'sqlsrv' => , // 'cubrid' => , // ], //], [ Schema::TYPE_TIME . ' NOT NULL', $this->time()->notNull(), [ 'pgsql' => 'time(0) NOT NULL', 'sqlite' => 'time NOT NULL', 'oci' => 'TIMESTAMP NOT NULL', 'sqlsrv' => 'time NOT NULL', 'cubrid' => 'time NOT NULL', ], ], [ Schema::TYPE_TIME, $this->time(), [ 'pgsql' => 'time(0)', 'sqlite' => 'time', 'oci' => 'TIMESTAMP', 'sqlsrv' => 'time', 'cubrid' => 'time', ], ], //[ // Schema::TYPE_TIMESTAMP . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", // $this->timestamp()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), // [ // 'mysql' => , // 'pgsql' => , // 'sqlite' => , // 'sqlsrv' => , // 'cubrid' => , // ], //], [ Schema::TYPE_TIMESTAMP . ' NOT NULL', $this->timestamp()->notNull(), [ 'pgsql' => 'timestamp(0) NOT NULL', 'sqlite' => 'timestamp NOT NULL', 'oci' => 'TIMESTAMP NOT NULL', 'sqlsrv' => 'datetime NOT NULL', 'cubrid' => 'timestamp NOT NULL', ], ], [ Schema::TYPE_TIMESTAMP, $this->timestamp(), [ /** * MySQL has its own TIMESTAMP test realization * @see \yiiunit\framework\db\mysql\QueryBuilderTest::columnTypes() */ 'pgsql' => 'timestamp(0)', 'sqlite' => 'timestamp', 'oci' => 'TIMESTAMP', 'sqlsrv' => 'datetime', 'cubrid' => 'timestamp', ], ], [ Schema::TYPE_TIMESTAMP . ' NULL DEFAULT NULL', $this->timestamp()->defaultValue(null), [ 'pgsql' => 'timestamp(0) NULL DEFAULT NULL', 'sqlite' => 'timestamp NULL DEFAULT NULL', 'sqlsrv' => 'datetime NULL DEFAULT NULL', 'cubrid' => 'timestamp NULL DEFAULT NULL', ], ], [ Schema::TYPE_UPK, $this->primaryKey()->unsigned(), [ 'mysql' => 'int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', 'pgsql' => 'serial NOT NULL PRIMARY KEY', 'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', ], ], [ Schema::TYPE_UBIGPK, $this->bigPrimaryKey()->unsigned(), [ 'mysql' => 'bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', 'pgsql' => 'bigserial NOT NULL PRIMARY KEY', 'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', ], ], [ Schema::TYPE_INTEGER . " COMMENT 'test comment'", $this->integer()->comment('test comment'), [ 'mysql' => "int(11) COMMENT 'test comment'", 'sqlsrv' => 'int', 'cubrid' => "int COMMENT 'test comment'", ], [ 'sqlsrv' => 'integer', ] ], [ Schema::TYPE_PK . " COMMENT 'test comment'", $this->primaryKey()->comment('test comment'), [ 'mysql' => "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'test comment'", 'sqlsrv' => 'int IDENTITY PRIMARY KEY', 'cubrid' => "int NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'test comment'", ], [ 'sqlsrv' => 'pk', ] ], [ Schema::TYPE_PK . ' FIRST', $this->primaryKey()->first(), [ 'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST', 'sqlsrv' => 'int IDENTITY PRIMARY KEY', 'cubrid' => 'int NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST', ], [ 'oci' => 'NUMBER(10) NOT NULL PRIMARY KEY', 'sqlsrv' => 'pk', ] ], [ Schema::TYPE_INTEGER . ' FIRST', $this->integer()->first(), [ 'mysql' => 'int(11) FIRST', 'sqlsrv' => 'int', 'cubrid' => 'int FIRST', ], [ 'oci' => 'NUMBER(10)', 'pgsql' => 'integer', 'sqlsrv' => 'integer', ] ], [ Schema::TYPE_STRING . ' FIRST', $this->string()->first(), [ 'mysql' => 'varchar(255) FIRST', 'sqlsrv' => 'nvarchar(255)', 'cubrid' => 'varchar(255) FIRST', ], [ 'oci' => 'VARCHAR2(255)', 'sqlsrv' => 'string', ] ], [ Schema::TYPE_INTEGER . ' NOT NULL FIRST', $this->integer()->append('NOT NULL')->first(), [ 'mysql' => 'int(11) NOT NULL FIRST', 'sqlsrv' => 'int NOT NULL', 'cubrid' => 'int NOT NULL FIRST', ], [ 'oci' => 'NUMBER(10) NOT NULL', 'sqlsrv' => 'integer NOT NULL', ] ], [ Schema::TYPE_STRING . ' NOT NULL FIRST', $this->string()->append('NOT NULL')->first(), [ 'mysql' => 'varchar(255) NOT NULL FIRST', 'sqlsrv' => 'nvarchar(255) NOT NULL', 'cubrid' => 'varchar(255) NOT NULL FIRST', ], [ 'oci' => 'VARCHAR2(255) NOT NULL', 'sqlsrv' => 'string NOT NULL', ] ], ]; foreach ($items as $i => $item) { if (array_key_exists($this->driverName, $item[2])) { $item[2] = $item[2][$this->driverName]; $items[$i] = $item; } else { unset($items[$i]); } } return array_values($items); }
This is not used as a dataprovider for testGetColumnType to speed up the test when used as dataprovider every single line will cause a reconnect with the database which is not needed here.
columnTypes
php
yiisoft/yii2
tests/framework/db/QueryBuilderTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/db/QueryBuilderTest.php
BSD-3-Clause
private function setErrorHandler() { if (PHP_VERSION_ID < 70000) { set_error_handler(function ($errno, $errstr, $errfile, $errline) { throw new \ErrorException($errstr, $errno, $errno, $errfile, $errline); }); } }
Set own error handler. In case of error in child process its execution bubbles up to phpunit to continue all the rest tests. So, all the rest tests in this case will run both in the child and parent processes. Such mess must be prevented with child's own error handler.
setErrorHandler
php
yiisoft/yii2
tests/framework/db/mysql/connection/DeadLockTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/db/mysql/connection/DeadLockTest.php
BSD-3-Clause
private function setLogFile($filename) { $this->logFile = $filename; }
Sets filename for log file shared between children processes. @param string $filename
setLogFile
php
yiisoft/yii2
tests/framework/db/mysql/connection/DeadLockTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/db/mysql/connection/DeadLockTest.php
BSD-3-Clause
private function deleteLog() { if (null !== $this->logFile && is_file($this->logFile)) { unlink($this->logFile); } }
Deletes shared log file. Deletes the file [[logFile]] if it exists.
deleteLog
php
yiisoft/yii2
tests/framework/db/mysql/connection/DeadLockTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/db/mysql/connection/DeadLockTest.php
BSD-3-Clause
private function getLogContentAndDelete() { if (null !== $this->logFile && is_file($this->logFile)) { $content = file_get_contents($this->logFile); unlink($this->logFile); return $content; } return null; }
Reads shared log content and deletes the log file. Reads content of log file [[logFile]] and returns it deleting the file. @return string|null String content of the file [[logFile]]. `false` is returned when file cannot be read. `null` is returned when file does not exist or [[logFile]] is not set.
getLogContentAndDelete
php
yiisoft/yii2
tests/framework/db/mysql/connection/DeadLockTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/db/mysql/connection/DeadLockTest.php
BSD-3-Clause
private function log($message) { if (null !== $this->logFile) { $time = microtime(true); $timeInt = floor($time); $timeFrac = $time - $timeInt; $timestamp = date('Y-m-d H:i:s', $timeInt) . '.' . round($timeFrac * 1000); file_put_contents($this->logFile, "[$timestamp] $message\n", FILE_APPEND | LOCK_EX); } }
Append message to shared log. @param string $message Message to append to the log. The message will be prepended with timestamp and appended with new line.
log
php
yiisoft/yii2
tests/framework/db/mysql/connection/DeadLockTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/db/mysql/connection/DeadLockTest.php
BSD-3-Clause
private function exportToken(SqlToken $token) { $result = get_object_vars($token); unset($result['parent']); $result['children'] = array_map(function (SqlToken $token) { return $this->exportToken($token); }, $token->children); return $result; }
Use this to export SqlToken for tests. @param SqlToken $token @return array
exportToken
php
yiisoft/yii2
tests/framework/db/sqlite/SqlTokenizerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/db/sqlite/SqlTokenizerTest.php
BSD-3-Clause
public function dataProviderGetByteSize() { return [ ['456', 456], ['5K', 5 * 1024], ['16KB', 16 * 1024], ['4M', 4 * 1024 * 1024], ['14MB', 14 * 1024 * 1024], ['7G', 7 * 1024 * 1024 * 1024], ['12GB', 12 * 1024 * 1024 * 1024], ]; }
Data provider for [[testGetByteSize()]]. @return array
dataProviderGetByteSize
php
yiisoft/yii2
tests/framework/requirements/YiiRequirementCheckerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/requirements/YiiRequirementCheckerTest.php
BSD-3-Clause
public function dataProviderCompareByteSize() { return [ ['2M', '2K', '>', true], ['2M', '2K', '>=', true], ['1K', '1024', '==', true], ['10M', '11M', '<', true], ['10M', '11M', '<=', true], ]; }
Data provider for [[testCompareByteSize()]] @return array
dataProviderCompareByteSize
php
yiisoft/yii2
tests/framework/requirements/YiiRequirementCheckerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/requirements/YiiRequirementCheckerTest.php
BSD-3-Clause
public function dataProviderTestPrepareDataProviderWithPaginationAndSorting() { return [ [ // Default config [], [], 11, // page size set as param in test (new Pagination())->defaultPageSize, [], null ], [ // Default config [], [ 'attributes' => ['test-sort'], ], 11, // page size set as param in test (new Pagination())->defaultPageSize, ['test-sort' => SORT_DESC], // test sort set as param in test null ], [ // Config via array [ 'pageSize' => 12, // Testing a fixed page size 'defaultPageSize' => 991, ], [ 'attributes' => ['test-sort'], 'defaultOrder' => [ 'created_at_1' => SORT_DESC, ], ], 12, 991, ['test-sort' => SORT_DESC], // test sort set as param in test ['created_at_1' => SORT_DESC] ], [ // Config via objects new Pagination([ 'defaultPageSize' => 992, ]), new Sort([ 'attributes' => ['created_at_2'], 'defaultOrder' => [ 'created_at_2' => SORT_DESC, ], ]), 11, // page size set as param in test 992, [], // sort param is set so no default sorting anymore ['created_at_2' => SORT_DESC] ], [ // Disable pagination and sort false, false, ] ]; }
Data provider for [[testPrepareDataProviderWithPaginationAndSorting()]]. @return array test data
dataProviderTestPrepareDataProviderWithPaginationAndSorting
php
yiisoft/yii2
tests/framework/rest/IndexActionTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/rest/IndexActionTest.php
BSD-3-Clause
protected function createAssetController() { $module = $this->getMockBuilder('yii\\base\\Module') ->setMethods(['fake']) ->setConstructorArgs(['console']) ->getMock(); $assetController = new AssetControllerMock('asset', $module); $assetController->interactive = false; $assetController->jsCompressor = 'cp {from} {to}'; $assetController->cssCompressor = 'cp {from} {to}'; return $assetController; }
Creates test asset controller instance. @return AssetControllerMock
createAssetController
php
yiisoft/yii2
tests/framework/console/controllers/AssetControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/AssetControllerTest.php
BSD-3-Clause
protected function runAssetControllerAction($actionID, array $args = []) { $controller = $this->createAssetController(); $controller->run($actionID, $args); return $controller->flushStdOutBuffer(); }
Emulates running of the asset controller action. @param string $actionID id of action to be run. @param array $args action arguments. @return string command output.
runAssetControllerAction
php
yiisoft/yii2
tests/framework/console/controllers/AssetControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/AssetControllerTest.php
BSD-3-Clause
protected function createCompressConfigFile($fileName, array $bundles, array $config = []) { $content = '<?php return ' . var_export($this->createCompressConfig($bundles, $config), true) . ';'; if (file_put_contents($fileName, $content) <= 0) { throw new \Exception("Unable to create file '{$fileName}'!"); } }
Creates test compress config file. @param string $fileName output file name. @param array[] $bundles asset bundles config. @param array $config additional config parameters. @throws \Exception on failure.
createCompressConfigFile
php
yiisoft/yii2
tests/framework/console/controllers/AssetControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/AssetControllerTest.php
BSD-3-Clause
protected function invokeAssetControllerMethod($methodName, array $args = []) { $controller = $this->createAssetController(); $controllerClassReflection = new \ReflectionClass(get_class($controller)); $methodReflection = $controllerClassReflection->getMethod($methodName); $methodReflection->setAccessible(true); $result = $methodReflection->invokeArgs($controller, $args); $methodReflection->setAccessible(false); return $result; }
Invokes the asset controller method even if it is protected. @param string $methodName name of the method to be invoked. @param array $args method arguments. @return mixed method invoke result.
invokeAssetControllerMethod
php
yiisoft/yii2
tests/framework/console/controllers/AssetControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/AssetControllerTest.php
BSD-3-Clause
protected function composeAssetBundleClassSource(array &$config) { $config = array_merge( [ 'namespace' => StringHelper::dirname(get_class($this)), 'class' => 'AppAsset', 'sourcePath' => null, 'basePath' => $this->testFilePath, 'baseUrl' => '', 'css' => [], 'js' => [], 'depends' => [], ], $config ); foreach ($config as $name => $value) { if (!in_array($name, ['namespace', 'class'])) { $config[$name] = VarDumper::export($value); } } $source = <<<EOL namespace {$config['namespace']}; use yii\web\AssetBundle; class {$config['class']} extends AssetBundle { public \$sourcePath = {$config['sourcePath']}; public \$basePath = {$config['basePath']}; public \$baseUrl = {$config['baseUrl']}; public \$css = {$config['css']}; public \$js = {$config['js']}; public \$depends = {$config['depends']}; } EOL; return $source; }
Composes asset bundle class source code. @param array $config asset bundle config. @return string class source code.
composeAssetBundleClassSource
php
yiisoft/yii2
tests/framework/console/controllers/AssetControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/AssetControllerTest.php
BSD-3-Clause
protected function declareAssetBundleClass(array $config) { $sourceCode = $this->composeAssetBundleClassSource($config); eval($sourceCode); return $config['namespace'] . '\\' . $config['class']; }
Declares asset bundle class according to given configuration. @param array $config asset bundle config. @return string new class full name.
declareAssetBundleClass
php
yiisoft/yii2
tests/framework/console/controllers/AssetControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/AssetControllerTest.php
BSD-3-Clause
public function adjustCssUrlDataProvider() { return [ [ '.published-same-dir-class {background-image: url(published_same_dir.png);}', '/test/base/path/assets/input', '/test/base/path/assets/output', '.published-same-dir-class {background-image: url(../input/published_same_dir.png);}', ], [ '.published-relative-dir-class {background-image: url(../img/published_relative_dir.png);}', '/test/base/path/assets/input', '/test/base/path/assets/output', '.published-relative-dir-class {background-image: url(../img/published_relative_dir.png);}', ], [ '.static-same-dir-class {background-image: url(\'static_same_dir.png\');}', '/test/base/path/css', '/test/base/path/assets/output', '.static-same-dir-class {background-image: url(\'../../css/static_same_dir.png\');}', ], [ '.static-relative-dir-class {background-image: url("../img/static_relative_dir.png");}', '/test/base/path/css', '/test/base/path/assets/output', '.static-relative-dir-class {background-image: url("../../img/static_relative_dir.png");}', ], [ '.absolute-url-class {background-image: url(http://domain.com/img/image.gif);}', '/test/base/path/assets/input', '/test/base/path/assets/output', '.absolute-url-class {background-image: url(http://domain.com/img/image.gif);}', ], [ '.absolute-url-secure-class {background-image: url(https://secure.domain.com/img/image.gif);}', '/test/base/path/assets/input', '/test/base/path/assets/output', '.absolute-url-secure-class {background-image: url(https://secure.domain.com/img/image.gif);}', ], [ "@font-face { src: url('../fonts/glyphicons-halflings-regular.eot'); src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'); }", '/test/base/path/assets/input/css', '/test/base/path/assets/output', "@font-face { src: url('../input/fonts/glyphicons-halflings-regular.eot'); src: url('../input/fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'); }", ], [ "@font-face { src: url('../fonts/glyphicons-halflings-regular.eot'); src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'); }", '/test/base/path/assets/input/css', '/test/base/path/assets', "@font-face { src: url('input/fonts/glyphicons-halflings-regular.eot'); src: url('input/fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'); }", ], [ "@font-face { src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAALAIAAAwAwT==) format('truetype'); }", '/test/base/path/assets/input/css', '/test/base/path/assets/output', "@font-face { src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAALAIAAAwAwT==) format('truetype'); }", ], [ '.published-same-dir-class {background-image: url(published_same_dir.png);}', 'C:\test\base\path\assets\input', 'C:\test\base\path\assets\output', '.published-same-dir-class {background-image: url(../input/published_same_dir.png);}', ], [ '.static-root-relative-class {background-image: url(\'/images/static_root_relative.png\');}', '/test/base/path/css', '/test/base/path/assets/output', '.static-root-relative-class {background-image: url(\'/images/static_root_relative.png\');}', ], [ '.published-relative-dir-class {background-image: url(../img/same_relative_dir.png);}', '/test/base/path/assets/css', '/test/base/path/assets/css', '.published-relative-dir-class {background-image: url(../img/same_relative_dir.png);}', ], [ 'img {clip-path: url(#xxx)}', '/test/base/path/css', '/test/base/path/assets/output', 'img {clip-path: url(#xxx)}', ], ]; }
Data provider for [[testAdjustCssUrl()]]. @return array test data.
adjustCssUrlDataProvider
php
yiisoft/yii2
tests/framework/console/controllers/AssetControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/AssetControllerTest.php
BSD-3-Clause
public function findRealPathDataProvider() { return [ [ '/linux/absolute/path', '/linux/absolute/path', ], [ '/linux/up/../path', '/linux/path', ], [ '/linux/twice/up/../../path', '/linux/path', ], [ '/linux/../mix/up/../path', '/mix/path', ], [ 'C:\\windows\\absolute\\path', 'C:\\windows\\absolute\\path', ], [ 'C:\\windows\\up\\..\\path', 'C:\\windows\\path', ], ]; }
Data provider for [[testFindRealPath()]]. @return array test data
findRealPathDataProvider
php
yiisoft/yii2
tests/framework/console/controllers/AssetControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/AssetControllerTest.php
BSD-3-Clause
protected function assertCommandCreatedFileWithoutNamespaceInput($expectedFile, $migrationName, $table, $params = []) { $params[0] = $migrationName; list($config, $namespace, $class) = $this->prepareMigrationNameData($this->migrationNamespace . '\\' . $migrationName); $this->runMigrateControllerAction('create', $params, $config); $this->assertFileContent($expectedFile, $class, $table, $namespace); }
Check config namespace but without input namespace @param mixed $expectedFile @param mixed $migrationName @param mixed $table @param array $params
assertCommandCreatedFileWithoutNamespaceInput
php
yiisoft/yii2
tests/framework/console/controllers/MigrateControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/MigrateControllerTest.php
BSD-3-Clause
protected function assertCommandCreatedJunctionFileWithoutNamespaceInput($expectedFile, $migrationName, $junctionTable, $firstTable, $secondTable) { list($config, $namespace, $class) = $this->prepareMigrationNameData($this->migrationNamespace . '\\' . $migrationName); $this->runMigrateControllerAction('create', [$migrationName], $config); $this->assertSame(ExitCode::OK, $this->getExitCode()); $this->assertFileContentJunction($expectedFile, $class, $junctionTable, $firstTable, $secondTable, $namespace); }
Check config namespace but without input namespace @param mixed $expectedFile @param mixed $migrationName @param mixed $junctionTable @param mixed $firstTable @param mixed $secondTable
assertCommandCreatedJunctionFileWithoutNamespaceInput
php
yiisoft/yii2
tests/framework/console/controllers/MigrateControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/MigrateControllerTest.php
BSD-3-Clause
protected function parseNameClassMigration($class) { $files = FileHelper::findFiles($this->migrationPath); $file = file_get_contents($files[0]); if (preg_match('/class (m\d+_?\d+_?.*) extends Migration/i', $file, $match)) { $file = str_replace($match[1], $class, $file); } $this->tearDownMigrationPath(); return $file; }
Change class name migration to $class. @param string $class name class @return string content generated class migration @see https://github.com/yiisoft/yii2/pull/10213
parseNameClassMigration
php
yiisoft/yii2
tests/framework/console/controllers/MigrateControllerTestTrait.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/MigrateControllerTestTrait.php
BSD-3-Clause
protected function runControllerAction($actionID, $actionParams = []) { $controller = $this->createController(); $action = $controller->createAction($actionID); $action->runWithParams($actionParams); return $controller->flushStdOutBuffer(); }
Emulates running controller action. @param string $actionID id of action to be run. @param array $actionParams action arguments. @return string command output.
runControllerAction
php
yiisoft/yii2
tests/framework/console/controllers/HelpControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/HelpControllerTest.php
BSD-3-Clause
protected function createMessageController() { $module = $this->getMockBuilder('yii\\base\\Module') ->setMethods(['fake']) ->setConstructorArgs(['console']) ->getMock(); $messageController = new MessageControllerMock('message', $module); $messageController->interactive = false; return $messageController; }
Creates test message controller instance. @return MessageControllerMock message command instance.
createMessageController
php
yiisoft/yii2
tests/framework/console/controllers/BaseMessageControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/BaseMessageControllerTest.php
BSD-3-Clause
protected function runMessageControllerAction($actionID, array $args = []) { $controller = $this->createMessageController(); $controller->run($actionID, $args); return $controller->flushStdOutBuffer(); }
Emulates running of the message controller action. @param string $actionID id of action to be run. @param array $args action arguments. @return string command output.
runMessageControllerAction
php
yiisoft/yii2
tests/framework/console/controllers/BaseMessageControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/BaseMessageControllerTest.php
BSD-3-Clause
protected function saveConfigFile(array $config) { if (file_exists($this->configFileName)) { unlink($this->configFileName); } $fileContent = '<?php return ' . VarDumper::export($config) . ';'; // save new config on random name to bypass HHVM cache // https://github.com/facebook/hhvm/issues/1447 file_put_contents($this->generateConfigFileName(), $fileContent); }
Creates message command config file named as [[configFileName]]. @param array $config message command config.
saveConfigFile
php
yiisoft/yii2
tests/framework/console/controllers/BaseMessageControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/BaseMessageControllerTest.php
BSD-3-Clause
protected function createSourceFile($content) { $fileName = $this->sourcePath . DIRECTORY_SEPARATOR . md5(uniqid()) . '.php'; file_put_contents($fileName, "<?php\n" . $content); return $fileName; }
Creates source file with given content. @param string $content file content @return string path to source file
createSourceFile
php
yiisoft/yii2
tests/framework/console/controllers/BaseMessageControllerTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/console/controllers/BaseMessageControllerTest.php
BSD-3-Clause
public function differentConfigProvider() { // make this test not break when intl is not installed if (!extension_loaded('intl')) { return []; } return [ [[ 'numberFormatterOptions' => [ NumberFormatter::MIN_FRACTION_DIGITS => 2, ], ]], [[ 'numberFormatterOptions' => [ NumberFormatter::MAX_FRACTION_DIGITS => 2, ], ]], [[ 'numberFormatterOptions' => [ NumberFormatter::FRACTION_DIGITS => 2, ], ]], [[ 'numberFormatterOptions' => [ NumberFormatter::MIN_FRACTION_DIGITS => 2, NumberFormatter::MAX_FRACTION_DIGITS => 4, ], ]], ]; }
Provides some configuration that should not affect Integer formatter.
differentConfigProvider
php
yiisoft/yii2
tests/framework/i18n/FormatterNumberTest.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/i18n/FormatterNumberTest.php
BSD-3-Clause
public static function setIntlStatus($test) { static::$enableIntl = null; if (strncmp($test->getName(false), 'testIntl', 8) === 0) { static::$enableIntl = true; if (!extension_loaded('intl')) { $test->markTestSkipped('intl extension is not installed.'); } } else { static::$enableIntl = false; } }
Emulate disabled intl extension. Enable it only for tests prefixed with testIntl. @param Testcase $test
setIntlStatus
php
yiisoft/yii2
tests/framework/i18n/IntlTestHelper.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/i18n/IntlTestHelper.php
BSD-3-Clause
public function afterSave() { }
Can be overridden to do things after save().
afterSave
php
yiisoft/yii2
tests/framework/ar/ActiveRecordTestTrait.php
https://github.com/yiisoft/yii2/blob/master/tests/framework/ar/ActiveRecordTestTrait.php
BSD-3-Clause
public static function getInstance() { if (!isset(self::$instance) || (self::$instance === null)) { self::$instance = new self(); } return self::$instance; }
Get an instance of this class. @return ReferenceHelper
getInstance
php
alhimik1986/php-excel-templator
src/ReferenceHelper.php
https://github.com/alhimik1986/php-excel-templator/blob/master/src/ReferenceHelper.php
MIT
public static function cellSort($a, $b) { [$ac, $ar] = sscanf($a, '%[A-Z]%d'); [$bc, $br] = sscanf($b, '%[A-Z]%d'); if ($ar === $br) { return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc); } return ($ar < $br) ? -1 : 1; }
Compare two cell addresses Intended for use as a Callback function for sorting cell addresses by column and row. @param string $a First cell to test (e.g. 'AA1') @param string $b Second cell to test (e.g. 'Z1') @return int
cellSort
php
alhimik1986/php-excel-templator
src/ReferenceHelper.php
https://github.com/alhimik1986/php-excel-templator/blob/master/src/ReferenceHelper.php
MIT
private static function cellAddressInDeleteRange($cellAddress, $beforeRow, $numberOfRows, $beforeColumnIndex, $numberOfCols) { [$cellColumn, $cellRow] = Coordinate::coordinateFromString($cellAddress); $cellColumnIndex = Coordinate::columnIndexFromString($cellColumn); // Is cell within the range of rows/columns if we're deleting if ( $numberOfRows < 0 && ($cellRow >= ($beforeRow + $numberOfRows)) && ($cellRow < $beforeRow) ) { return true; } elseif ( $numberOfCols < 0 && ($cellColumnIndex >= ($beforeColumnIndex + $numberOfCols)) && ($cellColumnIndex < $beforeColumnIndex) ) { return true; } return false; }
Test whether a cell address falls within a defined range of cells. @param string $cellAddress Address of the cell we're testing @param int $beforeRow Number of the row we're inserting/deleting before @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) @param int $beforeColumnIndex Index number of the column we're inserting/deleting before @param int $numberOfCols Number of columns to insert/delete (negative values indicate deletion) @return bool
cellAddressInDeleteRange
php
alhimik1986/php-excel-templator
src/ReferenceHelper.php
https://github.com/alhimik1986/php-excel-templator/blob/master/src/ReferenceHelper.php
MIT
public function __construct(array $inserted_cols = [], array $inserted_rows = []) { $this->inserted_rows = $inserted_rows; $this->inserted_cols = $inserted_cols; }
@param integer[][] $inserted_cols Inserted columns, where key 1 - index of column, key 2 - index of row, value - count of inserted rows in the row of template variable @param integer[][] $inserted_rows Inserted rows, where key 1 - index of row, key 2 - index of column, value - count of inserted columns in the column of template variable
__construct
php
alhimik1986/php-excel-templator
src/InsertedCells.php
https://github.com/alhimik1986/php-excel-templator/blob/master/src/InsertedCells.php
MIT
public function __construct(int|string $numberWithoutIDDCode, ?string $IDDCode = null) { $this->number = $numberWithoutIDDCode; $this->IDDCode = $IDDCode ? intval(ltrim($IDDCode, '+0')) : null; }
PhoneNumberInterface constructor.
__construct
php
overtrue/easy-sms
src/PhoneNumber.php
https://github.com/overtrue/easy-sms/blob/master/src/PhoneNumber.php
MIT
public function jsonSerialize() { return $this->getUniversalNumber(); }
Specify data which should be serialized to JSON. @see http://php.net/manual/en/jsonserializable.jsonserialize.php @return mixed data which can be serialized by <b>json_encode</b>, which is a value of any type other than a resource @since 5.4.0
jsonSerialize
php
overtrue/easy-sms
src/PhoneNumber.php
https://github.com/overtrue/easy-sms/blob/master/src/PhoneNumber.php
MIT
protected function buildContent(MessageInterface $message) { $data = $message->getData($this); if (is_array($data)) { return implode('##', $data); } return $data; }
构建发送内容 用 data 数据合成内容,或者直接使用 data 的值 @return string
buildContent
php
overtrue/easy-sms
src/Gateways/TinreeGateway.php
https://github.com/overtrue/easy-sms/blob/master/src/Gateways/TinreeGateway.php
MIT
public function getCredentialScope() { return date('Ymd', strtotime($this->getRequestDate())).'/'.$this->getRegionId().'/'.self::ENDPOINT_SERVICE.'/request'; }
指代信任状,格式为:YYYYMMDD/region/service/request. @return string
getCredentialScope
php
overtrue/easy-sms
src/Gateways/VolcengineGateway.php
https://github.com/overtrue/easy-sms/blob/master/src/Gateways/VolcengineGateway.php
MIT
protected function getSigningKey() { $dateKey = hash_hmac('sha256', date('Ymd', strtotime($this->getRequestDate())), $this->getAccessKeySecret(), true); $regionKey = hash_hmac('sha256', $this->getRegionId(), $dateKey, true); $serviceKey = hash_hmac('sha256', self::ENDPOINT_SERVICE, $regionKey, true); return hash_hmac('sha256', 'request', $serviceKey, true); }
计算签名密钥 在计算签名前,首先从私有访问密钥(Secret Access Key)派生出签名密钥(signing key),而不是直接使用私有访问密钥。具体计算过程如下: kSecret = *Your Secret Access Key* kDate = HMAC(kSecret, Date) kRegion = HMAC(kDate, Region) kService = HMAC(kRegion, Service) kSigning = HMAC(kService, "request") 其中Date精确到日,与RequestDate中YYYYMMDD部分相同。 @return string
getSigningKey
php
overtrue/easy-sms
src/Gateways/VolcengineGateway.php
https://github.com/overtrue/easy-sms/blob/master/src/Gateways/VolcengineGateway.php
MIT
public function getStringToSign($canonicalRequest) { return self::Algorithm."\n".$this->getRequestDate()."\n".$this->getCredentialScope()."\n".hash('sha256', $canonicalRequest); }
创建签名字符串 签名字符串主要包含请求以及正规化请求的元数据信息,由签名算法、请求日期、信任状和正规化请求哈希值连接组成,伪代码如下: StringToSign = Algorithm + '\n' + RequestDate + '\n' + CredentialScope + '\n' + HexEncode(Hash(CanonicalRequest)). @return string
getStringToSign
php
overtrue/easy-sms
src/Gateways/VolcengineGateway.php
https://github.com/overtrue/easy-sms/blob/master/src/Gateways/VolcengineGateway.php
MIT
public function getCanonicalQueryString(array $query) { ksort($query); return http_build_query($query); }
urlencode(注:同RFC3986方法)每一个querystring参数名称和参数值。 按照ASCII字节顺序对参数名称严格排序,相同参数名的不同参数值需保持请求的原始顺序。 将排序好的参数名称和参数值用=连接,按照排序结果将“参数对”用&连接。 例如:CanonicalQueryString = "Action=ListUsers&Version=2018-01-01". @return string
getCanonicalQueryString
php
overtrue/easy-sms
src/Gateways/VolcengineGateway.php
https://github.com/overtrue/easy-sms/blob/master/src/Gateways/VolcengineGateway.php
MIT
public function getCanonicalURI() { return '/'; }
指代正规化后的URI。 如果URI为空,那么使用"/"作为绝对路径。 在火山引擎中绝大多数接口的URI都为"/"。 如果是复杂的path,请通过RFC3986规范进行编码。 @return string
getCanonicalURI
php
overtrue/easy-sms
src/Gateways/VolcengineGateway.php
https://github.com/overtrue/easy-sms/blob/master/src/Gateways/VolcengineGateway.php
MIT
public function __construct(array $results = [], $code = 0, ?\Throwable $previous = null) { $this->results = $results; $this->exceptions = \array_column($results, 'exception', 'gateway'); parent::__construct('All the gateways have failed. You can get error details by `$exception->getExceptions()`', $code, $previous); }
NoGatewayAvailableException constructor. @param int $code
__construct
php
overtrue/easy-sms
src/Exceptions/NoGatewayAvailableException.php
https://github.com/overtrue/easy-sms/blob/master/src/Exceptions/NoGatewayAvailableException.php
MIT
public function __construct($certificatePath, $passPhrase = null, $environment = PushManager::ENVIRONMENT_DEV) { parent::__construct($environment); $this->certificatePath = $certificatePath; $this->passPhrase = $passPhrase; }
IOSPushNotificationService constructor. @param string $environment @param string $certificatePath @param string $passPhrase
__construct
php
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/ApnsPushService.php
https://github.com/Ph3nol/NotificationPusher/blob/master/src/Sly/NotificationPusher/ApnsPushService.php
MIT
public function feedback() { $adapterParams = []; $adapterParams['certificate'] = $this->certificatePath; $adapterParams['passPhrase'] = $this->passPhrase; // Development one by default (without argument). /** @var PushManager $pushManager */ $pushManager = new PushManager($this->environment); // Then declare an adapter. $apnsAdapter = new ApnsAdapter($adapterParams); $this->feedback = $pushManager->getFeedback($apnsAdapter); return $this->feedback; }
Use feedback to get not registered tokens from last send and remove them from your DB @return array
feedback
php
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/ApnsPushService.php
https://github.com/Ph3nol/NotificationPusher/blob/master/src/Sly/NotificationPusher/ApnsPushService.php
MIT
public function getFeedback() { return $this->feedback; }
The Apple Push Notification service includes a feedback service to give you information about failed remote notifications. When a remote notification cannot be delivered because the intended app does not exist on the device, the feedback service adds that device’s token to its list. @return array
getFeedback
php
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/ApnsPushService.php
https://github.com/Ph3nol/NotificationPusher/blob/master/src/Sly/NotificationPusher/ApnsPushService.php
MIT
public function __construct(AdapterInterface $adapter, $devices, MessageInterface $message, array $options = []) { if ($devices instanceof DeviceInterface) { $devices = new DeviceCollection([$devices]); } $this->adapter = $adapter; $this->devices = $devices; $this->message = $message; $this->options = $options; $this->status = self::STATUS_PENDING; $this->checkDevicesTokens(); }
@param AdapterInterface $adapter Adapter @param DeviceInterface|DeviceCollection $devices Device(s) @param MessageInterface $message Message @param array $options Options Options are adapters specific ones, like Apns "badge" or "sound" option for example. Of course, they can be more general. @throws AdapterException
__construct
php
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/Model/Push.php
https://github.com/Ph3nol/NotificationPusher/blob/master/src/Sly/NotificationPusher/Model/Push.php
MIT
public function getServiceMessageFromOrigin(array $tokens, BaseOptionedModel $message) { $data = $message->getOptions(); $data['message'] = $message->getText(); $serviceMessage = new ServiceMessage(); $serviceMessage->setRegistrationIds($tokens); if (isset($data['notificationData']) && !empty($data['notificationData'])) { $serviceMessage->setNotification($data['notificationData']); unset($data['notificationData']); } if ($message instanceof GcmMessage) { $serviceMessage->setNotification($message->getNotificationData()); } $serviceMessage->setData($data); $serviceMessage->setCollapseKey($this->getParameter('collapseKey')); $serviceMessage->setPriority($this->getParameter('priority', 'normal')); $serviceMessage->setRestrictedPackageName($this->getParameter('restrictedPackageName')); $serviceMessage->setDelayWhileIdle($this->getParameter('delayWhileIdle', false)); $serviceMessage->setTimeToLive($this->getParameter('ttl', 600)); $serviceMessage->setDryRun($this->getParameter('dryRun', false)); return $serviceMessage; }
Get service message from origin. @param array $tokens Tokens @param BaseOptionedModel|MessageInterface $message Message @return ServiceMessage @throws ZendInvalidArgumentException
getServiceMessageFromOrigin
php
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/Adapter/Gcm.php
https://github.com/Ph3nol/NotificationPusher/blob/master/src/Sly/NotificationPusher/Adapter/Gcm.php
MIT
public function setHttpClient(HttpClient $client) { $this->httpClient = $client; }
Overrides the default Http Client. @param HttpClient $client
setHttpClient
php
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/Adapter/Gcm.php
https://github.com/Ph3nol/NotificationPusher/blob/master/src/Sly/NotificationPusher/Adapter/Gcm.php
MIT
public function setAdapterParameters(array $config = []) { if (!is_array($config) || empty($config)) { throw new InvalidArgumentException('$config must be an associative array with at least 1 item.'); } if ($this->httpClient === null) { $this->httpClient = new HttpClient(); $this->httpClient->setAdapter(new HttpSocketAdapter()); } $this->httpClient->getAdapter()->setOptions($config); }
Send custom parameters to the Http Adapter without overriding the Http Client. @param array $config @throws InvalidArgumentException
setAdapterParameters
php
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/Adapter/Gcm.php
https://github.com/Ph3nol/NotificationPusher/blob/master/src/Sly/NotificationPusher/Adapter/Gcm.php
MIT
function get_dir_list($sDir) { $aDirList = array(); if ($rHandle = opendir($sDir)) { while (false !== ($sFile = readdir($rHandle))) { if ($sFile !== '.' && $sFile !== '..' && is_dir($sDir . '/' . $sFile)) { $aDirList[] = $sFile; } } closedir($rHandle); asort($aDirList); reset($aDirList); } return $aDirList; }
Get the list of name of directories inside a directory. @param string $sDir @return array
get_dir_list
php
pH7Software/pH7-Social-Dating-CMS
_install/inc/fns/misc.php
https://github.com/pH7Software/pH7-Social-Dating-CMS/blob/master/_install/inc/fns/misc.php
MIT
function validate_name($sName, $iMin = 2, $iMax = 20) { return (is_string($sName) && mb_strlen($sName) >= $iMin && mb_strlen($sName) <= $iMax); }
Validate name (first and last name). @param string $sName @param int $iMin Default 2 @param int $iMax Default 20 @return bool
validate_name
php
pH7Software/pH7-Social-Dating-CMS
_install/inc/fns/misc.php
https://github.com/pH7Software/pH7-Social-Dating-CMS/blob/master/_install/inc/fns/misc.php
MIT