diff --git a/.gitignore b/.gitignore index 5ea392f..adebe44 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /vendor/ -/components/ \ No newline at end of file +/components/ + +test.bat +test.php \ No newline at end of file diff --git a/composer.json b/composer.json index 4a873d6..b53f380 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "symfony/validator": "^5.3", "doctrine/annotations": "^1.13", "league/event": "^3.0", - "symfony/cache": "^5 | ^6.0" + "symfony/cache": "^5 | ^6.0", + "laminas/laminas-paginator": "^2.12" }, "require-dev": { "phpunit/phpunit": "^9.5" @@ -29,5 +30,8 @@ { "name": "Raymond Chong" } - ] -} + ], + "scripts": { + "test": "phpunit --bootstrap tests\\Testing.php tests" + } +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index 017b0ba..275e191 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "240828c996ff5531c6b85e50870ed873", + "content-hash": "4ecf1c86aad84ba4e7ffb9ffe453afc9", "packages": [ { "name": "doctrine/annotations", @@ -156,20 +156,20 @@ }, { "name": "laminas/laminas-db", - "version": "2.13.4", + "version": "2.15.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-db.git", - "reference": "cdabb4bfa669c2c0edb0cb4e014c15b41afd3fb1" + "reference": "1125ef2e55108bdfcc1f0030d3a0f9b895e09606" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-db/zipball/cdabb4bfa669c2c0edb0cb4e014c15b41afd3fb1", - "reference": "cdabb4bfa669c2c0edb0cb4e014c15b41afd3fb1", + "url": "https://api.github.com/repos/laminas/laminas-db/zipball/1125ef2e55108bdfcc1f0030d3a0f9b895e09606", + "reference": "1125ef2e55108bdfcc1f0030d3a0f9b895e09606", "shasum": "" }, "require": { - "laminas/laminas-stdlib": "^3.6", + "laminas/laminas-stdlib": "^3.7.1", "php": "^7.3 || ~8.0.0 || ~8.1.0" }, "conflict": { @@ -177,10 +177,10 @@ }, "require-dev": { "laminas/laminas-coding-standard": "~2.2.1", - "laminas/laminas-eventmanager": "^3.4", + "laminas/laminas-eventmanager": "^3.4.0", "laminas/laminas-hydrator": "^3.2 || ^4.3", - "laminas/laminas-servicemanager": "^3.7", - "phpunit/phpunit": "^9.5.5" + "laminas/laminas-servicemanager": "^3.7.0", + "phpunit/phpunit": "^9.5.19" }, "suggest": { "laminas/laminas-eventmanager": "Laminas\\EventManager component", @@ -223,7 +223,7 @@ "type": "community_bridge" } ], - "time": "2021-09-21T18:59:44+00:00" + "time": "2022-04-11T13:26:20+00:00" }, { "name": "laminas/laminas-hydrator", @@ -302,6 +302,85 @@ ], "time": "2021-09-09T09:55:00+00:00" }, + { + "name": "laminas/laminas-paginator", + "version": "2.12.2", + "source": { + "type": "git", + "url": "https://github.com/laminas/laminas-paginator.git", + "reference": "e2e5a17e2b6ca750e4a75b8f34763c63cc6bf8fa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laminas/laminas-paginator/zipball/e2e5a17e2b6ca750e4a75b8f34763c63cc6bf8fa", + "reference": "e2e5a17e2b6ca750e4a75b8f34763c63cc6bf8fa", + "shasum": "" + }, + "require": { + "ext-json": "*", + "laminas/laminas-stdlib": "^3.6.2", + "php": "^7.4 || ~8.0.0 || ~8.1.0" + }, + "conflict": { + "zendframework/zend-paginator": "*" + }, + "require-dev": { + "laminas/laminas-cache": "^3.1.2", + "laminas/laminas-cache-storage-adapter-memory": "^2.0.0", + "laminas/laminas-coding-standard": "^2.3.0", + "laminas/laminas-config": "^3.7.0", + "laminas/laminas-filter": "^2.13.0", + "laminas/laminas-servicemanager": "^3.10.0", + "laminas/laminas-view": "^2.15.0", + "phpunit/phpunit": "^9.5.10", + "psalm/plugin-phpunit": "^0.16.1", + "vimeo/psalm": "^4.15.0" + }, + "suggest": { + "laminas/laminas-cache": "Laminas\\Cache component to support cache features", + "laminas/laminas-filter": "Laminas\\Filter component", + "laminas/laminas-paginator-adapter-laminasdb": "Provides pagination adapters for Select statements and TableGateway instances", + "laminas/laminas-servicemanager": "Laminas\\ServiceManager component", + "laminas/laminas-view": "Laminas\\View component" + }, + "type": "library", + "extra": { + "laminas": { + "component": "Laminas\\Paginator", + "config-provider": "Laminas\\Paginator\\ConfigProvider" + } + }, + "autoload": { + "psr-4": { + "Laminas\\Paginator\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Paginate collections of data from arbitrary sources", + "homepage": "https://laminas.dev", + "keywords": [ + "laminas", + "paginator" + ], + "support": { + "chat": "https://laminas.dev/chat", + "docs": "https://docs.laminas.dev/laminas-paginator/", + "forum": "https://discourse.laminas.dev", + "issues": "https://github.com/laminas/laminas-paginator/issues", + "rss": "https://github.com/laminas/laminas-paginator/releases.atom", + "source": "https://github.com/laminas/laminas-paginator" + }, + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], + "time": "2022-01-11T18:09:02+00:00" + }, { "name": "laminas/laminas-stdlib", "version": "3.7.1", @@ -422,21 +501,21 @@ }, { "name": "mathsgod/data-structure", - "version": "1.4.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/mathsgod/data-structure.git", - "reference": "75c7bcabe68a6b77ba43e39400858285a1d69676" + "reference": "874011acdddca1bf97cda715b46cbfc336e2685e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mathsgod/data-structure/zipball/75c7bcabe68a6b77ba43e39400858285a1d69676", - "reference": "75c7bcabe68a6b77ba43e39400858285a1d69676", + "url": "https://api.github.com/repos/mathsgod/data-structure/zipball/874011acdddca1bf97cda715b46cbfc336e2685e", + "reference": "874011acdddca1bf97cda715b46cbfc336e2685e", "shasum": "" }, "require": { "mathsgod/php-util": "^1.0", - "php": ">=7.3" + "php": ">=7.3 || ~8.0" }, "require-dev": { "phpunit/phpunit": "^9.5" @@ -460,22 +539,22 @@ "description": "Data structure", "support": { "issues": "https://github.com/mathsgod/data-structure/issues", - "source": "https://github.com/mathsgod/data-structure/tree/1.4.0" + "source": "https://github.com/mathsgod/data-structure/tree/1.5.0" }, - "time": "2021-04-08T03:53:44+00:00" + "time": "2022-04-07T10:03:58+00:00" }, { "name": "mathsgod/php-util", - "version": "1.4.1", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/mathsgod/php-util.git", - "reference": "48308298b039cb8416d79588c9b0329667249ad8" + "reference": "9d582256da9d8054db1f9e4cf10e9ee0acecf16a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mathsgod/php-util/zipball/48308298b039cb8416d79588c9b0329667249ad8", - "reference": "48308298b039cb8416d79588c9b0329667249ad8", + "url": "https://api.github.com/repos/mathsgod/php-util/zipball/9d582256da9d8054db1f9e4cf10e9ee0acecf16a", + "reference": "9d582256da9d8054db1f9e4cf10e9ee0acecf16a", "shasum": "" }, "require": { @@ -506,9 +585,9 @@ "description": "a simple php util for data structure", "support": { "issues": "https://github.com/mathsgod/php-util/issues", - "source": "https://github.com/mathsgod/php-util/tree/1.4.1" + "source": "https://github.com/mathsgod/php-util/tree/1.4.2" }, - "time": "2021-09-07T09:53:59+00:00" + "time": "2022-04-06T09:51:21+00:00" }, { "name": "psr/cache", @@ -807,16 +886,16 @@ }, { "name": "symfony/cache-contracts", - "version": "v3.0.0", + "version": "v3.0.1", "source": { "type": "git", "url": "https://github.com/symfony/cache-contracts.git", - "reference": "2f7463f156cf9c665d9317e21a809c3bbff5754e" + "reference": "1c0a181c9ee221afe4fa55b2d13fc63c5ae14348" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/cache-contracts/zipball/2f7463f156cf9c665d9317e21a809c3bbff5754e", - "reference": "2f7463f156cf9c665d9317e21a809c3bbff5754e", + "url": "https://api.github.com/repos/symfony/cache-contracts/zipball/1c0a181c9ee221afe4fa55b2d13fc63c5ae14348", + "reference": "1c0a181c9ee221afe4fa55b2d13fc63c5ae14348", "shasum": "" }, "require": { @@ -866,7 +945,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/cache-contracts/tree/v3.0.0" + "source": "https://github.com/symfony/cache-contracts/tree/v3.0.1" }, "funding": [ { @@ -882,20 +961,20 @@ "type": "tidelift" } ], - "time": "2021-08-17T15:35:52+00:00" + "time": "2022-01-02T09:55:41+00:00" }, { "name": "symfony/deprecation-contracts", - "version": "v3.0.0", + "version": "v3.0.1", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "c726b64c1ccfe2896cb7df2e1331c357ad1c8ced" + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/c726b64c1ccfe2896cb7df2e1331c357ad1c8ced", - "reference": "c726b64c1ccfe2896cb7df2e1331c357ad1c8ced", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", "shasum": "" }, "require": { @@ -933,7 +1012,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.1" }, "funding": [ { @@ -949,7 +1028,7 @@ "type": "tidelift" } ], - "time": "2021-11-01T23:48:49+00:00" + "time": "2022-01-02T09:55:41+00:00" }, { "name": "symfony/polyfill-ctype", @@ -1359,16 +1438,16 @@ }, { "name": "symfony/service-contracts", - "version": "v3.0.0", + "version": "v3.0.1", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "36715ebf9fb9db73db0cb24263c79077c6fe8603" + "reference": "e517458f278c2131ca9f262f8fbaf01410f2c65c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/36715ebf9fb9db73db0cb24263c79077c6fe8603", - "reference": "36715ebf9fb9db73db0cb24263c79077c6fe8603", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/e517458f278c2131ca9f262f8fbaf01410f2c65c", + "reference": "e517458f278c2131ca9f262f8fbaf01410f2c65c", "shasum": "" }, "require": { @@ -1421,7 +1500,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.0.0" + "source": "https://github.com/symfony/service-contracts/tree/v3.0.1" }, "funding": [ { @@ -1437,20 +1516,20 @@ "type": "tidelift" } ], - "time": "2021-11-04T17:53:12+00:00" + "time": "2022-03-13T20:10:05+00:00" }, { "name": "symfony/translation-contracts", - "version": "v3.0.0", + "version": "v3.0.1", "source": { "type": "git", "url": "https://github.com/symfony/translation-contracts.git", - "reference": "1b6ea5a7442af5a12dba3dbd6d71034b5b234e77" + "reference": "c4183fc3ef0f0510893cbeedc7718fb5cafc9ac9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/1b6ea5a7442af5a12dba3dbd6d71034b5b234e77", - "reference": "1b6ea5a7442af5a12dba3dbd6d71034b5b234e77", + "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/c4183fc3ef0f0510893cbeedc7718fb5cafc9ac9", + "reference": "c4183fc3ef0f0510893cbeedc7718fb5cafc9ac9", "shasum": "" }, "require": { @@ -1499,7 +1578,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/translation-contracts/tree/v3.0.0" + "source": "https://github.com/symfony/translation-contracts/tree/v3.0.1" }, "funding": [ { @@ -1515,20 +1594,20 @@ "type": "tidelift" } ], - "time": "2021-09-07T12:43:40+00:00" + "time": "2022-01-02T09:55:41+00:00" }, { "name": "symfony/validator", - "version": "v5.4.6", + "version": "v5.4.7", "source": { "type": "git", "url": "https://github.com/symfony/validator.git", - "reference": "ab461eab209e3be062ba9c609d37b37e8364dbe4" + "reference": "f6402ff65e23b7a701d6938809c6451a8a125a8b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/validator/zipball/ab461eab209e3be062ba9c609d37b37e8364dbe4", - "reference": "ab461eab209e3be062ba9c609d37b37e8364dbe4", + "url": "https://api.github.com/repos/symfony/validator/zipball/f6402ff65e23b7a701d6938809c6451a8a125a8b", + "reference": "f6402ff65e23b7a701d6938809c6451a8a125a8b", "shasum": "" }, "require": { @@ -1612,7 +1691,7 @@ "description": "Provides tools to validate values", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/validator/tree/v5.4.6" + "source": "https://github.com/symfony/validator/tree/v5.4.7" }, "funding": [ { @@ -1628,20 +1707,20 @@ "type": "tidelift" } ], - "time": "2022-03-02T12:42:23+00:00" + "time": "2022-03-31T17:09:19+00:00" }, { "name": "symfony/var-exporter", - "version": "v6.0.6", + "version": "v6.0.7", "source": { "type": "git", "url": "https://github.com/symfony/var-exporter.git", - "reference": "130229a482abf17635a685590958894dfb4b4360" + "reference": "5f1fddb1b3a8394dbfb234044e3ad620a26e1735" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-exporter/zipball/130229a482abf17635a685590958894dfb4b4360", - "reference": "130229a482abf17635a685590958894dfb4b4360", + "url": "https://api.github.com/repos/symfony/var-exporter/zipball/5f1fddb1b3a8394dbfb234044e3ad620a26e1735", + "reference": "5f1fddb1b3a8394dbfb234044e3ad620a26e1735", "shasum": "" }, "require": { @@ -1684,7 +1763,7 @@ "serialize" ], "support": { - "source": "https://github.com/symfony/var-exporter/tree/v6.0.6" + "source": "https://github.com/symfony/var-exporter/tree/v6.0.7" }, "funding": [ { @@ -1700,7 +1779,7 @@ "type": "tidelift" } ], - "time": "2022-03-02T12:58:14+00:00" + "time": "2022-03-31T17:18:25+00:00" }, { "name": "webmozart/assert", @@ -2170,16 +2249,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.6.0", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706" + "reference": "77a32518733312af16a44300404e945338981de3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706", - "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/77a32518733312af16a44300404e945338981de3", + "reference": "77a32518733312af16a44300404e945338981de3", "shasum": "" }, "require": { @@ -2214,9 +2293,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.1" }, - "time": "2022-01-04T19:58:01+00:00" + "time": "2022-03-15T21:29:03+00:00" }, { "name": "phpspec/prophecy", @@ -2605,16 +2684,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.19", + "version": "9.5.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807" + "reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35ea4b7f3acabb26f4bb640f8c30866c401da807", - "reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/12bc8879fb65aef2138b26fc633cb1e3620cffba", + "reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba", "shasum": "" }, "require": { @@ -2692,7 +2771,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.19" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.20" }, "funding": [ { @@ -2704,7 +2783,7 @@ "type": "github" } ], - "time": "2022-03-15T09:57:31+00:00" + "time": "2022-04-01T12:37:26+00:00" }, { "name": "sebastian/cli-parser", @@ -3072,16 +3151,16 @@ }, { "name": "sebastian/environment", - "version": "5.1.3", + "version": "5.1.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "388b6ced16caa751030f6a69e588299fa09200ac" + "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/388b6ced16caa751030f6a69e588299fa09200ac", - "reference": "388b6ced16caa751030f6a69e588299fa09200ac", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7", + "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7", "shasum": "" }, "require": { @@ -3123,7 +3202,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/5.1.3" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.4" }, "funding": [ { @@ -3131,7 +3210,7 @@ "type": "github" } ], - "time": "2020-09-28T05:52:38+00:00" + "time": "2022-04-03T09:37:03+00:00" }, { "name": "sebastian/exporter", @@ -3731,5 +3810,5 @@ "ext-pdo": "*" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.0.0" } diff --git a/src/Paginator/Adapter.php b/src/Paginator/Adapter.php new file mode 100644 index 0000000..d28adb0 --- /dev/null +++ b/src/Paginator/Adapter.php @@ -0,0 +1,29 @@ +query = $query; + } + + function getItems($offset, $itemCountPerPage) + { + $this->query->offset($offset); + $this->query->limit($itemCountPerPage); + return new ArrayObject($this->query->toArray()); + } + + function count(): int + { + return $this->query->count(); + } +} diff --git a/src/Query.php b/src/Query.php index c730133..0bbfb22 100644 --- a/src/Query.php +++ b/src/Query.php @@ -11,6 +11,9 @@ use Laminas\Db\Sql\Delete; use Laminas\Db\Sql\Expression; use Laminas\Db\Sql\Update; +use Laminas\Paginator\Paginator; +use R\DB\Paginator\Adapter; +use Traversable; /** * @method static order(string|array|Expression $order) @@ -162,19 +165,17 @@ public function execute(array $input_parameters = []) } $a->add($obj); } - - - } return $a; } - public function getIterator() + function getIterator(): Traversable { return $this->execute(); } + /** * @return T[] */ @@ -209,4 +210,9 @@ public function map(callable $map) { return collect($this)->map($map); } + + public function getPaginator() + { + return new Paginator(new Adapter($this)); + } } diff --git a/test.bat b/test.bat deleted file mode 100644 index 7f68938..0000000 --- a/test.bat +++ /dev/null @@ -1 +0,0 @@ -vendor\bin\phpunit --bootstrap tests\Testing.php tests \ No newline at end of file diff --git a/test.php b/test.php deleted file mode 100644 index 81d6cb7..0000000 --- a/test.php +++ /dev/null @@ -1,312 +0,0 @@ -getTable("User"); -print_r($table->first()); - -die(); - -$schema = Model::GetSchema(); - -$schema->beginTransaction(); -$ug = new UserGroup(); -$ug->name = "Test"; -$ug->delete(); -$schema->rollback(); - - - -die(); -$dispatcher = $schema->eventDispatcher(); -$dispatcher->subscribeTo(BeforeInsert::class, function (BeforeInsert $event) { - echo "1"; - print_r($event); -}); - -$dispatcher->subscribeTo(BeforeInsert::class, function (BeforeInsert $event) { - echo "2"; - print_r($event); -}); - -$dispatcher->subscribeTo(AfterDelete::class, function (AfterDelete $event) { - print_r($event); -}); - - -$d = UserGroup::Create(['name' => 'test1']); -$d->save(); -$d->delete();; - - -$ug = UserGroup::Query(); - - - - -die(); - - -$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator(); -$schema->setDefaultValidator($validator); - -$ugs = UserGroup::Query()->toArray(); -$ug = $ugs[0]; -$ug->name = ""; -$ug->save(); - - -die(); - - -print_r(new User(1)); -die(); - -print_r(User::Load(1)->UserLog->delete()); -die(); - -foreach (Testing::_table()->columns() as $column) { - print_r($column->getMetaData()); - die(); -} -die(); - - -foreach ($rows as $row) { - $row->delete(); - die(); -} - - -die(); -$db = Model::GetSchema(); -foreach ($db->getTables() as $t) { - echo $t->name; -} - -die(); -$res = $db->alterTable("Testing", function (AlterTable $table) { - $column = new Column("test_abc"); - - - $table->addColumn($column); -}); - -print_R($res); - -die(); - - - - - -$db = Model::GetSchema(); - -$sql = new Sql($db->getDbAdatpter()); -$select = $sql->select(); -$select->from('foo'); -$select->where(['id' => 2]); -$sql->prepareStatementForSqlObject($select); - - - - -print_R($db->query("Select * from User")->fetchAll()); - -die(); -echo User::Load(1)->UserList->count(); -die(); -print_r(get_class(User::Load(1)->UserList())); -die(); -print_r(new Testing2(2)); - -die(); -print_r(Testing::Query()->count()); -die(); - -$t = new Testing(); -$t->name = "abc"; -$t->save(); - -die(); - - -$s = Testing::GetSchema(); -echo $i = $s->exec("select * from User"); -die(); -$t = $schema->table("Testing"); -$t->column("name")->rename("name1"); - -die(); - - - - - -return; -print_r(new User(1)); -die(); - -print_r(User::_table()->describe()); -die(); - -print_r(User::Query(["user_id" => 1])->toArray()); - -die(); -$adatper = User::GetSchema()->adatper; - -$statmemt = $adatper->createStatement("Select * from User"); -$statmemt->prepare(); -$s = $statmemt->getResource(); - -$s->execute(); -$s->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, "UserA", []); -print_r($s->fetchAll()); - -die(); - -print_r(User::Query(["user_id" => 1])->first()); - - -return; -// Script start -$rustart = getrusage(); - -foreach (range(1, 100000) as $i) { - UserList::Query()->toArray(); -} - - -// Script end -function rutime($ru, $rus, $index) -{ - return ($ru["ru_$index.tv_sec"] * 1000 + intval($ru["ru_$index.tv_usec"] / 1000)) - - ($rus["ru_$index.tv_sec"] * 1000 + intval($rus["ru_$index.tv_usec"] / 1000)); -} - - -$ru = getrusage(); -echo "This process used " . rutime($ru, $rustart, "utime") . - " ms for its computations\n"; -echo "It spent " . rutime($ru, $rustart, "stime") . - " ms in system calls\n"; -die(); - - -print_r(User::Query()->where(function (Where $where) { - $where->equalTo("user_id", 1); -})->toArray()); - -//print_r(User::Query()->toArray()); - -die(); - - - -print_r(Testing::Query()->setOrderMap("a", "(select count(*) from Testing)")->orderBy(["a" => "desc"])->sql()); -die(); - - -$t = new Testing(3); -print_R($t->Testing2()); -exit(); -$q = Testing::Query(); -//$list = $q->toList(); - -//$list[0]->name = "1a"; - -//print_r($q->toArray()); - -$q->where("name like :name"); - - -print_r($q->toArray(["name" => "%1%"])); - - - - - -die(); - -$table = User::_table(); - - -$q = User::Query()->where("username like :u or password like :u", ["u" => "a"]); - -print_r($q->toArray()); - -die(); - - -print_r($table->describe()); -die(); - -$a = ["a" => 1, "b" => null]; -//unset($a["b"]); -print_r($a); - -return; - -/*print_r(User::Query()->filter([ - "username" => "admin" -])->toArray()[0]->username); -die(); -*/ -foreach (User::Query()->select(["username"]) as $a) { - print_r($a); -} -return; - -print_r(Testing::__attribute()); -return; -$a = new stdClass(); -$st = Testing::_table()->where(["testing_id" => 100])->get(); -$st->setFetchMode(PDO::FETCH_INTO, $a); -if ($st->fetch() === false) { - echo "false"; -} else { - print_r($a); -} - - - -return; -$t = new Testing(1); - -$t->delete(); - - -return; -$q = new R\DB\Query(Testing::GetSchema(), "Testing"); -$q->where(["name" => 1]); - -print_r($q);