Compare commits

...

9 commits

Author SHA1 Message Date
Ade Attwood
db2ef27329 Update composer.json 2018-01-13 13:45:41 +00:00
Ade Attwood
9e157d6815 Edit ruleset 2017-11-01 19:58:12 +00:00
Ade Attwood
5ee2a60fc1 phpcs and docs 2017-09-17 20:50:44 +01:00
Ade Attwood
074ca1ee4b updates 2017-09-17 18:58:21 +01:00
AdeAttwood
d56bcc42d7 Add active record classes 2017-09-17 09:46:45 +01:00
Ade Attwood
6d2b1b569c move over to addon 2017-09-15 21:06:31 +01:00
Ade Attwood
f015e60d15 Update composer.json 2017-09-15 17:33:03 +00:00
Ade Attwood
049e5d3e72 Update composer.json 2017-09-15 17:26:46 +00:00
Ade Attwood
f95233dad2 Testing and bug fix 2017-06-25 20:43:32 +01:00
29 changed files with 2013 additions and 567 deletions

View file

@ -1,26 +1,26 @@
{
"name": "adeattwood/yii-helpers",
"description": "Helpers for the yii2 framework",
"version": "1.0.1",
"name": "adeattwood/yii-addon",
"description": "Add on for the yii2 framework",
"version": "1.1.0",
"time": "2017-06-24 16:25:17",
"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": {
"adeattwood\\helpers\\": "src"
"yiiaddon\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"adeattwood\\helpers\\tests\\": "tests"
"yiiaddon\\tests\\": "tests"
}
},
"require": {
@ -29,6 +29,7 @@
"require-dev": {
"codeception/specify": "^0.4.6",
"codeception/verify": "^0.3.3",
"codeception/codeception": "^2.3"
"codeception/codeception": "^2.3",
"squizlabs/php_codesniffer": "^2.8"
}
}

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

View file

@ -7,7 +7,7 @@ A collection of uefull helpers for the Yii2 framework
Install with composer
~~~php
compsoer install adeattwood/yii-helpers
compsoer install adeattwood/yii-addon
~~~
## Class docs

178
ruleset.xml Normal file
View file

@ -0,0 +1,178 @@
<?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,153 +0,0 @@
<?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;
}
}

View file

@ -1,155 +0,0 @@
<?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

@ -0,0 +1,74 @@
<?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

@ -0,0 +1,40 @@
<?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));
}
}

31
src/db/ActiveQuery.php Normal file
View file

@ -0,0 +1,31 @@
<?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));
}
}

60
src/db/ActiveRecord.php Normal file
View file

@ -0,0 +1,60 @@
<?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;
}
}

80
src/db/Rankable.php Normal file
View file

@ -0,0 +1,80 @@
<?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;
}
}

189
src/filters/PageMin.php Normal file
View file

@ -0,0 +1,189 @@
<?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,15 +1,17 @@
<?php
namespace adeattwood\helpers;
namespace yiiaddon\helpers;
use Yii;
use adeattwood\helpers\ArrayObject;
use adeattwood\helpers\Enum;
use yii\base\InvalidConfigException;
use yiiaddon\helpers\ArrayObject;
use yiiaddon\helpers\Enum;
/**
* @category PHP
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @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
@ -17,6 +19,7 @@ use adeattwood\helpers\Enum;
*/
class ArrayHelper extends \yii\helpers\ArrayHelper
{
/**
* Creates a array of numbers
*
@ -41,8 +44,8 @@ class ArrayHelper extends \yii\helpers\ArrayHelper
public static function numberArray( $max, $min = 0, $step = 1 )
{
$array = [];
for( $i = $min; $i <= $max; $i += $step ) {
$array[ $i ] = $i;
for($i = $min; $i <= $max; $i += $step) {
$array[$i] = $i;
}
return $array;
}
@ -62,23 +65,24 @@ class ArrayHelper extends \yii\helpers\ArrayHelper
*
* @return ArrayObject The parsed config
*/
public static function parseAttribute( $model, $attribute, $defalts = [ 'format' => "text", 'value' => '( NOT SET )' ] )
public static function parseAttribute( $model, $attribute, $defalts = [] )
{
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"' );
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"');
}
$rawValue = self::getValue( $model, $matches[ 1 ] );
$rawValue = self::getValue($model, $matches[1]);
$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 ] );
$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);
$lable = isset($matches[5]) ? $matches[5] : $model->getAttributeLabel($matches[1]);
return new ArrayObject( [
return new ArrayObject([
'format' => $format,
'value' => $value,
'lable' => $lable,
'raw' => $rawValue
] );
]);
}
}

247
src/helpers/ArrayObject.php Normal file
View file

@ -0,0 +1,247 @@
<?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;
}
}

150
src/helpers/Dumper.php Normal file
View file

