Compare commits

..

No commits in common. "master" and "v1" have entirely different histories.
master ... v1

30 changed files with 568 additions and 2038 deletions

View file

@ -1,26 +1,26 @@
{
"name": "adeattwood/yii-addon",
"description": "Add on for the yii2 framework",
"version": "1.1.0",
"time": "2017-06-24 16:25:17",
"name": "adeattwood/yii-helpers",
"description": "Helpers for the yii2 framework",
"version": "1",
"time": "2017-06-24 11:25:22",
"type": "library",
"authors": [
{
"name": "Ade Attwood",
"email": "attwood16@googlemail.com",
"homepage": "http://adeattwood.co.uk",
"homepage": "http:/adeattwood.co.uk",
"role": "Developer"
}
],
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"yiiaddon\\": "src"
"adeattwood\\helpers\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"yiiaddon\\tests\\": "tests"
"adeattwood\\helpers\\tests\\": "tests"
}
},
"require": {
@ -29,7 +29,6 @@
"require-dev": {
"codeception/specify": "^0.4.6",
"codeception/verify": "^0.3.3",
"codeception/codeception": "^2.3",
"squizlabs/php_codesniffer": "^2.8"
"codeception/codeception": "^2.3"
}
}

386
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "76e4b9dfeef71fc131683537fc22166b",
"content-hash": "4a60d8b60f36b09a2233362c19a305ff",
"packages": [
{
"name": "bower-asset/jquery",
@ -39,16 +39,16 @@
},
{
"name": "bower-asset/jquery.inputmask",
"version": "3.3.8",
"version": "3.3.7",
"source": {
"type": "git",
"url": "https://github.com/RobinHerbots/Inputmask.git",
"reference": "791d84990c4a98df1597e9d155be53a3725805dd"
"reference": "9835731cb78cac749734d94a1cb5bd70da4d3b10"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/791d84990c4a98df1597e9d155be53a3725805dd",
"reference": "791d84990c4a98df1597e9d155be53a3725805dd",
"url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/9835731cb78cac749734d94a1cb5bd70da4d3b10",
"reference": "9835731cb78cac749734d94a1cb5bd70da4d3b10",
"shasum": ""
},
"require": {
@ -160,16 +160,16 @@
},
{
"name": "cebe/markdown",
"version": "1.1.2",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/cebe/markdown.git",
"reference": "25b28bae8a6f185b5030673af77b32e1163d5c6e"
"reference": "c30eb5e01fe021cc5bba2f9ee0eeef96d4931166"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/cebe/markdown/zipball/25b28bae8a6f185b5030673af77b32e1163d5c6e",
"reference": "25b28bae8a6f185b5030673af77b32e1163d5c6e",
"url": "https://api.github.com/repos/cebe/markdown/zipball/c30eb5e01fe021cc5bba2f9ee0eeef96d4931166",
"reference": "c30eb5e01fe021cc5bba2f9ee0eeef96d4931166",
"shasum": ""
},
"require": {
@ -216,7 +216,7 @@
"markdown",
"markdown-extra"
],
"time": "2017-07-16T21:13:23+00:00"
"time": "2016-09-14T20:40:20+00:00"
},
{
"name": "ezyang/htmlpurifier",
@ -478,23 +478,23 @@
},
{
"name": "codeception/codeception",
"version": "2.3.5",
"version": "2.3.3",
"source": {
"type": "git",
"url": "https://github.com/Codeception/Codeception.git",
"reference": "e807cd458eb9f7ae7464f33ad835a2f54aa73194"
"reference": "67cd520b4f20cdfc3a52d1a0022924125822a8e6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Codeception/Codeception/zipball/e807cd458eb9f7ae7464f33ad835a2f54aa73194",
"reference": "e807cd458eb9f7ae7464f33ad835a2f54aa73194",
"url": "https://api.github.com/repos/Codeception/Codeception/zipball/67cd520b4f20cdfc3a52d1a0022924125822a8e6",
"reference": "67cd520b4f20cdfc3a52d1a0022924125822a8e6",
"shasum": ""
},
"require": {
"behat/gherkin": "~4.4.0",
"ext-json": "*",
"ext-mbstring": "*",
"facebook/webdriver": ">=1.1.3 <2.0",
"facebook/webdriver": ">=1.0.1 <2.0",
"guzzlehttp/guzzle": ">=4.1.4 <7.0",
"guzzlehttp/psr7": "~1.0",
"php": ">=5.4.0 <8.0",
@ -524,7 +524,6 @@
"php-amqplib/php-amqplib": "~2.4",
"predis/predis": "^1.0",
"squizlabs/php_codesniffer": "~2.0",
"symfony/process": ">=2.7 <4.0",
"vlucas/phpdotenv": "^2.4.0"
},
"suggest": {
@ -569,7 +568,7 @@
"functional testing",
"unit testing"
],
"time": "2017-08-10T20:28:02+00:00"
"time": "2017-06-02T00:22:30+00:00"
},
{
"name": "codeception/specify",
@ -649,32 +648,32 @@
},
{
"name": "doctrine/instantiator",
"version": "1.1.0",
"version": "1.0.5",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
"reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda"
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda",
"reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
"shasum": ""
},
"require": {
"php": "^7.1"
"php": ">=5.3,<8.0-DEV"
},
"require-dev": {
"athletic/athletic": "~0.1.8",
"ext-pdo": "*",
"ext-phar": "*",
"phpunit/phpunit": "^6.2.3",
"squizlabs/php_codesniffer": "^3.0.2"
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "1.0.x-dev"
}
},
"autoload": {
@ -699,7 +698,7 @@
"constructor",
"instantiate"
],
"time": "2017-07-22T11:58:36+00:00"
"time": "2015-06-14T21:17:01+00:00"
},
{
"name": "facebook/webdriver",
@ -1077,16 +1076,16 @@
},
{
"name": "phpdocumentor/reflection-common",
"version": "1.0.1",
"version": "1.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionCommon.git",
"reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6"
"reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6",
"reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c",
"reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c",
"shasum": ""
},
"require": {
@ -1127,26 +1126,26 @@
"reflection",
"static analysis"
],
"time": "2017-09-11T18:02:19+00:00"
"time": "2015-12-27T11:43:31+00:00"
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "4.1.1",
"version": "3.1.1",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "2d3d238c433cf69caeb4842e97a3223a116f94b2"
"reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/2d3d238c433cf69caeb4842e97a3223a116f94b2",
"reference": "2d3d238c433cf69caeb4842e97a3223a116f94b2",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e",
"reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e",
"shasum": ""
},
"require": {
"php": "^7.0",
"php": ">=5.5",
"phpdocumentor/reflection-common": "^1.0@dev",
"phpdocumentor/type-resolver": "^0.4.0",
"phpdocumentor/type-resolver": "^0.2.0",
"webmozart/assert": "^1.0"
},
"require-dev": {
@ -1172,24 +1171,24 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2017-08-30T18:51:59+00:00"
"time": "2016-09-30T07:12:33+00:00"
},
{
"name": "phpdocumentor/type-resolver",
"version": "0.4.0",
"version": "0.2.1",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "9c977708995954784726e25d0cd1dddf4e65b0f7"
"reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7",
"reference": "9c977708995954784726e25d0cd1dddf4e65b0f7",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb",
"reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb",
"shasum": ""
},
"require": {
"php": "^5.5 || ^7.0",
"php": ">=5.5",
"phpdocumentor/reflection-common": "^1.0"
},
"require-dev": {
@ -1219,26 +1218,26 @@
"email": "me@mikevanriel.com"
}
],
"time": "2017-07-14T14:27:02+00:00"
"time": "2016-11-25T06:54:22+00:00"
},
{
"name": "phpspec/prophecy",
"version": "v1.7.2",
"version": "v1.7.0",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6"
"reference": "93d39f1f7f9326d746203c7c056f300f7f126073"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6",
"reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/93d39f1f7f9326d746203c7c056f300f7f126073",
"reference": "93d39f1f7f9326d746203c7c056f300f7f126073",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.0.2",
"php": "^5.3|^7.0",
"phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0",
"phpdocumentor/reflection-docblock": "^2.0|^3.0.2",
"sebastian/comparator": "^1.1|^2.0",
"sebastian/recursion-context": "^1.0|^2.0|^3.0"
},
@ -1249,7 +1248,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.7.x-dev"
"dev-master": "1.6.x-dev"
}
},
"autoload": {
@ -1282,32 +1281,32 @@
"spy",
"stub"
],
"time": "2017-09-04T11:05:03+00:00"
"time": "2017-03-02T20:05:34+00:00"
},
{
"name": "phpunit/php-code-coverage",
"version": "5.2.2",
"version": "5.2.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "8ed1902a57849e117b5651fc1a5c48110946c06b"
"reference": "dc421f9ca5082a0c0cb04afb171c765f79add85b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/8ed1902a57849e117b5651fc1a5c48110946c06b",
"reference": "8ed1902a57849e117b5651fc1a5c48110946c06b",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/dc421f9ca5082a0c0cb04afb171c765f79add85b",
"reference": "dc421f9ca5082a0c0cb04afb171c765f79add85b",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-xmlwriter": "*",
"php": "^7.0",
"phpunit/php-file-iterator": "^1.4.2",
"phpunit/php-text-template": "^1.2.1",
"phpunit/php-file-iterator": "^1.3",
"phpunit/php-text-template": "^1.2",
"phpunit/php-token-stream": "^1.4.11 || ^2.0",
"sebastian/code-unit-reverse-lookup": "^1.0.1",
"sebastian/code-unit-reverse-lookup": "^1.0",
"sebastian/environment": "^3.0",
"sebastian/version": "^2.0.1",
"sebastian/version": "^2.0",
"theseer/tokenizer": "^1.1"
},
"require-dev": {
@ -1315,7 +1314,7 @@
"phpunit/phpunit": "^6.0"
},
"suggest": {
"ext-xdebug": "^2.5.5"
"ext-xdebug": "^2.5.3"
},
"type": "library",
"extra": {
@ -1346,7 +1345,7 @@
"testing",
"xunit"
],
"time": "2017-08-03T12:40:43+00:00"
"time": "2017-04-21T08:03:57+00:00"
},
{
"name": "phpunit/php-file-iterator",
@ -1487,29 +1486,29 @@
},
{
"name": "phpunit/php-token-stream",
"version": "2.0.1",
"version": "1.4.11",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
"reference": "9a02332089ac48e704c70f6cefed30c224e3c0b0"
"reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/9a02332089ac48e704c70f6cefed30c224e3c0b0",
"reference": "9a02332089ac48e704c70f6cefed30c224e3c0b0",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7",
"reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"php": "^7.0"
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "^6.2.4"
"phpunit/phpunit": "~4.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
"dev-master": "1.4-dev"
}
},
"autoload": {
@ -1532,20 +1531,20 @@
"keywords": [
"tokenizer"
],
"time": "2017-08-20T05:47:52+00:00"
"time": "2017-02-27T10:12:30+00:00"
},
{
"name": "phpunit/phpunit",
"version": "6.2.4",
"version": "6.2.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "ff3a76a58ac293657808aefd58c8aaf05945f4d9"
"reference": "f2786490399836d2a544a34785c4a8d3ab32cf0e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ff3a76a58ac293657808aefd58c8aaf05945f4d9",
"reference": "ff3a76a58ac293657808aefd58c8aaf05945f4d9",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f2786490399836d2a544a34785c4a8d3ab32cf0e",
"reference": "f2786490399836d2a544a34785c4a8d3ab32cf0e",
"shasum": ""
},
"require": {
@ -1565,7 +1564,7 @@
"phpunit/php-timer": "^1.0.6",
"phpunit/phpunit-mock-objects": "^4.0",
"sebastian/comparator": "^2.0",
"sebastian/diff": "^1.4.3",
"sebastian/diff": "^1.4.3 || ^2.0",
"sebastian/environment": "^3.0.2",
"sebastian/exporter": "^3.1",
"sebastian/global-state": "^1.1 || ^2.0",
@ -1616,26 +1615,26 @@
"testing",
"xunit"
],
"time": "2017-08-03T13:59:28+00:00"
"time": "2017-06-13T14:07:07+00:00"
},
{
"name": "phpunit/phpunit-mock-objects",
"version": "4.0.4",
"version": "4.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "2f789b59ab89669015ad984afa350c4ec577ade0"
"reference": "eabce450df194817a7d7e27e19013569a903a2bf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/2f789b59ab89669015ad984afa350c4ec577ade0",
"reference": "2f789b59ab89669015ad984afa350c4ec577ade0",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/eabce450df194817a7d7e27e19013569a903a2bf",
"reference": "eabce450df194817a7d7e27e19013569a903a2bf",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.0.5",
"doctrine/instantiator": "^1.0.2",
"php": "^7.0",
"phpunit/php-text-template": "^1.2.1",
"phpunit/php-text-template": "^1.2",
"sebastian/exporter": "^3.0"
},
"conflict": {
@ -1675,7 +1674,7 @@
"mock",
"xunit"
],
"time": "2017-08-03T14:08:16+00:00"
"time": "2017-03-03T06:30:20+00:00"
},
{
"name": "psr/http-message",
@ -1937,16 +1936,16 @@
},
{
"name": "sebastian/environment",
"version": "3.1.0",
"version": "3.0.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
"reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5"
"reference": "74776f8dbc081cab9287c2a601c0c1d842568744"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/cd0871b3975fb7fc44d11314fd1ee20925fce4f5",
"reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/74776f8dbc081cab9287c2a601c0c1d842568744",
"reference": "74776f8dbc081cab9287c2a601c0c1d842568744",
"shasum": ""
},
"require": {
@ -1958,7 +1957,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.1.x-dev"
"dev-master": "3.0.x-dev"
}
},
"autoload": {
@ -1983,7 +1982,7 @@
"environment",
"hhvm"
],
"time": "2017-07-01T08:51:00+00:00"
"time": "2017-06-20T16:25:05+00:00"
},
{
"name": "sebastian/exporter",
@ -2105,21 +2104,21 @@
},
{
"name": "sebastian/object-enumerator",
"version": "3.0.3",
"version": "3.0.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/object-enumerator.git",
"reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5"
"reference": "31dd3379d16446c5d86dec32ab1ad1f378581ad8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5",
"reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5",
"url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/31dd3379d16446c5d86dec32ab1ad1f378581ad8",
"reference": "31dd3379d16446c5d86dec32ab1ad1f378581ad8",
"shasum": ""
},
"require": {
"php": "^7.0",
"sebastian/object-reflector": "^1.1.1",
"sebastian/object-reflector": "^1.0",
"sebastian/recursion-context": "^3.0"
},
"require-dev": {
@ -2148,7 +2147,7 @@
],
"description": "Traverses array structures and object graphs to enumerate all referenced objects",
"homepage": "https://github.com/sebastianbergmann/object-enumerator/",
"time": "2017-08-03T12:35:26+00:00"
"time": "2017-03-12T15:17:29+00:00"
},
{
"name": "sebastian/object-reflector",
@ -2333,84 +2332,6 @@
"homepage": "https://github.com/sebastianbergmann/version",
"time": "2016-10-03T07:35:21+00:00"
},
{
"name": "squizlabs/php_codesniffer",
"version": "2.9.1",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "dcbed1074f8244661eecddfc2a675430d8d33f62"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dcbed1074f8244661eecddfc2a675430d8d33f62",
"reference": "dcbed1074f8244661eecddfc2a675430d8d33f62",
"shasum": ""
},
"require": {
"ext-simplexml": "*",
"ext-tokenizer": "*",
"ext-xmlwriter": "*",
"php": ">=5.1.2"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"bin": [
"scripts/phpcs",
"scripts/phpcbf"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
},
"autoload": {
"classmap": [
"CodeSniffer.php",
"CodeSniffer/CLI.php",
"CodeSniffer/Exception.php",
"CodeSniffer/File.php",
"CodeSniffer/Fixer.php",
"CodeSniffer/Report.php",
"CodeSniffer/Reporting.php",
"CodeSniffer/Sniff.php",
"CodeSniffer/Tokens.php",
"CodeSniffer/Reports/",
"CodeSniffer/Tokenizers/",
"CodeSniffer/DocGenerators/",
"CodeSniffer/Standards/AbstractPatternSniff.php",
"CodeSniffer/Standards/AbstractScopeSniff.php",
"CodeSniffer/Standards/AbstractVariableSniff.php",
"CodeSniffer/Standards/IncorrectPatternException.php",
"CodeSniffer/Standards/Generic/Sniffs/",
"CodeSniffer/Standards/MySource/Sniffs/",
"CodeSniffer/Standards/PEAR/Sniffs/",
"CodeSniffer/Standards/PSR1/Sniffs/",
"CodeSniffer/Standards/PSR2/Sniffs/",
"CodeSniffer/Standards/Squiz/Sniffs/",
"CodeSniffer/Standards/Zend/Sniffs/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Greg Sherwood",
"role": "lead"
}
],
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
"homepage": "http://www.squizlabs.com/php-codesniffer",
"keywords": [
"phpcs",
"standards"
],
"time": "2017-05-22T02:43:20+00:00"
},
{
"name": "stecman/symfony-console-completion",
"version": "0.7.0",
@ -2458,20 +2379,20 @@
},
{
"name": "symfony/browser-kit",
"version": "v3.3.9",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/browser-kit.git",
"reference": "aee7120b058c268363e606ff5fe8271da849a1b5"
"reference": "c2c8ceb1aa9dab9eae54e9150e6a588ce3e53be1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/browser-kit/zipball/aee7120b058c268363e606ff5fe8271da849a1b5",
"reference": "aee7120b058c268363e606ff5fe8271da849a1b5",
"url": "https://api.github.com/repos/symfony/browser-kit/zipball/c2c8ceb1aa9dab9eae54e9150e6a588ce3e53be1",
"reference": "c2c8ceb1aa9dab9eae54e9150e6a588ce3e53be1",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"php": ">=5.5.9",
"symfony/dom-crawler": "~2.8|~3.0"
},
"require-dev": {
@ -2511,24 +2432,24 @@
],
"description": "Symfony BrowserKit Component",
"homepage": "https://symfony.com",
"time": "2017-07-29T21:54:42+00:00"
"time": "2017-04-12T14:14:56+00:00"
},
{
"name": "symfony/console",
"version": "v3.3.9",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "a1e1b01293a090cb9ae2ddd221a3251a4a7e4abf"
"reference": "70d2a29b2911cbdc91a7e268046c395278238b2e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/a1e1b01293a090cb9ae2ddd221a3251a4a7e4abf",
"reference": "a1e1b01293a090cb9ae2ddd221a3251a4a7e4abf",
"url": "https://api.github.com/repos/symfony/console/zipball/70d2a29b2911cbdc91a7e268046c395278238b2e",
"reference": "70d2a29b2911cbdc91a7e268046c395278238b2e",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"php": ">=5.5.9",
"symfony/debug": "~2.8|~3.0",
"symfony/polyfill-mbstring": "~1.0"
},
@ -2541,6 +2462,7 @@
"symfony/dependency-injection": "~3.3",
"symfony/event-dispatcher": "~2.8|~3.0",
"symfony/filesystem": "~2.8|~3.0",
"symfony/http-kernel": "~2.8|~3.0",
"symfony/process": "~2.8|~3.0"
},
"suggest": {
@ -2579,24 +2501,24 @@
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
"time": "2017-09-06T16:40:18+00:00"
"time": "2017-06-02T19:24:58+00:00"
},
{
"name": "symfony/css-selector",
"version": "v3.3.9",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/css-selector.git",
"reference": "c5f5263ed231f164c58368efbce959137c7d9488"
"reference": "4d882dced7b995d5274293039370148e291808f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/c5f5263ed231f164c58368efbce959137c7d9488",
"reference": "c5f5263ed231f164c58368efbce959137c7d9488",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/4d882dced7b995d5274293039370148e291808f2",
"reference": "4d882dced7b995d5274293039370148e291808f2",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
"php": ">=5.5.9"
},
"type": "library",
"extra": {
@ -2632,24 +2554,24 @@
],
"description": "Symfony CssSelector Component",
"homepage": "https://symfony.com",
"time": "2017-07-29T21:54:42+00:00"
"time": "2017-05-01T15:01:29+00:00"
},
{
"name": "symfony/debug",
"version": "v3.3.9",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/debug.git",
"reference": "8beb24eec70b345c313640962df933499373a944"
"reference": "e9c50482841ef696e8fa1470d950a79c8921f45d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/debug/zipball/8beb24eec70b345c313640962df933499373a944",
"reference": "8beb24eec70b345c313640962df933499373a944",
"url": "https://api.github.com/repos/symfony/debug/zipball/e9c50482841ef696e8fa1470d950a79c8921f45d",
"reference": "e9c50482841ef696e8fa1470d950a79c8921f45d",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"php": ">=5.5.9",
"psr/log": "~1.0"
},
"conflict": {
@ -2688,24 +2610,24 @@
],
"description": "Symfony Debug Component",
"homepage": "https://symfony.com",
"time": "2017-09-01T13:23:39+00:00"
"time": "2017-06-01T21:01:25+00:00"
},
{
"name": "symfony/dom-crawler",
"version": "v3.3.9",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/dom-crawler.git",
"reference": "6b511d7329b203a620f09a2288818d27dcc915ae"
"reference": "fc2c588ce376e9fe04a7b8c79e3ec62fe32d95b1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/6b511d7329b203a620f09a2288818d27dcc915ae",
"reference": "6b511d7329b203a620f09a2288818d27dcc915ae",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/fc2c588ce376e9fe04a7b8c79e3ec62fe32d95b1",
"reference": "fc2c588ce376e9fe04a7b8c79e3ec62fe32d95b1",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"php": ">=5.5.9",
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
@ -2744,24 +2666,24 @@
],
"description": "Symfony DomCrawler Component",
"homepage": "https://symfony.com",
"time": "2017-09-11T15:55:22+00:00"
"time": "2017-05-25T23:10:31+00:00"
},
{
"name": "symfony/event-dispatcher",
"version": "v3.3.9",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "54ca9520a00386f83bca145819ad3b619aaa2485"
"reference": "4054a102470665451108f9b59305c79176ef98f0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/54ca9520a00386f83bca145819ad3b619aaa2485",
"reference": "54ca9520a00386f83bca145819ad3b619aaa2485",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/4054a102470665451108f9b59305c79176ef98f0",
"reference": "4054a102470665451108f9b59305c79176ef98f0",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
"php": ">=5.5.9"
},
"conflict": {
"symfony/dependency-injection": "<3.3"
@ -2807,24 +2729,24 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
"time": "2017-07-29T21:54:42+00:00"
"time": "2017-06-04T18:15:29+00:00"
},
{
"name": "symfony/finder",
"version": "v3.3.9",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "b2260dbc80f3c4198f903215f91a1ac7fe9fe09e"
"reference": "baea7f66d30854ad32988c11a09d7ffd485810c4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/b2260dbc80f3c4198f903215f91a1ac7fe9fe09e",
"reference": "b2260dbc80f3c4198f903215f91a1ac7fe9fe09e",
"url": "https://api.github.com/repos/symfony/finder/zipball/baea7f66d30854ad32988c11a09d7ffd485810c4",
"reference": "baea7f66d30854ad32988c11a09d7ffd485810c4",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
"php": ">=5.5.9"
},
"type": "library",
"extra": {
@ -2856,20 +2778,20 @@
],
"description": "Symfony Finder Component",
"homepage": "https://symfony.com",
"time": "2017-07-29T21:54:42+00:00"
"time": "2017-06-01T21:01:25+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.5.0",
"version": "v1.4.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803"
"reference": "f29dca382a6485c3cbe6379f0c61230167681937"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7c8fae0ac1d216eb54349e6a8baa57d515fe8803",
"reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/f29dca382a6485c3cbe6379f0c61230167681937",
"reference": "f29dca382a6485c3cbe6379f0c61230167681937",
"shasum": ""
},
"require": {
@ -2881,7 +2803,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.5-dev"
"dev-master": "1.4-dev"
}
},
"autoload": {
@ -2915,24 +2837,24 @@
"portable",
"shim"
],
"time": "2017-06-14T15:44:48+00:00"
"time": "2017-06-09T14:24:12+00:00"
},
{
"name": "symfony/process",
"version": "v3.3.9",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "b7666e9b438027a1ea0e1ee813ec5042d5d7f6f0"
"reference": "8e30690c67aafb6c7992d6d8eb0d707807dd3eaf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/b7666e9b438027a1ea0e1ee813ec5042d5d7f6f0",
"reference": "b7666e9b438027a1ea0e1ee813ec5042d5d7f6f0",
"url": "https://api.github.com/repos/symfony/process/zipball/8e30690c67aafb6c7992d6d8eb0d707807dd3eaf",
"reference": "8e30690c67aafb6c7992d6d8eb0d707807dd3eaf",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
"php": ">=5.5.9"
},
"type": "library",
"extra": {
@ -2964,24 +2886,24 @@
],
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
"time": "2017-07-29T21:54:42+00:00"
"time": "2017-05-22T12:32:03+00:00"
},
{
"name": "symfony/yaml",
"version": "v3.3.9",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "1d8c2a99c80862bdc3af94c1781bf70f86bccac0"
"reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/1d8c2a99c80862bdc3af94c1781bf70f86bccac0",
"reference": "1d8c2a99c80862bdc3af94c1781bf70f86bccac0",
"url": "https://api.github.com/repos/symfony/yaml/zipball/9752a30000a8ca9f4b34b5227d15d0101b96b063",
"reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
"php": ">=5.5.9"
},
"require-dev": {
"symfony/console": "~2.8|~3.0"
@ -3019,7 +2941,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2017-07-29T21:54:42+00:00"
"time": "2017-06-02T22:05:06+00:00"
},
{
"name": "theseer/tokenizer",

View file

@ -1,8 +0,0 @@
# &copy; Copyright 2017 Ade Attwood (adeattwood.co.uk)
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -1,16 +0,0 @@
# Yii Helpers
A collection of uefull helpers for the Yii2 framework
## Install
Install with composer
~~~php
compsoer install adeattwood/yii-addon
~~~
## Class docs
You can find the class docs [HERE](http://adeattwood.co.uk/open-source/yii-helpers/master)

View file

@ -1,178 +0,0 @@
<?xml version="1.0"?>
<ruleset name="Yii_Addon">
<!-- vendor/bin/phpcs -n --standard=ruleset.xml --report=emacs -->
<description>Yii addon coding standards</description>
<file>./src</file>
<file>./tests</file>
<exclude-pattern>*/_output/*</exclude-pattern>
<exclude-pattern>*/_data/*</exclude-pattern>
<exclude-pattern>**.*.css</exclude-pattern>
<exclude-pattern>**.*.js</exclude-pattern>
<arg name="colors"/>
<rule ref="PSR1"/>
<rule ref="PSR2">
<exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody"/>
</rule>
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter.Found">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="PEAR.Commenting.FunctionComment.MissingParamTag">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="PEAR.Commenting.FunctionComment.Missing">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="Generic.Commenting.Todo.CommentFound">
<type>warning</type>
</rule>
<rule ref="Generic.Formatting.MultipleStatementAlignment"/>
<rule ref="Generic.CodeAnalysis"/>
<rule ref="Zend.Debug.CodeAnalyzer"/>
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<rule ref="Squiz.Arrays.ArrayDeclaration">
<exclude name="Squiz.Arrays.ArrayDeclaration.NoKeySpecified"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.KeySpecified"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.ValueNotAligned"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.KeyNotAligned"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast"/>
</rule>
<rule ref="Generic.PHP">
<exclude name="Generic.PHP.ClosingPHPTag.NotFound"/>
<exclude name="Generic.PHP.UpperCaseConstant.Found"/>
</rule>
<rule ref="Squiz.PHP">
<exclude name="Squiz.PHP.DisallowComparisonAssignment.AssignedComparison"/>
<exclude name="Squiz.PHP.Heredoc.NotAllowed"/>
<exclude name="Squiz.PHP.DisallowInlineIf"/>
<exclude name="Squiz.PHP.DisallowMultipleAssignments.Found"/>
<exclude name="Squiz.PHP.DisallowBooleanStatement.Found"/>
</rule>
<rule ref="Squiz.Strings">
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
</rule>
<rule ref="Generic.Strings"/>
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="PEAR.Commenting">
<exclude name="PEAR.Commenting.FileComment"/>
<exclude name="PEAR.Commenting.ClassComment.InvalidPackage"/>
</rule>
<rule ref="PEAR.Commenting.FileComment.MissingCategoryTag">
<type>warning</type>
</rule>
<rule ref="PEAR.Commenting.FileComment.InvalidPackage">
<type>warning</type>
</rule>
<rule ref="PEAR.Commenting.FileComment.MissingPackageTag">
<type>warning</type>
</rule>
<rule ref="PEAR.Commenting.FileComment.MissingLicenseTag">
<type>warning</type>
</rule>
<rule ref="PEAR.Commenting.FileComment.MissingLinkTag">
<type>warning</type>
</rule>
<rule ref="PEAR.Commenting.ClassComment.MissingCategoryTag">
<type>warning</type>
</rule>
<rule ref="PEAR.Commenting.ClassComment.InvalidPackage">
<type>warning</type>
</rule>
<rule ref="PEAR.Commenting.ClassComment.MissingPackageTag">
<type>warning</type>
</rule>
<rule ref="PEAR.Commenting.ClassComment.MissingLicenseTag">
<type>warning</type>
</rule>
<rule ref="PEAR.Commenting.ClassComment.MissingLinkTag">
<type>warning</type>
</rule>
<rule ref="Squiz.Commenting.VariableComment"/>
<rule ref="Squiz.Commenting.VariableComment.Missing">
<type>warning</type>
</rule>
<rule ref="PEAR.Commenting.FunctionComment.MissingParamComment">
<type>warning</type>
</rule>
<rule ref="Squiz.ControlStructures">
<exclude name="Squiz.ControlStructures"/>
</rule>
<rule ref="Squiz.Functions">
<exclude name="Squiz.Functions"/>
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
<properties>
<property name="spacing" value="1"/>
</properties>
</rule>
<rule ref="Generic.Files.LineEndings">
<properties>
<property name="eolChar" value="\n"/>
</properties>
</rule>
<rule ref="Generic.Formatting.MultipleStatementAlignment">
<properties>
<property name="maxPadding" value="20"/>
<property name="error" value="true"/>
</properties>
</rule>
</ruleset>

View file

@ -1,17 +1,15 @@
<?php
namespace yiiaddon\helpers;
namespace adeattwood\helpers;
use Yii;
use yii\base\InvalidConfigException;
use yiiaddon\helpers\ArrayObject;
use yiiaddon\helpers\Enum;
use adeattwood\helpers\ArrayObject;
use adeattwood\helpers\Enum;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
@ -19,7 +17,6 @@ use yiiaddon\helpers\Enum;
*/
class ArrayHelper extends \yii\helpers\ArrayHelper
{
/**
* Creates a array of numbers
*
@ -65,7 +62,7 @@ class ArrayHelper extends \yii\helpers\ArrayHelper
*
* @return ArrayObject The parsed config
*/
public static function parseAttribute( $model, $attribute, $defalts = [] )
public static function parseAttribute( $model, $attribute, $defalts = [ 'format' => "text", 'value' => '( NOT SET )' ] )
{
if ( !preg_match( '/^([^:]+)(:(\w*))?(:(.*))?$/', $attribute, $matches ) ) {
throw new InvalidConfigException( 'The column must be specified in the format of "attribute", "attribute:format" or "attribute:format:label"' );
@ -73,8 +70,8 @@ class ArrayHelper extends \yii\helpers\ArrayHelper
$rawValue = self::getValue( $model, $matches[ 1 ] );
$format = isset($matches[3]) ? $matches[3] : self::remove($defalts, 'format', 'text');
$value = Enum::isEmpty($rawValue) ? self::remove($defalts, 'value', '( NOT SET )') : Yii::$app->formatter->format($rawValue, $format);
$format = isset( $matches[ 3 ] ) ? $matches[ 3 ] : $defalts[ 'format' ];
$value = Enum::isEmpty( $rawValue ) ? $defalts[ 'value' ] : Yii::$app->formatter->format( $rawValue, $format );
$lable = isset( $matches[ 5 ] ) ? $matches[ 5 ] : $model->getAttributeLabel( $matches[ 1 ] );
return new ArrayObject( [
@ -84,5 +81,4 @@ class ArrayHelper extends \yii\helpers\ArrayHelper
'raw' => $rawValue
] );
}
}

153
src/ArrayObject.php Normal file
View file

@ -0,0 +1,153 @@
<?php
namespace adeattwood\helpers;
use Yii;
use yii\helpers\Html;
use adeattwood\helpers\Enum;
/**
* @category PHP
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v0.1
*/
class ArrayObject extends \ArrayObject
{
/**
* __construct
*
* @param mixed $array The array to put into the array object
* @param mixed $flags The falgs of the object
* @param string $iterator_class The iterator class
*
* @return void
*/
public function __construct( $array = [], $flags = null, $iterator_class = 'ArrayIterator' )
{
if( $flags === null ) {
$flags = self::ARRAY_AS_PROPS;
}
parent::__construct( $array, $flags, $iterator_class );
}
/**
* Test that the ArrayObject contains an item
*
* @param $item The item to test
*
* @return bool
*/
public function contains( $item )
{
$flipped = array_flip( ( array )$this );
return isset( $flipped[ $item ] );
}
/**
* Gets a random value from the array
*
* @param int $count How many items to return
*
* @return int|array
*/
public function randomValue( $count = 1 )
{
$arr = ( array )$this;
shuffle( $arr );
$r = array();
for ( $i = 0; $i < $count; $i++ ) {
$r[] = $arr[$i];
}
return $count == 1 ? $r[0] : $r;
}
/**
* Converts the ArrayObject into a table
*
* @param mixed $transpose
* @param mixed $recursive
* @param mixed $typeHint
* @param string $tableOptions
* @param mixed $keyOptions
* @param string $valueOptions
* @param string $null
*
* @return string The html for the table
*/
public function toTable( $transpose = false, $recursive = false, $typeHint = true, $tableOptions = [ 'class' => 'table table-bordered table-striped' ], $keyOptions = [], $valueOptions = [ 'style' => 'cursor: default; border-bottom: 1px #aaa dashed;' ], $null = '<span class="not-set">(not set)</span>' )
{
if ( empty( ( array )$this ) ) {
return false;
}
$array = ( array )$this;
// Start the table
$table = Html::beginTag( 'table', $tableOptions ) . "\n";
// The header
$table .= "\t<tr>";
if ( $transpose ) {
foreach ( $this as $key => $value ) {
if ( $typeHint ) {
$valueOptions['title'] = Enum::getType( strtoupper( $value ) );
}
if ( is_array( $value ) ) {
$value = '<pre>' . print_r( $value, true ) . '</pre>';
} else {
$value = Html::tag( 'span', $value, $valueOptions );
}
$table .= "\t\t<th>" . Html::tag( 'span', $key, $keyOptions ) . "</th>" .
"<td>" . $value . "</td>\n\t</tr>\n";
}
$table .= "</table>";
return $table;
}
if ( !isset( $array[0] ) || !is_array( $array[0] ) ) {
$array = array( $array );
}
// Take the keys from the first row as the headings
foreach ( array_keys( $array[0] ) as $heading ) {
$table .= '<th>' . Html::tag( 'span', $heading, $keyOptions ) . '</th>';
}
$table .= "</tr>\n";
// The body
foreach ( $array as $row ) {
$table .= "\t<tr>";
foreach ( $row as $cell ) {
$table .= '<td>';
// Cast objects
if ( is_object( $cell ) ) {
$cell = (array)$cell;
}
if ( $recursive === true && is_array( $cell ) && !empty( $cell ) ) {
// Recursive mode
$table .= "\n" . static::array2table( $cell, true, true ) . "\n";
} else {
if ( !is_null( $cell ) && is_bool( $cell ) ) {
$val = $cell ? 'true' : 'false';
$type = 'boolean';
} else {
$chk = ( strlen( $cell ) > 0 );
$type = $chk ? Enum::getType( $cell ) : 'null';
$val = $chk ? htmlspecialchars( (string)$cell ) : $null;
}
if ( $typeHint ) {
$valueOptions['title'] = $type;
}
$table .= Html::tag( 'span', $val, $valueOptions );
}
$table .= '</td>';
}
$table .= "</tr>\n";
}
$table .= '</table>';
return $table;
}
}

155
src/Dumper.php Normal file
View file

@ -0,0 +1,155 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace adeattwood\helpers;
use Symfony\Component\VarDumper\VarDumper;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
/**
* Description of Dumper
*
* @author ade
*/
class Dumper
{
public static $styles = array(
'default' => 'background-color:#18171B; color:#FF8400; line-height:1.2em; font:14px Menlo, Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: normal',
'num' => 'font-weight:bold; color:#1299DA',
'const' => 'font-weight:bold',
'str' => 'font-weight:bold; color:#56DB3A',
'note' => 'color:#1299DA',
'ref' => 'color:#A0A0A0',
'public' => 'color:#FFFFFF',
'protected' => 'color:#FFFFFF',
'private' => 'color:#FFFFFF',
'meta' => 'color:#B729D9',
'key' => 'color:#56DB3A',
'index' => 'color:#1299DA',
'ellipsis' => 'color:#FF8400',
);
public static $displayOptions = array(
'maxDepth' => 1,
'maxStringLength' => 160,
'fileLinkFormat' => null,
);
public static function dump( $var ) {
VarDumper::setHandler( function ( $var ) {
$cloner = new VarCloner();
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
$dumper->setStyles( self::$styles );
$dumper->setDisplayOptions( self::$displayOptions );
$dumper->dump( $cloner->cloneVar( $var ) );
} );
dump( $var );
}
public static function dDump( $var )
{
self::dump( $var );
die;
}
public static function dumpInfo( $var )
{
$dataArray = [];
$class = new \ReflectionClass( $var );
$dataArray[ 'name' ] = $class->name;
$methods = $class->getMethods();
$dataArray[ 'constants'] = ( array )$class->getConstants();
foreach ( $class->getProperties() as $propertie ) {
$prop = '';
if ( $propertie->isPublic() ) {
$prop .= "public";
} elseif ( $propertie->isPrivate() ) {
$prop .= "private";
} elseif ( $propertie->isProtected() ) {
$prop .= "protected";
}
if ( $propertie->isStatic() ) {
$prop .= " static";
}
$prop .= " \${$propertie->name}";
$dataArray[ 'properties' ][] = $prop;
}
foreach ( $methods as $method ) {
$prop = '';
if ( $method->isPublic() ) {
$prop .= "public";
} elseif ( $method->isPrivate() ) {
$prop .= "private";
} elseif ( $method->isProtected() ) {
$prop .= "protected";
}
$prop .= " {$method->name}( ";
$params = "";
foreach ( $method->getParameters() as $parameter ) {
$params .= "\${$parameter->name}";
if ( $parameter->isDefaultValueAvailable() ) {
$value = $parameter->getDefaultValue();
if ( is_array( $value ) ) {
$value = "[]";
} elseif ( is_bool( $value ) ) {
$value = $value ? "true" : "false";
}
$params .= "= {$value}";
// self::dDump( $parameter->getDefaultValue() );
}
$params .= ", ";
}
$params = rtrim( $params, ", " );
$prop .= "{$params} )";
// $prop .= " : {$method->getReturnType()}";
$dataArray[ 'methords' ][ $prop ] = [
"file" => $method->getFileName(),
"line" => $method->getStartLine(),
'fileLine' => "{$method->getFileName()}:{$method->getStartLine()}",
"doc" => $method->getDocComment()
];
}
sort( $dataArray[ 'properties' ] );
ksort( $dataArray[ 'constants' ] );
ksort( $dataArray[ 'methords' ] );
self::dDump( $dataArray );
}
public static function dDumpInfo( $var )
{
self::dumpInfo( $var );
die;
}
}

View file

@ -1,11 +1,11 @@
<?php
namespace yiiaddon\helpers;
namespace adeattwood\helpers;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
@ -48,38 +48,29 @@ class Enum extends \yii\base\Object
*/
public static function getType( $var )
{
if ($var === null) {
return self::TYPE_NULL;
switch( $var ) {
case is_null( $var ):
return static::TYPE_NULL;
break;
case is_bool( $var );
return static::TYPE_BOOL;
break;
case is_float( $var ):
case is_numeric( str_replace( ',', '', $var ) ) && strpos( $var, '.' ) > 0 && is_float( ( float )str_replace( ',', '', $var ) ):
return static::TYPE_FLOAT;
break;
case is_int( $var ) || ( is_numeric( $var ) && is_int( ( int )$var ) ):
return static::TYPE_INT;
break;
case is_scalar( $var ) && strtotime( $var ) !== false:
return static::TYPE_DATETIME;
break;
case is_scalar( $var ):
return static::TYPE_STRING;
break;
default:
return static::TYPE_UNKNOWN;
}
if (is_array($var)) {
return self::TYPE_ARRAY;
}
if (is_bool($var)) {
return self::TYPE_BOOL;
}
if (is_float($var)
|| (!is_object($var) &&
is_numeric(str_replace(',', '', $var)) && strpos($var, '.') > 0 && is_float(( float ) str_replace(',', '', $var)))
) {
return self::TYPE_FLOAT;
}
if (is_int($var) || ( is_numeric($var) && is_int(( int ) $var) )) {
return self::TYPE_INT;
}
if (is_scalar($var) && strtotime($var) !== false) {
return self::TYPE_DATETIME;
}
if (is_scalar($var)) {
return self::TYPE_STRING;
}
return self::TYPE_UNKNOWN;
}
/**
@ -127,5 +118,4 @@ class Enum extends \yii\base\Object
$bytes /= pow( 1024, $pow );
return round( $bytes, $precision ) . ' ' . $units[$pow];
}
}

View file

@ -1,74 +0,0 @@
<?php
namespace yiiaddon\behaviors;
use yii\db\BaseActiveRecord;
use yii\web\UploadedFile;
/**
* Loads the Uploaded file instance to an attribute in your model
*
* ~~~php
* use yiiaddon\behaviors\UploadedFileBehavior;
*
* public function behaviors()
* {
* return [
* [
* 'class' => UploadedFileBehavior::className(),
* 'fileAttribute' => 'my_file'
* ],
* ];
* }
* ~~~
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v1.2
*/
class UploadedFileBehavior extends \yii\behaviors\AttributeBehavior
{
/**
* The attribute in your model that will be uploading the file from the form
*
* @var string
*/
public $fileAttribute = 'file';
/**
* The temporary instance of UploadFile
*
* @var yii\web\UploadedFile
*/
public $value;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (empty($this->attributes)) {
$this->attributes = [
BaseActiveRecord::EVENT_BEFORE_VALIDATE => $this->fileAttribute,
];
}
}
/**
* @inheritdoc
*/
protected function getValue($event)
{
if ($this->value === null) {
return UploadedFile::getInstance($this->owner, $this->fileAttribute);
}
return parent::getValue($event);
}
}

View file

@ -1,40 +0,0 @@
<?php
namespace yiiaddon\components;
use yiiaddon\helpers\ArrayHelper;
use yiiaddon\helpers\ArrayObject;
/**
* A collection of active records when getting data from the database
*
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v1.2
*/
class ActiveRecordCollection extends \yiiaddon\helpers\ArrayObject
{
/**
* Maps a the collection into a single key-value pair
*
* ~~~php
* $model = Model::find()->all();
* $map = $model->map('id', 'name');
* ~~~
*
* @param string $key The attribute you want to be the key
* @param string $value The attribute you want to be the value
*
* @return ArrayObject
*/
public function map($key, $value)
{
return new ArrayObject(ArrayHelper::map((array) $this, $key, $value));
}
}

View file

@ -1,31 +0,0 @@
<?php
namespace yiiaddon\db;
use yiiaddon\components\ActiveRecordCollection;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v1.2
*/
class ActiveQuery extends \yii\db\ActiveQuery
{
/**
* Overrides the Yii method to return an ActiveRecordCollection instead of an array
*
* @param mixed $db The DB connection used to create the DB command.
*
* @return ActiveRecordCollection
*/
public function all($db = null)
{
return new ActiveRecordCollection(parent::all($db));
}
}

View file

@ -1,60 +0,0 @@
<?php
namespace yiiaddon\db;
use Yii;
use yiiaddon\helpers\ArrayHelper;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v1.2
*/
class ActiveRecord extends \yii\db\ActiveRecord
{
/**
* Creates an instance of ActiveQuery
*
* @return yiiaddon\db\ActiveQuery
*/
public static function find()
{
return Yii::createObject(ActiveQuery::className(), [get_called_class()]);
}
/**
* Parses an attribute
*
* @see yiiaddon\helpers\ArrayHelper::parseAttribute
*
* @param string $attribute The attribute format string
* @param array $defalts The array of defalts to override
*
* @return yiiaddon\helpers\ArrayObject
*/
public function parseAttribute($attribute, $defalts = [])
{
return ArrayHelper::parseAttribute($this, $attribute, $defalts);
}
/**
* Get a value of an attribute and formats with a string
*
* @see yiiaddon\helpers\ArrayHelper::parseAttribute
*
* @param string $attribute The attribute and format string
* @param string $defalt The defalt value to return if the attribute is not set
*
* @return mixed
*/
public function getValue($attribute, $defalt = '( NOT SET )')
{
return $this->parseAttribute($attribute, ['value' => $defalt])->value;
}
}

View file

@ -1,80 +0,0 @@
<?php
namespace yiiaddon\db;
use Yii;
use yii\db\Expression;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v1.2
*/
trait Rankable
{
public $rank_filed = 'rank';
public $rank_group = false;
public function getRankField()
{
return 'rank';
}
public function getRankGoup()
{
return false;
}
public function getNextRank()
{
$query = self::find();
if ($this->rankGoup) {
$query->where([$this->rankGroup => $this->{$this->rankGroup}]);
}
return $query->count();
}
public function changeRank( $new_rank )
{
$rank_filed = $this->rankField;
$group = $this->rankGoup;
$old_rank = $this->{ $rank_filed };
if ($new_rank == $old_rank) {
return true;
}
$value = '';
if ($new_rank > $old_rank) {
$value = $rank_filed.' - 1';
$where = $rank_filed.'>= :rank1 AND '.$rank_filed.' <= :rank2';
} else {
$value = $rank_filed.' + 1';
$where = $rank_filed.' <= :rank1 AND '.$rank_filed.' >= :rank2';
}
if ($group) {
$where .= ' AND '.$group.' = '.$this->{ $group };
}
$query = Yii::$app->db->createCommand()
->update(self::tableName(), [ $rank_filed => new Expression($value) ], $where)
->bindValue(':rank1', $old_rank)
->bindValue(':rank2', $new_rank)
->execute();
$this->updateAttributes([ 'rank' => $new_rank ]);
return true;
}
}

View file

@ -1,189 +0,0 @@
<?php
namespace yiiaddon\filters;
use Yii;
use yii\di\Instance;
use yii\web\Response;
/**
* Minifies the html output of the page
*
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v1.2
*/
class PageMin extends \yii\base\ActionFilter
{
/**
* The the filter should be enabled
*
* @var boolean
*/
public $enabled = true;
/**
* @inheritDoc
*/
public function beforeAction($action)
{
if (!$this->enabled) {
return true;
}
$response = Yii::$app->getResponse();
$response->on(Response::EVENT_BEFORE_SEND, [$this, 'pageMin']);
return true;
}
/**
* Minifies the event data
*
* @param Event $event The request event
*
* @return void
*/
public function pageMin($event)
{
Yii::$app->response->data = $this->minifyHtml($event->sender->data);
}
/**
* Minifies html string
*
* @param string $input The string of html
*
* @return string The output html
*/
public function minifyHtml( $input )
{
if(trim($input) === '') { return $input;
}
$input = preg_replace_callback('#<([^\/\s<>!]+)(?:\s+([^<>]*?)\s*|\s*)(\/?)>#s', function($matches) {
return '<'.$matches[1].preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]).$matches[3].'>';
}, str_replace("\r", '', $input));
if(strpos($input, ' style=') !== false) {
$input = preg_replace_callback('#<([^<]+?)\s+style=([\'"])(.*?)\2(?=[\/\s>])#s', function($matches) {
return '<'.$matches[1].' style='.$matches[2].$this->minifyCss($matches[3]).$matches[2];
}, $input);
}
if(strpos($input, '</style>') !== false) {
$input = preg_replace_callback('#<style(.*?)>(.*?)</style>#is', function($matches) {
return '<style'.$matches[1].'>'.$this->minifyCss($matches[2]).'</style>';
}, $input);
}
if(strpos($input, '</script>') !== false) {
$input = preg_replace_callback('#<script(.*?)>(.*?)</script>#is', function($matches) {
return '<script'.$matches[1].'>'.$this->minifyJs($matches[2]).'</script>';
}, $input);
}
return preg_replace(
[
'#<(img|input)(>| .*?>)#s',
'#(<!--.*?-->)|(>)(?:\n*|\s{2,})(<)|^\s*|\s*$#s',
'#(<!--.*?-->)|(?<!\>)\s+(<\/.*?>)|(<[^\/]*?>)\s+(?!\<)#s',
'#(<!--.*?-->)|(<[^\/]*?>)\s+(<[^\/]*?>)|(<\/.*?>)\s+(<\/.*?>)#s',
'#(<!--.*?-->)|(<\/.*?>)\s+(\s)(?!\<)|(?<!\>)\s+(\s)(<[^\/]*?\/?>)|(<[^\/]*?\/?>)\s+(\s)(?!\<)#s',
'#(<!--.*?-->)|(<[^\/]*?>)\s+(<\/.*?>)#s',
'#<(img|input)(>| .*?>)<\/\1>#s',
'#(&nbsp;)&nbsp;(?![<\s])#',
'#(?<=\>)(&nbsp;)(?=\<)#',
'#\s*<!--(?!\[if\s).*?-->\s*|(?<!\>)\n+(?=\<[^!])#s'
],
[
'<$1$2</$1>',
'$1$2$3',
'$1$2$3',
'$1$2$3$4$5',
'$1$2$3$4$5$6$7',
'$1$2$3',
'<$1$2',
'$1 ',
'$1',
''
],
$input
);
}
/**
* Minifies css strings inside the html
*
* @param string $input The input html
*
* @return string The output html
*/
public function minifyCss($input)
{
if (trim($input) === '') {
return $input;
}
return preg_replace(
[
'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s',
'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+]|\s*+-(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si',
'#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si',
'#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i',
'#(background-position):0(?=[;\}])#si',
'#(?<=[\s:,\-])0+\.(\d+)#s',
'#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si',
'#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si',
'#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i',
'#(?<=[\{;])(border|outline):none(?=[;\}\!])#',
'#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s'
],
[
'$1',
'$1$2$3$4$5$6$7',
'$1',
':0',
'$1:0 0',
'.$1',
'$1$3',
'$1$2$4$5',
'$1$2$3',
'$1:0',
'$1$2'
],
$input
);
}
/**
* Minifies js strings inside the html
*
* @param string $input The input html
*
* @return string The output html
*/
public function minifyJs($input)
{
if (trim($input) === '') {
return $input;
}
return preg_replace(
[
'#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s',
'#;+\}#',
'#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i',
'#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i'
],
[
'$1',
'$1$2',
'}',
'$1$3',
'$1.$3'
],
$input
);
}
}

View file

@ -1,247 +0,0 @@
<?php
namespace yiiaddon\helpers;
use Yii;
use yii\helpers\Html;
use yiiaddon\helpers\Enum;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v0.1
*/
class ArrayObject extends \ArrayObject
{
/**
* __construct
*
* @param mixed $array The array to put into the array object
* @param mixed $flags The falgs of the object
* @param string $iterator_class The iterator class
*
* @return void
*/
public function __construct( $array = [], $flags = null, $iterator_class = 'ArrayIterator' )
{
if($flags === null) {
$flags = self::ARRAY_AS_PROPS;
}
parent::__construct($array, $flags, $iterator_class);
}
/**
* Test that the ArrayObject contains an item
*
* @param mixed $item The item to test
*
* @return bool
*/
public function contains( $item )
{
$flipped = array_flip(( array ) $this);
return isset($flipped[$item]);
}
/**
* Gets a random value from the array
*
* @param int $count How many items to return
*
* @return int|self
*/
public function randomValue( $count = 1 )
{
$arr = ( array ) $this;
shuffle($arr);
$r = array();
for ($i = 0; $i < $count; $i++) {
$r[] = $arr[$i];
}
return $count == 1 ? $r[0] : new self($r);
}
/**
* Adds an item to the start of the object
*
* @param mixed $value The item to prepend
*
* @return void
*/
public function prepend($value)
{
$array = $this->getArrayCopy();
if (is_string($value)) {
$value = (array) $value;
}
if (is_object($value)) {
$value = [$value];
}
$this->exchangeArray($value + $array);
}
/**
* Combines an array to the existing object
*
* @param array $array The array to comnine
*
* @return void
*/
public function combine($array)
{
$this->exchangeArray(array_merge((array) $this->getArrayCopy(), $array));
}
/**
* Splits the object up into chunks
*
* Example:
*
* ~~~php
* $obj = new ArrayObject([
* 'key_one' => 'Value One'
* 'key_two' => 'Value Two'
* 'key_three' => 'Value Three'
* 'key_four' => 'Value Four'
* 'key_five' => 'Value Five'
* 'key_six' => 'Value Six'
* ]);
*
* $chunks = $obj->chunks(2);
*
* [
* [
* 'key_one' => 'Value One'
* 'key_two' => 'Value Two'
* ],
* [
* 'key_three' => 'Value Three'
* 'key_four' => 'Value Four'
* ],
* [
* 'key_five' => 'Value Five'
* 'key_six' => 'Value Six'
* ],
* ]
* ~~~
*
* @param integer $count How big to make the chunks
*
* @return void
*/
public function chunks($count)
{
$out = [];
$array = array_chunk((array) $this, $count);
foreach ($array as $chunk) {
$out[] = new self($chunk);
}
return new self($out);
}
/**
* Turns the object into a json stirng
*
* @return string
*/
public function toJson()
{
return \yii\helpers\Json::encode((array) $this);
}
/**
* Converts the ArrayObject into a table
*
* @param mixed $transpose
* @param mixed $recursive
* @param mixed $typeHint
* @param string $tableOptions
* @param mixed $keyOptions
* @param string $valueOptions
* @param string $null
*
* @return string The html for the table
*/
public function toTable( $transpose = false, $recursive = false, $typeHint = true, $tableOptions = [ 'class' => 'table table-bordered table-striped' ], $keyOptions = [], $valueOptions = [ 'style' => 'cursor: default; border-bottom: 1px #aaa dashed;' ], $null = '<span class="not-set">(not set)</span>' )
{
if (empty(( array ) $this)) {
return false;
}
$array = ( array ) $this;
// Start the table
$table = Html::beginTag('table', $tableOptions)."\n";
// The header
$table .= "\t<tr>";
if ($transpose) {
foreach ($this as $key => $value) {
if ($typeHint) {
$valueOptions['title'] = Enum::getType(strtoupper($value));
}
if (is_array($value)) {
$value = '<pre>'.print_r($value, true).'</pre>';
} else {
$value = Html::tag('span', $value, $valueOptions);
}
$table .= "\t\t<th>".Html::tag('span', $key, $keyOptions).'</th>'.'<td>'.$value."</td>\n\t</tr>\n";
}
$table .= '</table>';
return $table;
}
if (!isset($array[0]) || !is_array($array[0])) {
$array = array( $array );
}
// Take the keys from the first row as the headings
foreach (array_keys($array[0]) as $heading) {
$table .= '<th>'.Html::tag('span', $heading, $keyOptions).'</th>';
}
$table .= "</tr>\n";
// The body
foreach ($array as $row) {
$table .= "\t<tr>";
foreach ($row as $cell) {
$table .= '<td>';
// Cast objects
if (is_object($cell)) {
$cell = (array) $cell;
}
if ($recursive === true && is_array($cell) && !empty($cell)) {
// Recursive mode
$table .= "\n".static::array2table($cell, true, true)."\n";
} else {
if ($cell !== null && is_bool($cell)) {
$val = $cell ? 'true' : 'false';
$type = 'boolean';
} else {
$chk = ( strlen($cell) > 0 );
$type = $chk ? Enum::getType($cell) : 'null';
$val = $chk ? htmlspecialchars((string) $cell) : $null;
}
if ($typeHint) {
$valueOptions['title'] = $type;
}
$table .= Html::tag('span', $val, $valueOptions);
}
$table .= '</td>';
}
$table .= "</tr>\n";
}
$table .= '</table>';
return $table;
}
}

View file

@ -1,150 +0,0 @@
<?php
namespace adeattwood\helpers;
use Symfony\Component\VarDumper\VarDumper;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
/**
* Description of Dumper
*
* @author ade
*/
class Dumper
{
public static $styles = array(
'default' => 'background-color:#18171B; color:#FF8400; line-height:1.2em; font:14px Menlo, Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: normal',
'num' => 'font-weight:bold; color:#1299DA',
'const' => 'font-weight:bold',
'str' => 'font-weight:bold; color:#56DB3A',
'note' => 'color:#1299DA',
'ref' => 'color:#A0A0A0',
'public' => 'color:#FFFFFF',
'protected' => 'color:#FFFFFF',
'private' => 'color:#FFFFFF',
'meta' => 'color:#B729D9',
'key' => 'color:#56DB3A',
'index' => 'color:#1299DA',
'ellipsis' => 'color:#FF8400',
);
public static $displayOptions = array(
'maxDepth' => 1,
'maxStringLength' => 160,
'fileLinkFormat' => null,
);
public static function dump( $var ) {
VarDumper::setHandler(function ( $var ) {
$cloner = new VarCloner();
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
$dumper->setStyles(self::$styles);
$dumper->setDisplayOptions(self::$displayOptions);
$dumper->dump($cloner->cloneVar($var));
});
dump($var);
}
public static function dDump( $var )
{
self::dump($var);
die;
}
public static function dumpInfo( $var )
{
$dataArray = [];
$class = new \ReflectionClass($var);
$dataArray['name'] = $class->name;
$methods = $class->getMethods();
$dataArray['constants'] = ( array ) $class->getConstants();
foreach ($class->getProperties() as $propertie) {
$prop = '';
if ($propertie->isPublic()) {
$prop .= 'public';
} elseif ($propertie->isPrivate()) {
$prop .= 'private';
} elseif ($propertie->isProtected()) {
$prop .= 'protected';
}
if ($propertie->isStatic()) {
$prop .= ' static';
}
$prop .= " \${$propertie->name}";
$dataArray['properties'][] = $prop;
}
foreach ($methods as $method) {
$prop = '';
if ($method->isPublic()) {
$prop .= 'public';
} elseif ($method->isPrivate()) {
$prop .= 'private';
} elseif ($method->isProtected()) {
$prop .= 'protected';
}
$prop .= " {$method->name}( ";
$params = '';
foreach ($method->getParameters() as $parameter) {
$params .= "\${$parameter->name}";
if ($parameter->isDefaultValueAvailable()) {
$value = $parameter->getDefaultValue();
if (is_array($value)) {
$value = '[]';
} elseif (is_bool($value)) {
$value = $value ? 'true' : 'false';
}
$params .= "= {$value}";
// self::dDump( $parameter->getDefaultValue() );
}
$params .= ', ';
}
$params = rtrim($params, ', ');
$prop .= "{$params} )";
// $prop .= " : {$method->getReturnType()}";
$dataArray['methords'][$prop] = [
'file' => $method->getFileName(),
'line' => $method->getStartLine(),
'fileLine' => "{$method->getFileName()}:{$method->getStartLine()}",
'doc' => $method->getDocComment()
];
}
sort($dataArray['properties']);
ksort($dataArray['constants']);
ksort($dataArray['methords']);
self::dDump($dataArray);
}
public static function dDumpInfo( $var )
{
self::dumpInfo($var);
die;
}
}

View file

@ -1,67 +0,0 @@
<?php
namespace yiiaddon\web;
use Yii;
use yii\helpers\Url;
/**
* [
* 'class' => 'yiiaddon\web\RedirectRule',
*
* 'route' => '/about',
*
* 'permanents' => [
* 'deprecated-about',
* 'an-older-deprecated-about'
* ],
*
* 'temporaries' => [
* 'under-construction-about',
* ]
* ]
*
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v1.2
*/
class RedirectRule extends \yii\web\UrlRule
{
public $permanents = [];
public $temporaries = [];
public function init()
{
if ($this->pattern === null) {
$this->pattern = false;
}
if ($this->name === null) {
$this->name = $this->route;
}
parent::init();
}
public function parseRequest($manager, $request)
{
$pathInfo = $request->getPathInfo();
if(in_array($pathInfo, $this->permanents)) {
$request->setPathInfo($this->name);
Yii::$app->response->redirect($this->name, 301);
} elseif(in_array($pathInfo, $this->temporaries)) {
$request->setPathInfo($this->name);
Yii::$app->response->redirect($this->name, 302);
}
parent::parseRequest($manager, $request);
Yii::$app->end();
}
}

View file

@ -1,262 +0,0 @@
<?php
namespace yiiaddon\web;
use Yii;
use yii\helpers\Url;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v1.2
*/
class View extends \yii\web\View
{
/**
* If to add facebook og tags to the head
*
* @var boolean
*/
public $facebook_og = true;
/**
* If to add twitter cards to the head tag
*
* @var boolean
*/
public $twitter_card = true;
/**
* Description of the page
*
* @var string
*/
public $description;
/**
* The url of the page
*
* This will be used in the canonical tag
*
* @var string
*/
public $url;
/**
* Keyword to be put in the kewords meata tag
*
* @var string
*/
public $keywords;
/**
* Url to the image to be used in the og and card metas
*
* @var string
*/
public $image;
/**
* The twitter name e.g. '@twitter'
*
* @var string
*/
public $twitterTag;
/**
* The page authers name
*
* @var string
*/
public $authorName;
/**
* The page authers twitter tag
*
* @var string
*/
public $authorTwitterTag;
/**
* The default viewport content used in the viewport meta tag
*
* @var string
*/
public $viewportContent = 'width=device-width, initial-scale=1';
/**
* Googel analytics code to put in the js
*
* @var string
*/
public $googleAnalyticsCode;
/**
* The position to put the google analytics js
*
* Default is `POS_END`
*
* @var integer
*/
public $googleAnalyticsPosition;
/**
* The url to the google analytics js
*
* @var string
*/
public $googleAnalyticsFile = 'https://www.google-analytics.com/analytics.js';
/**
* The js variable the store the google analytics js object in
*
* e.g. `ga('send', 'pageview');`
*
* @var string
*/
public $googleAnalyticsVar = 'ga';
/**
* Google analytics vars to set
*
* @var array
*
* @see https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference#set
*/
protected $googleAnalyticsSet = [];
/**
* Initializes the view instance
*
* @return void
*/
public function init()
{
if (!$this->googleAnalyticsPosition) {
$this->googleAnalyticsPosition = self::POS_END;
}
return parent::init();
}
/**
* Adds a set variable to the google analyitcs script
*
* @see https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference#set
*
* @param string $key The var key
* @param mixed $value The var value
*
* @return void
*/
public function googleAnalyticsSet($key, $value)
{
$this->googleAnalyticsSet[$key] = $value;
}
/**
* Renders the head html adding all of the registers scripts and adding the meta tags
*
* @return string
*/
public function renderHeadHtml()
{
$metas = [
'charset' => ['charset' => Yii::$app->charset],
'viewport' => ['name' => 'viewport', 'content' => $this->viewportContent],
'http-equiv' => ['http-equiv' => 'X-UA-Compatible', 'content' => 'IE=edge'],
'description' => ['name' => 'description', 'content' => $this->description],
'keywords' => $this->keywords ? ['name' => 'keywords', 'content' => $this->keywords] : false,
'author' => $this->authorName ? ['name' => 'author', 'content' => $this->authorName] : false
];
$links = [
'canonical' => ['rel' => 'canonical', 'href' => Url::to($this->url, true)]
];
if ($this->facebook_og) {
$metas = array_merge($metas, $this->registerFacebookOg());
}
if ($this->twitter_card) {
$metas = array_merge($metas, $this->registerTwitterCard());
}
foreach ($metas as $meta => $content) {
if (!isset($this->metaTags[$meta]) && $content) {
$this->registerMetaTag($content, $meta);
}
}
foreach ($links as $link => $content) {
if (!isset($this->metaTags[$link]) && $content) {
$this->registerLinkTag($content, $link);
}
}
if ($this->googleAnalyticsCode) {
$this->registerGoogleAnalytics();
}
return '<title>'.$this->title.'</title>'.parent::renderHeadHtml();
}
/**
* Creates and registers the google analytics scripts
*
* @return void
*/
public function registerGoogleAnalytics()
{
$js = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','$this->googleAnalyticsFile','$this->googleAnalyticsVar');";
$js .= "$this->googleAnalyticsVar('create', '$this->googleAnalyticsCode', 'auto');";
$js .= "$this->googleAnalyticsVar('send', 'pageview');";
foreach ($this->googleAnalyticsSet as $key => $value) {
$js .= "$this->googleAnalyticsVar('set', '$key', '$value');";
}
$this->registerJS($js, $this->googleAnalyticsPosition);
}
/**
* Adds the facebook og meta tags
*
* @return array
*/
public function registerFacebookOg()
{
return [
'og:locale' => ['property' => 'og:locale', 'content' => 'en_GB'],
'og:type' => ['property' => 'og:type', 'content' => 'website'],
'og:title' => ['property' => 'og:title', 'content' => $this->title],
'og:description' => ['property' => 'og:description', 'content' => $this->description],
'og:url' => ['property' => 'og:url', 'content' => Url::to($this->url, true)],
'og:site_name' => ['property' => 'og:site_name', 'content' => Yii::$app->name],
'og:image' => $this->image ? ['property' => 'og:image', 'content' => Url::to($this->image, true)] : false,
];
}
/**
* Adds the twitter card meta tags
*
* @return array
*/
public function registerTwitterCard()
{
return [
'twitter:card' => ['name' => 'twitter:card', 'content' => 'summary'],
'twitter:description' => ['name' => 'twitter:description', 'content' => $this->description],
'twitter:title' => ['name' => 'twitter:title', 'content' => $this->title],
'twitter:url' => ['name' => 'twitter:url', 'content' => Url::to($this->url, true)],
'twitter:site' => $this->twitterTag ? ['name' => 'twitter:site', 'content' => $this->twitterTag] : false,
'twitter:image' => $this->image ? ['name' => 'twitter:image', 'content' => Url::to($this->image, true)] : false,
'twitter:creator' => $this->authorTwitterTag ? ['name' => 'twitter:creator', 'content' => $this->authorTwitterTag] : false,
];
}
}

View file

@ -1,16 +0,0 @@
<?php
namespace yiiaddon\tests\_data;
class ActiveModel extends \yiiaddon\db\ActiveRecord
{
public $id;
public $propOne = 'one';
public $propTwo = 'two';
public $propThree = 'three';
public $propFour = 'four';
public $propFive = 'five';
public $date = 1505655703;
}

View file

@ -1,11 +1,11 @@
<?php
namespace yiiaddon\tests\_data;
namespace adeattwood\helpers\tests\_data;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
@ -13,7 +13,6 @@ namespace yiiaddon\tests\_data;
*/
class ModelOne extends \yii\base\Model
{
/**
* The first test proprety
*
@ -32,5 +31,4 @@ class ModelOne extends \yii\base\Model
[ [ 'propOne' ], 'string' ]
];
}
}

View file

@ -3,8 +3,8 @@ namespace Helper;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk

View file

@ -2,8 +2,8 @@
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk

View file

@ -1,4 +1,4 @@
<?php //[STAMP] a598cdbe5601ddbe60c940fbad750d55
<?php //[STAMP] f70ebbe2fe34ed5c20c33b65fb3a7753
namespace _generated;
// This class was automatically generated by build task
@ -226,36 +226,6 @@ trait UnitTesterActions
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that a string starts with the given prefix.
*
* @param string $prefix
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertStringStartsWith()
*/
public function assertStringStartsWith($prefix, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsWith', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that a string doesn't start with the given prefix.
*
* @param string $prefix
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertStringStartsNotWith()
*/
public function assertStringStartsNotWith($prefix, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsNotWith', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
@ -432,22 +402,6 @@ trait UnitTesterActions
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that array contains subset.
*
* @param array $subset
* @param array $array
* @param bool $strict
* @param string $message
* @see \Codeception\Module\Asserts::assertArraySubset()
*/
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*

View file

@ -1,63 +0,0 @@
<?php
use yiiaddon\db\ActiveQuery;
use yiiaddon\tests\_data\ActiveModel;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v0.1
*/
class ActiveRecordCest
{
/**
* The instace of ActiveModel that we will be using in the tests
*
* @var ActiveModel
*/
public $model;
public function _before( UnitTester $I )
{
$this->model = new ActiveModel(['id' => 1]);
}
public function _after( UnitTester $I )
{
}
public function testGetValue(UnitTester $I)
{
$value = $this->model->getValue('propOne');
$I->assertEquals($value, 'one');
}
public function testGetValueAsDate(UnitTester $I)
{
$value = $this->model->getValue('date:date');
$I->assertEquals($value, 'Sep 17, 2017');
}
public function testParseAttribute(UnitTester $I)
{
$value = $this->model->parseAttribute('date:date');
$I->assertEquals($value->value, 'Sep 17, 2017');
$I->assertEquals($value->raw, 1505655703);
$I->assertEquals($value->format, 'date');
$I->assertEquals($value->lable, 'Date');
}
public function testFind(UnitTester $I)
{
$query = ActiveModel::find();
$I->assertTrue($query instanceof ActiveQuery);
}
}

View file

@ -1,50 +0,0 @@
<?php
use yiiaddon\components\ActiveRecordCollection;
use yiiaddon\helpers\ArrayObject;
use yiiaddon\tests\_data\ActiveModel;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v0.1
*/
class ActiveRecordCollectionCest
{
/**
* The model collection built before every test
*
* @var ActiveRecordCollection
*/
public $model;
public function _before( UnitTester $I )
{
$models = [];
for ($i = 1; $i <= 10; $i++) {
$models[$i] = new ActiveModel(['id' => $i]);
}
$this->model = new ActiveRecordCollection($models);
}
public function _after( UnitTester $I )
{
}
public function testMap(UnitTester $I)
{
$maped = $this->model->map('id', 'propTwo');
$I->assertEquals($maped[1], 'two');
$I->assertEquals($maped->count(), 10);
$I->assertTrue($maped instanceof ArrayObject);
}
}

View file

@ -1,12 +1,12 @@
<?php
use yiiaddon\helpers\ArrayHelper;
use yiiaddon\tests\_data\ModelOne;
use adeattwood\helpers\ArrayHelper;
use adeattwood\helpers\tests\_data\ModelOne;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
@ -44,8 +44,7 @@ class ArrayHelperCest
public function testParseAttribute( UnitTester $I )
{
$model = new ModelOne;
$model->propOne = 'test';
$model->propOne = "test";
$data = ArrayHelper::parseAttribute( $model, 'propOne' );
@ -56,35 +55,4 @@ class ArrayHelperCest
$I->assertEquals( $data->value, 'test' );
$I->assertEquals( $data->raw, 'test' );
}
public function testErrorWithParseAttribute( UnitTester $I )
{
$model = new ModelOne;
$model->propOne = 'test';
try {
$data = ArrayHelper::parseAttribute($model, 'not_a_prop');
$I->fail('Not exseption thrown');
} catch (\yii\base\UnknownPropertyException $e) {
$I->assertEquals($e->getMessage(), 'Getting unknown property: yiiaddon\tests\_data\ModelOne::not_a_prop');
} catch (\Exception $e) {
$I->fail('\yii\base\UnknownPropertyException should have been thorwn');
}
}
public function testInvalidConfigParseAttribute( UnitTester $I )
{
$model = new ModelOne;
$model->propOne = 'test';
try {
$data = ArrayHelper::parseAttribute($model, '');
$I->fail('Not exseption thrown');
} catch (\yii\base\InvalidConfigException $e) {
$I->assertEquals($e->getMessage(), 'The column must be specified in the format of "attribute", "attribute:format" or "attribute:format:label"');
} catch (\Exception $e) {
$I->fail('\yii\base\InvalidConfigException should have been thorwn');
}
}
}

View file

@ -1,11 +1,11 @@
<?php
use yiiaddon\helpers\ArrayObject;
use adeattwood\helpers\ArrayObject;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
@ -16,8 +16,8 @@ class ArrayObjectCest
public $arrayObject;
public $array = [
'key_one' => 'Value One',
'key_two' => 'Value Two'
"key_one" => "Value One",
"key_two" => "Value Two"
];
public function _before( UnitTester $I )
@ -31,7 +31,7 @@ class ArrayObjectCest
public function testArrayAsProps( UnitTester $I )
{
$I->assertEquals($this->arrayObject->key_one, 'Value One');
$I->assertEquals( $this->arrayObject->key_one, "Value One" );
}
/**
@ -41,8 +41,8 @@ class ArrayObjectCest
*/
public function testArrayContains( UnitTester $I )
{
$I->assertTrue($this->arrayObject->contains('Value One'));
$I->assertFalse($this->arrayObject->contains('Not in array'));
$I->assertTrue( $this->arrayObject->contains( "Value One" ) );
$I->assertFalse( $this->arrayObject->contains( "Not in array" ) );
}
/**
@ -57,56 +57,4 @@ class ArrayObjectCest
$I->assertContains( '<table class="table table-bordered table-striped">', $table );
$I->assertContains( '<span title="string" style="cursor: default; border-bottom: 1px #aaa dashed;">Value One</span>', $table );
}
public function testRandomValue( UnitTester $I )
{
for($i = 0; $i < 5; $i++) {
$I->assertContains($this->arrayObject->randomValue(), $this->array);
}
}
public function testPrepend(UnitTester $I)
{
$this->arrayObject->prepend('New Value');
$I->assertEquals($this->arrayObject[0], 'New Value');
$this->arrayObject->prepend(['topProp' => 'Top Value']);
$I->assertEquals($this->arrayObject->topProp, 'Top Value');
}
public function testToJson(UnitTester $I)
{
$json = $this->arrayObject->toJson();
$I->assertEquals($json, '{"key_one":"Value One","key_two":"Value Two"}');
}
public function testChunk(UnitTester $I)
{
$this->arrayObject->combine([
'key_three' => 'Value Three',
'key_four' => 'Value Four',
'key_five' => 'Value Five',
'key_six' => 'Value Six'
]);
$chunks = $this->arrayObject->chunks(2);
$I->assertEquals($chunks->count(), 3);
$I->assertEquals($chunks->{0}->count(), 2);
$I->assertEquals($chunks->{1}->count(), 2);
$I->assertEquals($chunks->{2}->count(), 2);
$I->assertTrue($chunks->{0}->contains('Value One'));
$I->assertFalse($chunks->{0}->contains('Value Three'));
$I->assertTrue($chunks->{1}->contains('Value Three'));
$I->assertFalse($chunks->{1}->contains('Value One'));
$I->assertTrue($chunks->{2}->contains('Value Five'));
$I->assertFalse($chunks->{2}->contains('Value One'));
}
}

View file

@ -1,11 +1,11 @@
<?php
use yiiaddon\helpers\Enum;
use adeattwood\helpers\Enum;
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
@ -24,29 +24,7 @@ class EnumCest
public function testNumberArray( UnitTester $I )
{
$I->assertEquals(Enum::formatBytes(28434322.25), '27.12 MB');
$I->assertEquals(Enum::formatBytes(17328347842.25, 3), '16.138 GB');
}
/**
* @todo test returning a resource
*/
public function testGetTypeReturnValue( UnitTester $I )
{
$array = [
'array' => [ 'key' => 'value' ],
'null' => null,
'boolean' => true,
'float' => 1.2,
'integer' => 3,
'datetime' => '2-2-1989',
'string' => 'I\'m a string',
'unknown' => new StdClass()
];
foreach ($array as $type => $var) {
$I->assertEquals($type, Enum::getType($var));
$I->assertEquals( Enum::formatBytes( 28434322.25 ), "27.12 MB" );
$I->assertEquals( Enum::formatBytes( 17328347842.25, 3 ), "16.138 GB" );
}
}
}

View file

@ -2,16 +2,16 @@
/**
* @category PHP
* @package adeattwood\yii-addon
* @author Ade Attwood <hello@adeattwood.co.uk>
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @copyright 2017 adeattwood.co.uk
* @license BSD-2-Clause http://adeattwood.co.uk/license.html
* @link adeattwood.co.uk
* @since v0.1
*/
require __DIR__.'/../../vendor/autoload.php';
require __DIR__.'/../../vendor/yiisoft/yii2/Yii.php';
require __DIR__ . "/../../vendor/autoload.php";
require __DIR__ . "/../../vendor/yiisoft/yii2/Yii.php";
$config = [
'id' => 'Yii Helpers Tests',