@ -0,0 +1,150 @@
<?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,11 +1,11 @@
<?php
namespace adeattwood\helpers;
namespace yiiaddon\helpers;
/**
* @category PHP
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @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
@ -48,29 +48,38 @@ class Enum extends \yii\base\Object
*/
public static function getType( $var )
{
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 ($var === null) {
return self::TYPE_NULL;
}
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;
}
/**
@ -90,7 +99,7 @@ class Enum extends \yii\base\Object
*/
public static function isEmpty( $var )
{
return !isset( $var ) ? true : ( is_array( $var ) ? empty( $var ) : ( $var === null || $var === '' ) );
return !isset($var) ? true : ( is_array($var) ? empty($var) : ( $var === null || $var === '' ) );
}
/**
@ -111,11 +120,12 @@ class Enum extends \yii\base\Object
*/
public static function formatBytes( $bytes, $precision = 2 )
{
$units = [ 'B', 'KB', 'MB', 'GB', 'TB' ];
$bytes = max( $bytes, 0 );
$pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
$pow = min( $pow, count( $units ) - 1 );
$bytes /= pow( 1024, $pow );
return round( $bytes, $precision ) . ' ' . $units[$pow];
$units = [ 'B', 'KB', 'MB', 'GB', 'TB' ];
$bytes = max($bytes, 0);
$pow = floor(( $bytes ? log($bytes) : 0 ) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision).' '.$units[$pow];
}
}

67
src/web/RedirectRule.php Normal file
View file

@ -0,0 +1,67 @@
<?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();
}
}

262
src/web/View.php Normal file
View file

@ -0,0 +1,262 @@
<?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

@ -0,0 +1,16 @@
<?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,18 +1,19 @@
<?php
namespace adeattwood\helpers\tests\_data;
namespace yiiaddon\tests\_data;
/**
* @category PHP
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @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 ModelOne extends \yii\base\Model
{
{
/**
* The first test proprety
*
@ -31,4 +32,5 @@ class ModelOne extends \yii\base\Model
[ [ 'propOne' ], 'string' ]
];
}
}

View file

@ -3,8 +3,8 @@ namespace Helper;
/**
* @category PHP
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @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

View file

@ -2,8 +2,8 @@
/**
* @category PHP
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @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

View file

@ -1,4 +1,4 @@
<?php //[STAMP] f70ebbe2fe34ed5c20c33b65fb3a7753
<?php //[STAMP] a598cdbe5601ddbe60c940fbad750d55
namespace _generated;
// This class was automatically generated by build task
@ -226,6 +226,36 @@ 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.
*
@ -402,6 +432,22 @@ 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

@ -0,0 +1,63 @@
<?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

@ -0,0 +1,50 @@
<?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 adeattwood\helpers\ArrayHelper;
use adeattwood\helpers\tests\_data\ModelOne;
use yiiaddon\helpers\ArrayHelper;
use yiiaddon\tests\_data\ModelOne;
/**
* @category PHP
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @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
@ -25,34 +25,66 @@ class ArrayHelperCest
public function testNumberArray( UnitTester $I )
{
$array = ArrayHelper::numberArray( 10, 2, 2 );
$array = ArrayHelper::numberArray(10, 2, 2);
$I->assertEquals( $array[ 2 ], 2 );
$I->assertFalse( isset( $array[ 3 ] ) );
$I->assertEquals( $array[ 4 ], 4 );
$I->assertEquals($array[2], 2);
$I->assertFalse(isset($array[3]));
$I->assertEquals($array[4], 4);
}
public function testNumberArrayWithStep( UnitTester $I )
{
$array = ArrayHelper::numberArray( 10 );
$array = ArrayHelper::numberArray(10);
$I->assertEquals( $array[ 0 ], 0 );
$I->assertEquals( $array[ 10 ], 10 );
$I->assertFalse( isset( $array[ 11 ] ) );
$I->assertEquals($array[0], 0);
$I->assertEquals($array[10], 10);
$I->assertFalse(isset($array[11]));
}
public function testParseAttribute( UnitTester $I )
{
$model = new ModelOne;
$model->propOne = "test";
$data = ArrayHelper::parseAttribute( $model, 'propOne' );
$model->propOne = 'test';
$I->assertEquals( $data->format, 'text' );
$data = ArrayHelper::parseAttribute($model, 'propOne');
$I->assertEquals( $data->lable, 'Prop One' );
$I->assertEquals($data->format, 'text');
$I->assertEquals( $data->value, 'test' );
$I->assertEquals( $data->raw, 'test' );
$I->assertEquals($data->lable, 'Prop One');
$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 adeattwood\helpers\ArrayObject;
use yiiaddon\helpers\ArrayObject;
/**
* @category PHP
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @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
@ -16,13 +16,13 @@ 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 )
{
$this->arrayObject = new ArrayObject( $this->array );
$this->arrayObject = new ArrayObject($this->array);
}
public function _after( 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'));
}
/**
@ -54,7 +54,59 @@ class ArrayObjectCest
{
$table = $this->arrayObject->toTable();
$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 );
$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 adeattwood\helpers\Enum;
use yiiaddon\helpers\Enum;
/**
* @category PHP
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @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
@ -24,7 +24,29 @@ 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" );
$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));
}
}
}

View file

@ -2,20 +2,20 @@
/**
* @category PHP
* @package adeattwood\yii-helpers
* @author Ade Attwood <attwood16@googlemail.com>
* @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
*/
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',
'basePath' => dirname( __DIR__ )
'basePath' => dirname(__DIR__)
];
( new yii\web\Application( $config ) );
( new yii\web\Application($config) );