diff --git a/composer.json b/composer.json index 37164c5..92831e5 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "drupal-core", "license": "GPL-2.0+", "require": { - "php": ">5.4.4-13", + "php": ">5.4.5", "sdboyer/gliph": "0.1.*", "symfony/class-loader": "2.5.*", "symfony/css-selector": "2.5.*", @@ -23,6 +23,8 @@ "kriswallsmith/assetic": "1.1.*@alpha", "symfony-cmf/routing": "1.2.*", "easyrdf/easyrdf": "0.8.*", + "ocramius/proxy-manager": "0.5.*", + "symfony/proxy-manager-bridge": "2.5.*", "phpunit/phpunit": "4.1.*", "phpunit/phpunit-mock-objects": "dev-master#e60bb929c50ae4237aaf680a4f6773f4ee17f0a2", "zendframework/zend-feed": "2.2.*", diff --git a/composer.lock b/composer.lock index 371f59e..30374d1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "84084dce2bc995cf540fa58e5f3c796d", + "hash": "edda2f2d9298642b2e82d0b46f600db0", "packages": [ { "name": "doctrine/annotations", @@ -736,6 +736,71 @@ "time": "2014-07-21 20:15:54" }, { + "name": "ocramius/proxy-manager", + "version": "0.5.0", + "source": { + "type": "git", + "url": "https://github.com/Ocramius/ProxyManager.git", + "reference": "3b3b7101b1eea62afe039db50faee0d3a9e3e330" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Ocramius/ProxyManager/zipball/3b3b7101b1eea62afe039db50faee0d3a9e3e330", + "reference": "3b3b7101b1eea62afe039db50faee0d3a9e3e330", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "zendframework/zend-code": "2.*" + }, + "require-dev": { + "phpmd/phpmd": "1.4.*", + "phpunit/phpunit": ">=3.7", + "satooshi/php-coveralls": "~0.6", + "squizlabs/php_codesniffer": "1.4.*" + }, + "suggest": { + "ocramius/generated-hydrator": "To have very fast object to array to object conversion for ghost objects", + "zendframework/zend-json": "To have the JsonRpc adapter (Remote Object feature)", + "zendframework/zend-soap": "To have the Soap adapter (Remote Object feature)", + "zendframework/zend-stdlib": "To use the hydrator proxy", + "zendframework/zend-xmlrpc": "To have the XmlRpc adapter (Remote Object feature)" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.5.x-dev" + } + }, + "autoload": { + "psr-0": { + "ProxyManager\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/", + "role": "Developer" + } + ], + "description": "A library providing utilities to generate, instantiate and generally operate with Object Proxies", + "homepage": "https://github.com/Ocramius/ProxyManager", + "keywords": [ + "aop", + "lazy loading", + "proxy", + "proxy pattern", + "service proxies" + ], + "time": "2013-11-30 15:00:46" + }, + { "name": "phpunit/php-code-coverage", "version": "2.0.8", "source": { @@ -2015,6 +2080,58 @@ "time": "2014-09-23 05:25:11" }, { + "name": "symfony/proxy-manager-bridge", + "version": "v2.5.5", + "target-dir": "Symfony/Bridge/ProxyManager", + "source": { + "type": "git", + "url": "https://github.com/symfony/ProxyManagerBridge.git", + "reference": "aea5f3f814221b2cd4eac6c8fd91fdee006c498a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/ProxyManagerBridge/zipball/aea5f3f814221b2cd4eac6c8fd91fdee006c498a", + "reference": "aea5f3f814221b2cd4eac6c8fd91fdee006c498a", + "shasum": "" + }, + "require": { + "ocramius/proxy-manager": ">=0.3.1,<0.6-dev", + "php": ">=5.3.3", + "symfony/dependency-injection": "~2.3" + }, + "require-dev": { + "symfony/config": "2.3" + }, + "type": "symfony-bridge", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Bridge\\ProxyManager\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony ProxyManager Bridge", + "homepage": "http://symfony.com", + "time": "2014-09-22 15:28:36" + }, + { "name": "symfony/routing", "version": "v2.5.5", "target-dir": "Symfony/Component/Routing", @@ -2351,6 +2468,54 @@ "time": "2013-12-06 07:47:10" }, { + "name": "zendframework/zend-code", + "version": "2.2.1", + "target-dir": "Zend/Code", + "source": { + "type": "git", + "url": "https://github.com/zendframework/Component_ZendCode.git", + "reference": "83ef7d8bc1fbf08f6eec04215b2ba309e543a5fa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/Component_ZendCode/zipball/83ef7d8bc1fbf08f6eec04215b2ba309e543a5fa", + "reference": "83ef7d8bc1fbf08f6eec04215b2ba309e543a5fa", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "zendframework/zend-eventmanager": "self.version" + }, + "require-dev": { + "doctrine/common": ">=2.1" + }, + "suggest": { + "doctrine/common": "Doctrine\\Common >=2.1 for annotation features" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev", + "dev-develop": "2.3-dev" + } + }, + "autoload": { + "psr-0": { + "Zend\\Code\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "provides facilities to generate arbitrary code using an object oriented interface", + "keywords": [ + "code", + "zf2" + ], + "time": "2013-06-12 19:48:38" + }, + { "name": "zendframework/zend-escaper", "version": "2.2.1", "target-dir": "Zend/Escaper", @@ -2391,6 +2556,47 @@ "time": "2013-05-01 21:53:03" }, { + "name": "zendframework/zend-eventmanager", + "version": "2.2.1", + "target-dir": "Zend/EventManager", + "source": { + "type": "git", + "url": "https://github.com/zendframework/Component_ZendEventManager.git", + "reference": "f325feef4e1a19b873936e5b116980fbe88dd176" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/Component_ZendEventManager/zipball/f325feef4e1a19b873936e5b116980fbe88dd176", + "reference": "f325feef4e1a19b873936e5b116980fbe88dd176", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "zendframework/zend-stdlib": "self.version" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev", + "dev-develop": "2.3-dev" + } + }, + "autoload": { + "psr-0": { + "Zend\\EventManager\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "keywords": [ + "eventmanager", + "zf2" + ], + "time": "2013-06-12 19:45:10" + }, + { "name": "zendframework/zend-feed", "version": "2.2.1", "target-dir": "Zend/Feed", @@ -2498,7 +2704,7 @@ }, "prefer-stable": false, "platform": { - "php": ">=5.4.2" + "php": ">5.4.5" }, "platform-dev": [ diff --git a/core/core.services.yml b/core/core.services.yml index 1d9b2d2..72713ae 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -201,6 +201,7 @@ services: logger.factory: class: Drupal\Core\Logger\LoggerChannelFactory parent: container.trait + lazy: true tags: - { name: service_collector, tag: logger, call: addLogger } logger.channel_base: @@ -208,23 +209,30 @@ services: class: Drupal\Core\Logger\LoggerChannel factory_method: get factory_service: logger.factory + lazy: true logger.channel.default: parent: logger.channel_base arguments: ['system'] + lazy: true logger.channel.php: parent: logger.channel_base arguments: ['php'] + lazy: true logger.channel.image: parent: logger.channel_base arguments: ['image'] + lazy: true logger.channel.cron: parent: logger.channel_base arguments: ['cron'] + lazy: true logger.channel.form: parent: logger.channel_base arguments: ['form'] + lazy: true logger.log_message_parser: class: Drupal\Core\Logger\LogMessageParser + lazy: true serialization.json: class: Drupal\Component\Serialization\Json @@ -448,6 +456,7 @@ services: lock: class: Drupal\Core\Lock\DatabaseLockBackend arguments: ['@database'] + lazy: true tags: - { name: backend_overridable } router.request_context: diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 6a9b78d..cf09c14 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -22,6 +22,7 @@ use Drupal\Core\PageCache\RequestPolicyInterface; use Drupal\Core\PhpStorage\PhpStorageFactory; use Drupal\Core\Site\Settings; +use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; @@ -1135,6 +1136,9 @@ protected function dumpDrupalContainer(ContainerBuilder $container, $baseClass) } // Cache the container. $dumper = new PhpDumper($container); + $proxy_dumper = new ProxyDumper(); + $dumper->setProxyDumper($proxy_dumper); + $class = $this->getClassName(); $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass)); return $this->storage()->save($class . '.php', $content); diff --git a/core/vendor/composer/autoload_namespaces.php b/core/vendor/composer/autoload_namespaces.php index 50cec57..c4e45ba 100644 --- a/core/vendor/composer/autoload_namespaces.php +++ b/core/vendor/composer/autoload_namespaces.php @@ -9,7 +9,9 @@ 'org\\bovigo\\vfs\\' => array($vendorDir . '/mikey179/vfsStream/src/main/php'), 'Zend\\Stdlib\\' => array($vendorDir . '/zendframework/zend-stdlib'), 'Zend\\Feed\\' => array($vendorDir . '/zendframework/zend-feed'), + 'Zend\\EventManager\\' => array($vendorDir . '/zendframework/zend-eventmanager'), 'Zend\\Escaper\\' => array($vendorDir . '/zendframework/zend-escaper'), + 'Zend\\Code\\' => array($vendorDir . '/zendframework/zend-code'), 'Twig_' => array($vendorDir . '/twig/twig/lib'), 'Symfony\\Component\\Yaml\\' => array($vendorDir . '/symfony/yaml'), 'Symfony\\Component\\Validator\\' => array($vendorDir . '/symfony/validator'), @@ -25,8 +27,10 @@ 'Symfony\\Component\\CssSelector\\' => array($vendorDir . '/symfony/css-selector'), 'Symfony\\Component\\ClassLoader\\' => array($vendorDir . '/symfony/class-loader'), 'Symfony\\Cmf\\Component\\Routing' => array($vendorDir . '/symfony-cmf/routing'), + 'Symfony\\Bridge\\ProxyManager\\' => array($vendorDir . '/symfony/proxy-manager-bridge'), 'Stack' => array($vendorDir . '/stack/builder/src'), 'Psr\\Log\\' => array($vendorDir . '/psr/log'), + 'ProxyManager\\' => array($vendorDir . '/ocramius/proxy-manager/src'), 'Gliph' => array($vendorDir . '/sdboyer/gliph/src'), 'Egulias\\' => array($vendorDir . '/egulias/email-validator/src'), 'EasyRdf_' => array($vendorDir . '/easyrdf/easyrdf/lib'), diff --git a/core/vendor/composer/installed.json b/core/vendor/composer/installed.json index 5623c7f..e05fbc1 100644 --- a/core/vendor/composer/installed.json +++ b/core/vendor/composer/installed.json @@ -2564,5 +2564,219 @@ ], "description": "Symfony Yaml Component", "homepage": "http://symfony.com" + }, + { + "name": "zendframework/zend-eventmanager", + "version": "2.2.1", + "version_normalized": "2.2.1.0", + "target-dir": "Zend/EventManager", + "source": { + "type": "git", + "url": "https://github.com/zendframework/Component_ZendEventManager.git", + "reference": "f325feef4e1a19b873936e5b116980fbe88dd176" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/Component_ZendEventManager/zipball/f325feef4e1a19b873936e5b116980fbe88dd176", + "reference": "f325feef4e1a19b873936e5b116980fbe88dd176", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "zendframework/zend-stdlib": "self.version" + }, + "time": "2013-06-12 19:45:10", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev", + "dev-develop": "2.3-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Zend\\EventManager\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "keywords": [ + "eventmanager", + "zf2" + ] + }, + { + "name": "zendframework/zend-code", + "version": "2.2.1", + "version_normalized": "2.2.1.0", + "target-dir": "Zend/Code", + "source": { + "type": "git", + "url": "https://github.com/zendframework/Component_ZendCode.git", + "reference": "83ef7d8bc1fbf08f6eec04215b2ba309e543a5fa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/Component_ZendCode/zipball/83ef7d8bc1fbf08f6eec04215b2ba309e543a5fa", + "reference": "83ef7d8bc1fbf08f6eec04215b2ba309e543a5fa", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "zendframework/zend-eventmanager": "self.version" + }, + "require-dev": { + "doctrine/common": ">=2.1" + }, + "suggest": { + "doctrine/common": "Doctrine\\Common >=2.1 for annotation features" + }, + "time": "2013-06-12 19:48:38", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev", + "dev-develop": "2.3-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Zend\\Code\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "provides facilities to generate arbitrary code using an object oriented interface", + "keywords": [ + "code", + "zf2" + ] + }, + { + "name": "ocramius/proxy-manager", + "version": "0.5.0", + "version_normalized": "0.5.0.0", + "source": { + "type": "git", + "url": "https://github.com/Ocramius/ProxyManager.git", + "reference": "3b3b7101b1eea62afe039db50faee0d3a9e3e330" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Ocramius/ProxyManager/zipball/3b3b7101b1eea62afe039db50faee0d3a9e3e330", + "reference": "3b3b7101b1eea62afe039db50faee0d3a9e3e330", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "zendframework/zend-code": "2.*" + }, + "require-dev": { + "phpmd/phpmd": "1.4.*", + "phpunit/phpunit": ">=3.7", + "satooshi/php-coveralls": "~0.6", + "squizlabs/php_codesniffer": "1.4.*" + }, + "suggest": { + "ocramius/generated-hydrator": "To have very fast object to array to object conversion for ghost objects", + "zendframework/zend-json": "To have the JsonRpc adapter (Remote Object feature)", + "zendframework/zend-soap": "To have the Soap adapter (Remote Object feature)", + "zendframework/zend-stdlib": "To use the hydrator proxy", + "zendframework/zend-xmlrpc": "To have the XmlRpc adapter (Remote Object feature)" + }, + "time": "2013-11-30 15:00:46", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.5.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "ProxyManager\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/", + "role": "Developer" + } + ], + "description": "A library providing utilities to generate, instantiate and generally operate with Object Proxies", + "homepage": "https://github.com/Ocramius/ProxyManager", + "keywords": [ + "aop", + "lazy loading", + "proxy", + "proxy pattern", + "service proxies" + ] + }, + { + "name": "symfony/proxy-manager-bridge", + "version": "v2.5.5", + "version_normalized": "2.5.5.0", + "target-dir": "Symfony/Bridge/ProxyManager", + "source": { + "type": "git", + "url": "https://github.com/symfony/ProxyManagerBridge.git", + "reference": "aea5f3f814221b2cd4eac6c8fd91fdee006c498a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/ProxyManagerBridge/zipball/aea5f3f814221b2cd4eac6c8fd91fdee006c498a", + "reference": "aea5f3f814221b2cd4eac6c8fd91fdee006c498a", + "shasum": "" + }, + "require": { + "ocramius/proxy-manager": ">=0.3.1,<0.6-dev", + "php": ">=5.3.3", + "symfony/dependency-injection": "~2.3" + }, + "require-dev": { + "symfony/config": "2.3" + }, + "time": "2014-09-22 15:28:36", + "type": "symfony-bridge", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Bridge\\ProxyManager\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony ProxyManager Bridge", + "homepage": "http://symfony.com" } ] diff --git a/core/vendor/ocramius/proxy-manager/.scrutinizer.yml b/core/vendor/ocramius/proxy-manager/.scrutinizer.yml new file mode 100644 index 0000000..095ce35 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/.scrutinizer.yml @@ -0,0 +1,39 @@ +before_commands: + - "composer install --no-dev --prefer-source" + +tools: + php_code_coverage: + enabled: true + test_command: phpunit -c phpunit.xml.dist --exclude-group Functional,Performance + #filter: + #paths: ["src"] + php_code_sniffer: + enabled: true + config: + standard: PSR2 + filter: + paths: ["src/*", "tests/*"] + php_cpd: + enabled: true + excluded_dirs: ["build/*", "docs", "examples", "tests", "vendor"] + php_cs_fixer: + enabled: true + config: + level: all + filter: + paths: ["src/*", "tests/*"] + php_loc: + enabled: true + excluded_dirs: ["build", "docs", "examples", "tests", "vendor"] + php_mess_detector: + enabled: true + filter: + paths: ["src/*"] + php_pdepend: + enabled: true + excluded_dirs: ["build", "docs", "examples", "tests", "vendor"] + php_analyzer: true + php_analyzer: + filter: + paths: ["src/*", "tests/*", "examples/*"] + sensiolabs_security_checker: true diff --git a/core/vendor/ocramius/proxy-manager/.travis.yml b/core/vendor/ocramius/proxy-manager/.travis.yml new file mode 100644 index 0000000..ef9de34 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/.travis.yml @@ -0,0 +1,20 @@ +language: php + +php: + - 5.3.3 + - 5.3 + - 5.4 + - 5.5 + +before_script: + - composer self-update + - composer update --prefer-source; composer install --dev --prefer-source; + +script: + - ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml --exclude-group Performance + - ./vendor/bin/phpunit ./tests/language-feature-scripts/ + - php -n ./vendor/bin/phpunit --group=Performance + - ./vendor/bin/phpcs --standard=PSR2 ./src/ ./tests/ + +after_script: + - php vendor/bin/coveralls -v diff --git a/core/vendor/ocramius/proxy-manager/CONTRIBUTING.md b/core/vendor/ocramius/proxy-manager/CONTRIBUTING.md new file mode 100644 index 0000000..d07d8dc --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/CONTRIBUTING.md @@ -0,0 +1,35 @@ +# Contributing + + * Coding standard for the project is [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) + * The project will follow strict [object calisthenics](http://www.slideshare.net/guilhermeblanco/object-calisthenics-applied-to-php) + * Any contribution must provide tests for additional introduced conditions + * Any un-confirmed issue needs a failing test case before being accepted + * Pull requests must be sent from a new hotfix/feature branch, not from `master`. + +## Installation + +To install the project and run the tests, you need to clone it first: + +```sh +$ git clone git://github.com/Ocramius/ProxyManager.git +``` + +You will then need to run a composer installation: + +```sh +$ cd ProxyManager +$ curl -s https://getcomposer.org/installer | php +$ php composer.phar update +``` + +## Testing + +The PHPUnit version to be used is the one installed as a dev- dependency via composer: + +```sh +$ ./vendor/bin/phpunit +``` + +Accepted coverage for new contributions is 80%. Any contribution not satisfying this requirement +won't be merged. + diff --git a/core/vendor/ocramius/proxy-manager/LICENSE b/core/vendor/ocramius/proxy-manager/LICENSE new file mode 100644 index 0000000..49adae0 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2013 Marco Pivetta + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/README.md b/core/vendor/ocramius/proxy-manager/README.md new file mode 100644 index 0000000..e7f9944 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/README.md @@ -0,0 +1,193 @@ +# Proxy Manager + +This library aims at providing abstraction for generating various kinds of [proxy classes](http://marco-pivetta.com/proxy-pattern-in-php/). + +![ProxyManager](proxy-manager.png) + +[![Build Status](https://travis-ci.org/Ocramius/ProxyManager.png?branch=master)](https://travis-ci.org/Ocramius/ProxyManager) +[![Coverage Status](https://coveralls.io/repos/Ocramius/ProxyManager/badge.png?branch=master)](https://coveralls.io/r/Ocramius/ProxyManager) +[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/Ocramius/ProxyManager/badges/quality-score.png?s=eaa858f876137ed281141b1d1e98acfa739729ed)](https://scrutinizer-ci.com/g/Ocramius/ProxyManager/) +[![Total Downloads](https://poser.pugx.org/ocramius/proxy-manager/downloads.png)](https://packagist.org/packages/ocramius/proxy-manager) +[![Latest Stable Version](https://poser.pugx.org/ocramius/proxy-manager/v/stable.png)](https://packagist.org/packages/ocramius/proxy-manager) +[![Latest Unstable Version](https://poser.pugx.org/ocramius/proxy-manager/v/unstable.png)](https://packagist.org/packages/ocramius/proxy-manager) +[![Dependency Status](https://www.versioneye.com/package/php--ocramius--proxy-manager/badge.png)](https://www.versioneye.com/package/php--ocramius--proxy-manager) + +## Installation + +The suggested installation method is via [composer](https://getcomposer.org/): + +```sh +php composer.phar require ocramius/proxy-manager:0.5.* +``` + +## Lazy Loading Value Holders (Virtual Proxy) + +ProxyManager can generate [lazy loading value holders](http://www.martinfowler.com/eaaCatalog/lazyLoad.html), +which are virtual proxies capable of saving performance and memory for objects that require a lot of dependencies or +CPU cycles to be loaded: particularly useful when you may not always need the object, but are constructing it anyways. + +```php +$factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory(); + +$proxy = $factory->createProxy( + 'MyApp\HeavyComplexObject', + function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) { + $wrappedObject = new HeavyComplexObject(); // instantiation logic here + $initializer = null; // turning off further lazy initialization + + return true; + } +); + +$proxy->doFoo(); +``` + +See the [complete documentation about lazy loading value holders](/docs/lazy-loading-value-holder.md) +in the `docs/` directory. + +## Access Interceptor Value Holder + +An access interceptor value holder is a smart reference that allows you to execute logic before +and after a particular method is executed or a particular property is accessed, and it allows to +manipulate parameters and return values depending on your needs. + +```php +$factory = new \ProxyManager\Factory\AccessInterceptorValueHolderFactory(); + +$proxy = $factory->createProxy( + new \My\Db\Connection(), + array('query' => function () { echo "Query being executed!\n"; }), + array('query' => function () { echo "Query completed!\n"; }) +); + +$proxy->query(); // produces "Query being executed!\nQuery completed!\n" +``` + +See the [complete documentation about access interceptor value holders](/docs/access-interceptor-value-holder.md) +in the `docs/` directory. + +## Access Interceptor Scope Localizer + +An access interceptor scope localizer works exactly like an access interceptor value holder, +but it is safe to use to proxy fluent interfaces. + +See the [complete documentation about access interceptor scope localizer](/docs/access-interceptor-scope-localizer.md) +in the `docs/` directory. + +## Null Objects + +A Null Object proxy implements the [null object pattern](http://en.wikipedia.org/wiki/Null_Object_pattern). + +This kind of proxr allows you to have fallback logic in case loading of the wrapped value failed. + +```php +$factory = new \ProxyManager\Factory\NullObjectFactory(); + +$proxy = $factory->createProxy('My\EntityObject'); + +$proxy->getName(); // empty return +``` + +A Null Object Proxy can be created from an object, a class name or an interface name: + +```php +$factory = new \ProxyManager\Factory\NullObjectFactory(); + +$proxy = $factory->createProxy('My\EntityObjectInterface'); // created from interface name +$proxy->getName(); // empty return + +$proxy = $factory->createProxy($entity); // created from object +$proxy->getName(); // empty return +``` + +See the [complete documentation about null object proxy](/docs/null-object.md) +in the `docs/` directory. + +## Ghost Objects + + +Similar to value holder, a ghost object is usually created to handle lazy loading. + +The difference between a value holder and a ghost object is that the ghost object does not contain a real instance of +the required object, but handles lazy loading by initializing its own inherited properties. + +ProxyManager can generate [lazy loading ghost objects](http://www.martinfowler.com/eaaCatalog/lazyLoad.html), +which are proxies used to save performance and memory for large datasets and graphs representing relational data. +Ghost objects are particularly useful when building data-mappers. + +Additionally, the overhead introduced by ghost objects is very low when compared to the memory and performance overhead +caused by virtual proxies. + +```php +$factory = new \ProxyManager\Factory\LazyLoadingGhostFactory(); + +$proxy = $factory->createProxy( + 'MyApp\HeavyComplexObject', + function ($proxy, $method, $parameters, & $initializer) { + $initializer = null; // turning off further lazy initialization + + // modify the proxy instance + $proxy->setFoo('foo'); + $proxy->setBar('bar'); + + return true; + } +); + +$proxy->doFoo(); +``` + +See the [complete documentation about lazy loading ghost objects](/docs/lazy-loading-ghost-object.md) +in the `docs/` directory. + +This feature is [planned](https://github.com/Ocramius/ProxyManager/issues/6). + +## Lazy References + +A lazy reference proxy is actually a proxy backed by some kind of reference holder (usually a registry) that can fetch +existing instances of a particular object. + +A lazy reference is usually necessary when multiple instances of the same object can be avoided, or when the instances +are not hard links (like with [Weakref](http://php.net/manual/en/book.weakref.php)), and could be garbage-collected to +save memory in long time running processes. + +This feature [yet to be planned](https://github.com/Ocramius/ProxyManager/issues/8). + +## Remote Object + +A remote object proxy is an object that is located on a different system, but is used as if it was available locally. +There's various possible remote proxy implementations, which could be based on xmlrpc/jsonrpc/soap/dnode/etc. + +This example uses the XML-RPC client of Zend Framework 2: + +```php +interface FooServiceInterface +{ + public function foo(); +} + +$factory = new \ProxyManager\Factory\RemoteObjectFactory( + new \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc( + new \Zend\XmlRpc\Client('https://example.com/rpc-endpoint') + ) +); + +// proxy is your remote implementation +$proxy = $factory->createProxy('FooServiceInterface'); + +var_dump($proxy->foo()); +``` + +See the [complete documentation about remote objects](https://github.com/Ocramius/ProxyManager/tree/master/docs/remote-object.md) +in the `docs/` directory. + +## Contributing + +Please read the [CONTRIBUTING.md](https://github.com/Ocramius/ProxyManager/blob/master/CONTRIBUTING.md) contents if you +wish to help out! + +## Credits + +The idea was originated by a [talk about Proxies in PHP OOP](http://marco-pivetta.com/proxy-pattern-in-php/) that I gave +at the [@phpugffm](https://twitter.com/phpugffm) in January 2013. + diff --git a/core/vendor/ocramius/proxy-manager/UPGRADE.md b/core/vendor/ocramius/proxy-manager/UPGRADE.md new file mode 100644 index 0000000..d0de61d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/UPGRADE.md @@ -0,0 +1,69 @@ +This is a list of backwards compatibility (BC) breaks introduced in ProxyManager: + +# 0.5.0 + + * The Generated Hydrator has been removed - it is now available as a separate project + at [Ocramius/GeneratedHydrator](https://github.com/Ocramius/GeneratedHydrator) [#65](https://github.com/Ocramius/ProxyManager/pull/65) + * When having a `public function __get($name)` defined (by-val) and public properties, it won't be possible to get public + properties by-ref while initializing the object. Either drop `__get()` or implement + a by-ref `& __get()` [#126](https://github.com/Ocramius/ProxyManager/pull/126) + * Proxies are now being always auto-generated if they could not be autoloaded by a factory. The methods + [`ProxyManager\Configuration#setAutoGenerateProxies()`](https://github.com/Ocramius/ProxyManager/blob/0.5.0-BETA2/src/ProxyManager/Configuration.php#L67) + and [`ProxyManager\Configuration#doesAutoGenerateProxies()`](https://github.com/Ocramius/ProxyManager/blob/0.5.0-BETA2/src/ProxyManager/Configuration.php#L75) + are now no-op and deprecated, and will be removed in the next minor + version [#87](https://github.com/Ocramius/ProxyManager/pull/87) [#90](https://github.com/Ocramius/ProxyManager/pull/90) + * Proxy public properties defaults are now set before initialization [#116](https://github.com/Ocramius/ProxyManager/pull/116) [#122](https://github.com/Ocramius/ProxyManager/pull/122) + +# 0.4.0 + + * An optional parameter `$options` was introduced + in [`ProxyManager\Inflector\ClassNameInflectorInterface#getProxyClassName($className, array $options = array())`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Inflector/ClassNameInflectorInterface.php) + parametrize the generated class name as of [#10](https://github.com/Ocramius/ProxyManager/pull/10) + and [#59](https://github.com/Ocramius/ProxyManager/pull/59) + * Generated hydrators no longer have constructor arguments. Any required reflection instantiation is now dealt with + in the hydrator internally as of [#63](https://github.com/Ocramius/ProxyManager/pull/63) + +# 0.3.4 + + * Interface names are also supported for proxy generation as of [#40](https://github.com/Ocramius/ProxyManager/pull/40) + +# 0.3.3 + + * [Generated hydrators](https://github.com/Ocramius/ProxyManager/tree/master/docs/generated-hydrator.md) were introduced + +# 0.3.2 + + * An additional (optional) [by-ref parameter was added](https://github.com/Ocramius/ProxyManager/pull/31) + to the lazy loading proxies' initializer to allow unsetting the initializer with less overhead. + +# 0.3.0 + + * Dependency to [jms/cg](https://github.com/schmittjoh/cg-library) removed + * Moved code generation logic to [`Zend\Code`](https://github.com/zendframework/zf2) + * Added method [`ProxyManager\Inflector\ClassNameInflectorInterface#isProxyClassName($className)`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Inflector/ClassNameInflectorInterface.php) + * The constructor of [`ProxyManager\Autoloader\Autoloader`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Autoloader/Autoloader.php) + changed from `__construct(\ProxyManager\FileLocator\FileLocatorInterface $fileLocator)` to + `__construct(\ProxyManager\FileLocator\FileLocatorInterface $fileLocator, \ProxyManager\Inflector\ClassNameInflectorInterface $classNameInflector)` + * Classes implementing `CG\Core\GeneratorStrategyInterface` now implement + [`ProxyManager\GeneratorStrategy\GeneratorStrategyInterface`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/GeneratorStrategy/GeneratorStrategyInterface.php) + instead + * All code generation logic has been replaced - If you wrote any logic based on `ProxyManager\ProxyGenerator`, you will + have to rewrite it + +# 0.2.0 + + * The signature of initializers to be used with proxies implementing + [`ProxyManager\Proxy\LazyLoadingInterface`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/LazyLoadingInterface.php) + changed from: + + ```php + $initializer = function ($proxy, & $wrappedObject, $method, $parameters) {}; + ``` + + to + + ```php + $initializer = function (& $wrappedObject, $proxy, $method, $parameters) {}; + ``` + + Only the order of parameters passed to the closures has been changed. diff --git a/core/vendor/ocramius/proxy-manager/build/.gitignore b/core/vendor/ocramius/proxy-manager/build/.gitignore new file mode 100644 index 0000000..6d8e8bf --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/build/.gitignore @@ -0,0 +1,4 @@ +* +!logs +!.gitignore +!coverage-checker.php \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/composer.json b/core/vendor/ocramius/proxy-manager/composer.json new file mode 100644 index 0000000..3b58c27 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/composer.json @@ -0,0 +1,49 @@ +{ + "name": "ocramius/proxy-manager", + "description": "A library providing utilities to generate, instantiate and generally operate with Object Proxies", + "type": "library", + "license": "MIT", + "homepage": "https://github.com/Ocramius/ProxyManager", + "minimum-stability": "dev", + "keywords": [ + "proxy", + "proxy pattern", + "service proxies", + "lazy loading", + "aop" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "require": { + "php": ">=5.3.3", + "zendframework/zend-code": "2.*" + }, + "require-dev": { + "phpunit/phpunit": ">=3.7", + "phpmd/phpmd": "1.4.*", + "squizlabs/php_codesniffer": "1.4.*", + "satooshi/php-coveralls": "~0.6" + }, + "suggest": { + "zendframework/zend-stdlib": "To use the hydrator proxy", + "ocramius/generated-hydrator": "To have very fast object to array to object conversion for ghost objects", + "zendframework/zend-xmlrpc": "To have the XmlRpc adapter (Remote Object feature)", + "zendframework/zend-json": "To have the JsonRpc adapter (Remote Object feature)", + "zendframework/zend-soap": "To have the Soap adapter (Remote Object feature)" + }, + "autoload": { + "psr-0": { + "ProxyManager\\": "src" + } + }, + "extra": { + "branch-alias": { + "dev-master": "0.5.x-dev" + } + } +} diff --git a/core/vendor/ocramius/proxy-manager/docs/access-interceptor-scope-localizer.md b/core/vendor/ocramius/proxy-manager/docs/access-interceptor-scope-localizer.md new file mode 100644 index 0000000..040ed8e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/docs/access-interceptor-scope-localizer.md @@ -0,0 +1,105 @@ +# Access Interceptor Scope Localizer Proxy + +An access interceptor scope localizer is a smart reference proxy that allows you to dynamically +define logic to be executed before or after any of the proxied object's methods' logic. + +It works exactly like the [access interceptor value holder](access-interceptor-value-holder.md), +with some minor differences in behavior. + +The working concept of an access interceptor scope localizer is to localize scope of a proxied object: + +```php +class Example +{ + protected $foo; + protected $bar; + protected $baz; + + public function doFoo() + { + // ... + } +} + +class ExampleProxy extends Example +{ + public function __construct(Example $example) + { + $this->foo = & $example->foo; + $this->bar = & $example->bar; + $this->baz = & $example->baz; + } + + public function doFoo() + { + return parent::doFoo(); + } +} +``` + +This allows to create a mirror copy of the real instance, where any change in the proxy or in the real +instance is reflected in both objects. + +The main advantage of this approach is that the proxy is now safe against fluent interfaces, which +would break an [access interceptor value holder](access-interceptor-value-holder.md) instead. + +## Differences with [access interceptor value holder](access-interceptor-value-holder.md): + + * It does **NOT** implement the `ProxyManager\Proxy\ValueHolderInterface`, since the proxy itself + does not keep a reference to the original object being proxied + * In all interceptor methods (see [access interceptor value holder](access-interceptor-value-holder.md)), + the `$instance` passed in is the proxy itself. There is no way to gather a reference to the + original object right now, and that's mainly to protect from misuse. + +## Known limitations + + * It is **NOT** possible to intercept access to public properties + * It is **NOT** possible to proxy interfaces, since this proxy relies on `parent::method()` calls. + Interfaces obviously don't provide a parent method implementation. + * calling `unset` on a property of an access interceptor scope localizer (or the real instance) + will cause the two objects to be un-synchronized, with possible unexpected behaviour. + * serializing or un-serializing an access interceptor scope localizer (or the real instance) + will not cause the real instance (or the proxy) to be serialized or un-serialized + * if a proxied object contains private properties, then an exception will be thrown if you use + PHP `< 5.4.0`. + +## Example + +Here's an example of how you can create and use an access interceptor value holder: + +```php +createProxy( + new Foo(), + array('doFoo' => function () { echo "PreFoo!\n"; }), + array('doFoo' => function () { echo "PostFoo!\n"; }) +); + +$proxy->doFoo(); +``` + +This send something like following to your output: + +``` +PreFoo! +Foo! +PostFoo! +``` + +This is pretty much the same logic that you can find +in [access interceptor value holder](access-interceptor-value-holder.md). diff --git a/core/vendor/ocramius/proxy-manager/docs/access-interceptor-value-holder.md b/core/vendor/ocramius/proxy-manager/docs/access-interceptor-value-holder.md new file mode 100644 index 0000000..e47e941 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/docs/access-interceptor-value-holder.md @@ -0,0 +1,108 @@ +# Access Interceptor Value Holder Proxy + +An access interceptor value holder is a smart reference proxy that allows you to dynamically +define logic to be executed before or after any of the wrapped object's methods +logic. + +It wraps around a real instance of the object to be proxied, and can be useful for things like: + + * caching execution of slow and heavy methods + * log method calls + * debugging + * event triggering + * handling of orthogonal logic, and [AOP](http://en.wikipedia.org/wiki/Aspect-oriented_programming) in general + +## Example + +Here's an example of how you can create and use an access interceptor value holder: + +```php +createProxy( + new Foo(), + array('doFoo' => function () { echo "PreFoo!\n"; }), + array('doFoo' => function () { echo "PostFoo!\n"; }) +); + +$proxy->doFoo(); +``` + +This send something like following to your output: + +``` +PreFoo! +Foo! +PostFoo! +``` + +## Implementing pre- and post- access interceptors + +A proxy produced by the +[`ProxyManager\Factory\AccessInterceptorValueHolderFactory`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php) +implements both the +[`ProxyManager\Proxy\ValueHolderInterface`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/ValueHolderInterface.php) +and the +[`ProxyManager\Proxy\AccessInterceptorInterface`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/ValueHolderInterface.php). + +Therefore, you can set an access interceptor callback by calling: + +```php +$proxy->setMethodPrefixInterceptor('methodName', function () { echo 'pre'; }); +$proxy->setMethodSuffixInterceptor('methodName', function () { echo 'post'; }); +``` + +You can also listen to public properties access by attaching interceptors to `__get`, `__set`, `__isset` and `__unset`. + +A prefix interceptor (executed before method logic) should have following signature: + +```php +/** + * @var object $proxy the proxy that intercepted the method call + * @var object $instance the wrapped instance within the proxy + * @var string $method name of the called method + * @var array $params sorted array of parameters passed to the intercepted + * method, indexed by parameter name + * @var bool $returnEarly flag to tell the interceptor proxy to return early, returning + * the interceptor's return value instead of executing the method logic + * + * @return mixed + */ +$prefixInterceptor = function ($proxy, $instance, $method, $params, & $returnEarly) {}; +``` + +A suffix interceptor (executed after method logic) should have following signature: + +```php +/** + * @var object $proxy the proxy that intercepted the method call + * @var object $instance the wrapped instance within the proxy + * @var string $method name of the called method + * @var array $params sorted array of parameters passed to the intercepted + * method, indexed by parameter name + * @var mixed $returnValue the return value of the intercepted method + * @var bool $returnEarly flag to tell the proxy to return early, returning the interceptor's + * return value instead of the value produced by the method + * + * @return mixed + */ +$suffixInterceptor = function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) {}; +``` + +## Tuning performance for production + +See [Tuning ProxyManager for Production](https://github.com/Ocramius/ProxyManager/blob/master/docs/tuning-for-production.md). \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/docs/generator-strategies.md b/core/vendor/ocramius/proxy-manager/docs/generator-strategies.md new file mode 100644 index 0000000..e4022d5 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/docs/generator-strategies.md @@ -0,0 +1,16 @@ +# Generator strategies + +ProxyManager allows you to generate classes based on generator strategies and a +given `Zend\Code\Generator\ClassGenerator` as of +the [interface of a generator strategy](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/GeneratorStrategy/GeneratorStrategyInterface.php). + +Currently, 3 generator strategies are shipped with ProxyManager: + + * [`ProxyManager\GeneratorStrategy\BaseGeneratorStrategy`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/GeneratorStrategy/BaseGeneratorStrategy.php), + which simply retrieves the string representation of the class from `ClassGenerator` + * [`ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/GeneratorStrategy/EvaluatingGeneratorStrategy.php), + which calls `eval()` upon the generated class code before returning it. This is useful in cases + where you want to generate multiple classes at runtime + * [`ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/GeneratorStrategy/FileWriterGeneratorStrategy.php), + which accepts a [`ProxyManager\FileLocator\FileLocatorInterface`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/FileLocator/FileLocatorInterface.php) + instance as constructor parameter, and based on it, writes the generated class to a file before returning its code. \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/docs/lazy-loading-ghost-object.md b/core/vendor/ocramius/proxy-manager/docs/lazy-loading-ghost-object.md new file mode 100644 index 0000000..4c93439 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/docs/lazy-loading-ghost-object.md @@ -0,0 +1,206 @@ +# Lazy Loading Ghost Object Proxies + +A lazy loading ghost object proxy is a ghost proxy that looks exactly like the real instance of the proxied subject, +but which has all properties nulled before initialization. + +## Lazy loading with the Ghost Object + +In pseudo-code, in userland, [lazy loading](http://www.martinfowler.com/eaaCatalog/lazyLoad.html) in a ghost object +looks like following: + +```php +class MyObjectProxy +{ + private $initialized = false; + private $name; + private $surname; + + public function doFoo() + { + $this->init(); + + // Perform doFoo routine using loaded variables + } + + private function init() + { + if (! $this->initialized) { + $data = some_logic_that_loads_data(); + + $this->name = $data['name']; + $this->surname = $data['surname']; + + $this->initialized = true; + } + } +} +``` + +Ghost objects work similarly to virtual proxies, but since they don't wrap around a "real" instance of the proxied +subject, they are better suited for representing dataset rows. + +## When do I use a ghost object? + +You usually need a ghost object in cases where following applies + + * you are building a small data-mapper and want to lazily load data across associations in your object graph + * you want to initialize objects representing rows in a large dataset + * you want to compare instances of lazily initialized objects without the risk of comparing a proxy with a real subject + * you are aware of the internal state of the object and are confident in working with its internals via reflection + or direct property access + +## Usage examples + +[ProxyManager](https://github.com/Ocramius/ProxyManager) provides a factory that creates lazy loading ghost objects. +To use it, follow these steps: + +First of all, define your object's logic without taking care of lazy loading: + +```php +namespace MyApp; + +class Customer +{ + private $name; + private $surname; + + // just write your business logic or generally logic + // don't worry about how complex this object will be! + // don't code lazy-loading oriented optimizations in here! + public function getName() { return $this->name; } + public function setName($name) { $this->name = (string) $name; } + public function getSurname() { return $this->surname; } + public function setSurname($surname) { $this->surname = (string) $surname; } +} +``` + +Then use the proxy manager to create a ghost object of it. +You will be responsible of setting its state during lazy loading: + +```php +namespace MyApp; + +use ProxyManager\Factory\LazyLoadingGhostFactory; +use ProxyManager\Proxy\LazyLoadingInterface; + +require_once __DIR__ . '/vendor/autoload.php'; + +$factory = new LazyLoadingGhostFactory(); +$initializer = function (LazyLoadingInterface $proxy, $method, array $parameters, & $initializer) { + $initializer = null; // disable initialization + + // load data and modify the object here + $proxy->setName('Agent'); + $proxy->setSurname('Smith'); + + return true; // confirm that initialization occurred correctly +}; + +$instance = $factory->createProxy('MyApp\Customer', $initializer); +``` + +You can now simply use your object as before: + +```php +// this will just work as before +echo $proxy->getName() . ' ' . $proxy->getSurname(); // Agent Smith +``` + +## Lazy Initialization + +As you can see, we use a closure to handle lazy initialization of the proxy instance at runtime. +The initializer closure signature for ghost objects should be as following: + +```php +/** + * @var object $proxy the instance the ghost object proxy that is being initialized + * @var string $method the name of the method that triggered lazy initialization + * @var array $parameters an ordered list of parameters passed to the method that + * triggered initialization, indexed by parameter name + * @var Closure $initializer a reference to the property that is the initializer for the + * proxy. Set it to null to disable further initialization + * + * @return bool true on success + */ +$initializer = function ($proxy, $method, $parameters, & $initializer) {}; +``` + +The initializer closure should usually be coded like following: + +```php +$initializer = function ($proxy, $method, $parameters, & $initializer) { + $initializer = null; // disable initializer for this proxy instance + + // modify the object with loaded data + $proxy->setFoo(/* ... */); + $proxy->setBar(/* ... */); + + return true; // report success +}; +``` + +The +[`ProxyManager\Factory\LazyLoadingGhostFactory`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Factory/LazyLoadingGhostFactory.php) +produces proxies that implement both the +[`ProxyManager\Proxy\GhostObjectInterface`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/GhostObjectInterface.php) +and the +[`ProxyManager\Proxy\LazyLoadingInterface`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/LazyLoadingInterface.php). + +At any point in time, you can set a new initializer for the proxy: + +```php +$proxy->setProxyInitializer($initializer); +``` + +In your initializer, you **MUST** turn off any further initialization: + +```php +$proxy->setProxyInitializer(null); +``` + +or + +```php +$initializer = null; // if you use the initializer passed by reference to the closure +``` + +## Triggering Initialization + +A lazy loading ghost object is initialized whenever you access any property or method of it. +Any of the following interactions would trigger lazy initialization: + +```php +// calling a method +$proxy->someMethod(); + +// reading a property +echo $proxy->someProperty; + +// writing a property +$proxy->someProperty = 'foo'; + +// checking for existence of a property +isset($proxy->someProperty); + +// removing a property +unset($proxy->someProperty); + +// cloning the entire proxy +clone $proxy; + +// serializing the proxy +$unserialized = serialize(unserialize($proxy)); +``` + +Remember to call `$proxy->setProxyInitializer(null);` to disable initialization of your proxy, or it will happen more +than once. + +## Proxying interfaces + +You can also generate proxies from an interface FQCN. By proxying an interface, you will only be able to access the +methods defined by the interface itself, even if the `wrappedObject` implements more methods. This will anyway save +some memory since the proxy won't contain any properties. + +## Tuning performance for production + +See [Tuning ProxyManager for Production](https://github.com/Ocramius/ProxyManager/blob/master/docs/tuning-for-production.md). diff --git a/core/vendor/ocramius/proxy-manager/docs/lazy-loading-value-holder.md b/core/vendor/ocramius/proxy-manager/docs/lazy-loading-value-holder.md new file mode 100644 index 0000000..4de56ce --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/docs/lazy-loading-value-holder.md @@ -0,0 +1,200 @@ +# Lazy Loading Value Holder Proxy + +A lazy loading value holder proxy is a virtual proxy that wraps and lazily initializes a "real" instance of the proxied +class. + +## What is lazy loading? + +In pseudo-code, in userland, [lazy loading](http://www.martinfowler.com/eaaCatalog/lazyLoad.html) looks like following: + +```php +class MyObjectProxy +{ + private $wrapped; + + public function doFoo() + { + $this->init(); + + return $this->wrapped->doFoo(); + } + + private function init() + { + if (null === $this->wrapped) { + $this->wrapped = new MyObject(); + } + } +} +``` + +This code is problematic, and adds a lot of complexity that makes your unit tests' code even worse. + +Also, this kind of usage often ends up in coupling your code with a particular +[Dependency Injection Container](http://martinfowler.com/articles/injection.html) +or a framework that fetches dependencies for you. +That way, further complexity is introduced, and some problems related +with service location raise, as I've explained +[in this article](http://ocramius.github.com/blog/zf2-and-symfony-service-proxies-with-doctrine-proxies/). + +Lazy loading value holders abstract this logic for you, hiding your complex, slow, performance-impacting objects behind +tiny wrappers that have their same API, and that get initialized at first usage. + +## When do I use a lazy value holder? + +You usually need a lazy value holder in cases where following applies + + * your object takes a lot of time and memory to be initialized (with all dependencies) + * your object is not always used, and the instantiation overhead can be avoided + +## Usage examples + +[ProxyManager](https://github.com/Ocramius/ProxyManager) provides a factory that eases instantiation of lazy loading +value holders. To use it, follow these steps: + +First of all, define your object's logic without taking care of lazy loading: + +```php +namespace MyApp; + +class HeavyComplexObject +{ + public function doFoo() + { + // ... do foo + echo 'OK!'; + // just write your business logic + // don't worry about how heavy this object will be! + } +} +``` + +Then use the proxy manager to create a lazy version of the object (as a proxy): + +```php +namespace MyApp; + +use ProxyManager\Factory\LazyLoadingValueHolderFactory; +use ProxyManager\Proxy\LazyLoadingInterface; + +require_once __DIR__ . '/vendor/autoload.php'; + +$factory = new LazyLoadingValueHolderFactory(); +$initializer = function (& $wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, & $initializer) { + $initializer = null; // disable initialization + $wrappedObject = new HeavyComplexObject(); // fill your object with values here + + return true; // confirm that initialization occurred correctly +}; + +$instance = $factory->createProxy('MyApp\HeavyComplexObject', $initializer); +``` + +You can now simply use your object as before: + +```php +// this will just work as before +$proxy->doFoo(); // OK! +``` + +## Lazy Initialization + +As you can see, we use a closure to handle lazy initialization of the proxy instance at runtime. +The initializer closure signature should be as following: + +```php +/** + * @var object $wrappedObject the instance (passed by reference) of the wrapped object, + * set it to your real object + * @var object $proxy the instance proxy that is being initialized + * @var string $method the name of the method that triggered lazy initialization + * @var string $parameters an ordered list of parameters passed to the method that + * triggered initialization, indexed by parameter name + * @var Closure $initializer a reference to the property that is the initializer for the + * proxy. Set it to null to disable further initialization + * + * @return bool true on success + */ +$initializer = function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) {}; +``` + +The initializer closure should usually be coded like following: + +```php +$initializer = function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) { + $newlyCreatedObject = new Foo(); // instantiation logic + $newlyCreatedObject->setBar('baz') // instantiation logic + $newlyCreatedObject->setBat('bam') // instantiation logic + + $wrappedObject = $newlyCreatedObject; // set wrapped object in the proxy + $initializer = null; // disable initializer + + return true; // report success +}; +``` + +The +[`ProxyManager\Factory\LazyLoadingValueHolderFactory`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Factory/LazyLoadingValueHolderFactory.php) +produces proxies that implement both the +[`ProxyManager\Proxy\ValueHolderInterface`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/ValueHolderInterface.php) +and the +[`ProxyManager\Proxy\LazyLoadingInterface`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/LazyLoadingInterface.php). + +At any point in time, you can set a new initializer for the proxy: + +```php +$proxy->setProxyInitializer($initializer); +``` + +In your initializer, you currently **MUST** turn off any further initialization: + +```php +$proxy->setProxyInitializer(null); +``` + +or + +```php +$initializer = null; // if you use the initializer by reference +``` + +## Triggering Initialization + +A lazy loading proxy is initialized whenever you access any property or method of it. +Any of the following interactions would trigger lazy initialization: + +```php +// calling a method +$proxy->someMethod(); + +// reading a property +echo $proxy->someProperty; + +// writing a property +$proxy->someProperty = 'foo'; + +// checking for existence of a property +isset($proxy->someProperty); + +// removing a property +unset($proxy->someProperty); + +// cloning the entire proxy +clone $proxy; + +// serializing the proxy +$unserialized = serialize(unserialize($proxy)); +``` + +Remember to call `$proxy->setProxyInitializer(null);` to disable initialization of your proxy, or it will happen more +than once. + +## Proxying interfaces + +You can also generate proxies from an interface FQCN. By proxying an interface, you will only be able to access the +methods defined by the interface itself, even if the `wrappedObject` implements more methods. This will anyway save +some memory since the proxy won't contain useless inherited properties. + +## Tuning performance for production + +See [Tuning ProxyManager for Production](https://github.com/Ocramius/ProxyManager/blob/master/docs/tuning-for-production.md). diff --git a/core/vendor/ocramius/proxy-manager/docs/null-object.md b/core/vendor/ocramius/proxy-manager/docs/null-object.md new file mode 100644 index 0000000..aca1739 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/docs/null-object.md @@ -0,0 +1,89 @@ +# Null Object Proxy + +A Null Object proxy is a [null object pattern](http://en.wikipedia.org/wiki/Null_Object_pattern) implementation. +The proxy factory creates a new object with defined neutral behavior based on an other object, class name or interface. + +## What is null object proxy ? + +In your application, when you can't return the object related to the request, the consumer of the model must check +for the return value and handle the failing condition gracefully, thus generating an explosion of conditionals throughout your code. +Fortunately, this seemingly-tangled situation can be sorted out simply by creating a polymorphic implementation of the +domain object, which would implement the same interface as the one of the object in question, only that its methods +wouldn’t do anything, therefore offloading client code from doing repetitive checks for ugly null values when the operation + is executed. + +## Usage examples + +```php +class UserMapper +{ + private $adapter; + + public function __construct(DatabaseAdapterInterface $adapter) { + $this->adapter = $adapter; + } + + public function fetchById($id) { + $this->adapter->select("users", array("id" => $id)); + if (!$row = $this->adapter->fetch()) { + return null; + } + return $this->createUser($row); + } + + private function createUser(array $row) { + $user = new Entity\User($row["name"], $row["email"]); + $user->setId($row["id"]); + return $user; + } +} +``` + +If you want to remove conditionals from client code, you need to have a version of the entity conforming to the corresponding +interface. With the Null Object Proxy, you can build this object : + +```php +$factory = new \ProxyManager\Factory\NullObjectFactory(); + +$nullUser = $factory->createProxy('Entity\User'); + +var_dump($nullUser->getName()); // empty return +``` + +You can now return a valid entity : + +```php +class UserMapper +{ + private $adapter; + + public function __construct(DatabaseAdapterInterface $adapter) { + $this->adapter = $adapter; + } + + public function fetchById($id) { + $this->adapter->select("users", array("id" => $id)); + return $this->createUser($this->adapter->fetch()); + } + + private function createUser($row) { + if (!$row) { + $factory = new \ProxyManager\Factory\NullObjectFactory(); + + return $factory->createProxy('Entity\User'); + } + $user = new Entity\User($row["name"], $row["email"]); + $user->setId($row["id"]); + return $user; + } +} +``` + +## Proxying interfaces + +You can also generate proxies from an interface FQCN. By proxying an interface, you will only be able to access the +methods defined by the interface itself, and like with the object, the methods are empty. + +## Tuning performance for production + +See [Tuning ProxyManager for Production](https://github.com/Ocramius/ProxyManager/blob/master/docs/tuning-for-production.md). diff --git a/core/vendor/ocramius/proxy-manager/docs/remote-object.md b/core/vendor/ocramius/proxy-manager/docs/remote-object.md new file mode 100644 index 0000000..1e040bd --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/docs/remote-object.md @@ -0,0 +1,100 @@ +# Remote Object Proxy + +The remote object implementation is a mechanism that enables an local object to control an other object on an other server. +Each call method on the local object will do a network call to get information or execute operations on the remote object. + +## What is remote object proxy ? + +A remote object is based on an interface. The remote interface defines the API that a consumer can call. This interface +must be implemented both by the client and the RPC server. + +## Adapters + +ZendFramework's RPC components (XmlRpc, JsonRpc & Soap) can be used easily with the remote object. +You will need to require the one you need via composer, though: + +```sh +$ php composer.phar require zendframework/zend-xmlrpc:2.* +$ php composer.phar require zendframework/zend-json:2.* +$ php composer.phar require zendframework/zend-soap:2.* +``` + +ProxyManager comes with 3 adapters: + + * `ProxyManager\Factory\RemoteObject\Adapter\XmlRpc` + * `ProxyManager\Factory\RemoteObject\Adapter\JsonRpc` + * `ProxyManager\Factory\RemoteObject\Adapter\Soap` + +## Usage examples + +RPC server side code (`xmlrpc.php` in your local webroot): + +```php +interface FooServiceInterface +{ + public function foo(); +} + +class Foo implements FooServiceInterface +{ + /** + * Foo function + * @return string + */ + public function foo() + { + return 'bar remote'; + } +} + +$server = new Zend\XmlRpc\Server(); +$server->setClass('Foo', 'FooServiceInterface'); // my FooServiceInterface implementation +$server->handle(); +``` + +Client side code (proxy) : + +```php + +interface FooServiceInterface +{ + public function foo(); +} + +$factory = new \ProxyManager\Factory\RemoteObjectFactory( + new \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc( + new \Zend\XmlRpc\Client('https://localhost/xmlrpc.php') + ) +); + +$proxy = $factory->createProxy('FooServiceInterface'); + +var_dump($proxy->foo()); // "bar remote" +``` + +## Implementing custom adapters + +Your adapters must implement `ProxyManager\Factory\RemoteObject\AdapterInterface` : + +```php +interface AdapterInterface +{ + /** + * Call remote object + * + * @param string $wrappedClass + * @param string $method + * @param array $params + * + * @return mixed + */ + public function call($wrappedClass, $method, array $params = array()); +} +``` + +It is very easy to create your own implementation (for RESTful web services, for example). Simply pass +your own adapter instance to your factory at construction time + +## Tuning performance for production + +See [Tuning ProxyManager for Production](https://github.com/Ocramius/ProxyManager/blob/master/docs/tuning-for-production.md). diff --git a/core/vendor/ocramius/proxy-manager/docs/tuning-for-production.md b/core/vendor/ocramius/proxy-manager/docs/tuning-for-production.md new file mode 100644 index 0000000..48ccf9f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/docs/tuning-for-production.md @@ -0,0 +1,24 @@ +## Tuning the ProxyManager for production + +By default, all proxy factories generate the required proxy classes at runtime. + +Proxy generation causes I/O operations and uses a lot of reflection, so be sure to have +generated all of your proxies **before deploying your code on a live system**, or you +may experience poor performance. + +You can configure ProxyManager so that it will try autoloading the proxies first. +Generating them "bulk" is not yet implemented: + +```php +$config = new \ProxyManager\Configuration(); +$config->setProxiesTargetDir(__DIR__ . '/my/generated/classes/cache/dir'); + +// then register the autoloader +spl_autoload_register($config->getProxyAutoloader()); +``` + +Generating a classmap with all your proxy classes in it will also work perfectly. + +Please note that all the currently implemented `ProxyManager\Factory\*` classes accept +a `ProxyManager\Configuration` object as optional constructor parameter. This allows for +fine-tuning of ProxyManager according to your needs. diff --git a/core/vendor/ocramius/proxy-manager/examples/access-interceptor-scope-localizer.php b/core/vendor/ocramius/proxy-manager/examples/access-interceptor-scope-localizer.php new file mode 100644 index 0000000..eb1da5b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/examples/access-interceptor-scope-localizer.php @@ -0,0 +1,38 @@ +counter += 1; + + return $this; + } +} + +$factory = new AccessInterceptorScopeLocalizerFactory(); +$foo = new FluentCounter(); + +/* @var $proxy FluentCounter */ +$proxy = $factory->createProxy( + $foo, + array('fluentMethod' => function ($proxy) { echo "pre-fluentMethod #{$proxy->counter}!\n"; }), + array('fluentMethod' => function ($proxy) { echo "post-fluentMethod #{$proxy->counter}!\n"; }) +); + +$proxy->fluentMethod()->fluentMethod()->fluentMethod()->fluentMethod(); + +echo 'The proxy counter is now at ' . $proxy->counter . "\n"; +echo 'The real instance counter is now at ' . $foo->counter . "\n"; diff --git a/core/vendor/ocramius/proxy-manager/examples/ghost-object.php b/core/vendor/ocramius/proxy-manager/examples/ghost-object.php new file mode 100644 index 0000000..b4ec216 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/examples/ghost-object.php @@ -0,0 +1,46 @@ +foo = (string) $foo; + } + + public function getFoo() + { + return $this->foo; + } +} + +$startTime = microtime(true); +$factory = new LazyLoadingGhostFactory(); + +for ($i = 0; $i < 1000; $i += 1) { + $proxy = $factory->createProxy( + 'Foo', + function ($proxy, $method, $parameters, & $initializer) { + $initializer = null; + $proxy->setFoo('Hello World!'); + + return true; + } + ); +} + +var_dump('time after 1000 instantiations: ' . (microtime(true) - $startTime)); + +echo $proxy->getFoo() . "\n"; + +var_dump('time after single call to doFoo: ' . (microtime(true) - $startTime)); diff --git a/core/vendor/ocramius/proxy-manager/examples/remote-proxy.php b/core/vendor/ocramius/proxy-manager/examples/remote-proxy.php new file mode 100644 index 0000000..97025fc --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/examples/remote-proxy.php @@ -0,0 +1,36 @@ +createProxy('Foo'); + +try { + var_dump($proxy->bar()); // bar remote ! +} catch (\Zend\Http\Client\Adapter\Exception\RuntimeException $error) { + echo "To run this example, please following before:\n\n\$ php -S localhost:9876 -t \"" . __DIR__ . "\"\n"; + + exit(2); +} diff --git a/core/vendor/ocramius/proxy-manager/examples/remote-proxy/remote-proxy-server.php b/core/vendor/ocramius/proxy-manager/examples/remote-proxy/remote-proxy-server.php new file mode 100644 index 0000000..81a742f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/examples/remote-proxy/remote-proxy-server.php @@ -0,0 +1,20 @@ +setClass(new Foo(), 'Foo'); +$server->setReturnResponse(false); + +$server->handle(); diff --git a/core/vendor/ocramius/proxy-manager/examples/smart-reference.php b/core/vendor/ocramius/proxy-manager/examples/smart-reference.php new file mode 100644 index 0000000..8c00a3a --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/examples/smart-reference.php @@ -0,0 +1,23 @@ +createProxy( + new Foo(), + array('doFoo' => function () { echo "pre-foo!\n"; }), + array('doFoo' => function () { echo "post-foo!\n"; }) +); + +$proxy->doFoo(); diff --git a/core/vendor/ocramius/proxy-manager/examples/virtual-proxy.php b/core/vendor/ocramius/proxy-manager/examples/virtual-proxy.php new file mode 100644 index 0000000..7ee6b2e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/examples/virtual-proxy.php @@ -0,0 +1,39 @@ +createProxy( + 'Foo', + function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) { + $initializer = null; + $wrappedObject = new Foo(); + + return true; + } + ); +} + +var_dump('time after 1000 instantiations: ' . (microtime(true) - $startTime)); + +$proxy->doFoo(); + +var_dump('time after single call to doFoo: ' . (microtime(true) - $startTime)); diff --git a/core/vendor/ocramius/proxy-manager/phpdox.xml.dist b/core/vendor/ocramius/proxy-manager/phpdox.xml.dist new file mode 100644 index 0000000..c610db9 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/phpdox.xml.dist @@ -0,0 +1,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/phpmd.xml.dist b/core/vendor/ocramius/proxy-manager/phpmd.xml.dist new file mode 100644 index 0000000..4a9f7df --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/phpmd.xml.dist @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/phpunit.xml.dist b/core/vendor/ocramius/proxy-manager/phpunit.xml.dist new file mode 100644 index 0000000..94f3665 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/phpunit.xml.dist @@ -0,0 +1,22 @@ + + + + ./tests/ProxyManagerTest + + + + ./src + + + diff --git a/core/vendor/ocramius/proxy-manager/proxy-manager.png b/core/vendor/ocramius/proxy-manager/proxy-manager.png new file mode 100644 index 0000000..0ab1c6e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/proxy-manager.png @@ -0,0 +1,73 @@ +‰PNG + + IHDRzòC4‘bKGDÿÿÿ ½§“ pHYs × ×B(›xtIMEÝ 0ž¾¬ IDATxÚíy`TÕÙÿ¿Ï½3ÉE­€Y](j…AxMfbj)ÖV[ß¾bÛ·µ.¯Õª’ÌÜ …äNHÀºñÖ.V»Hß_»¿VcV‘M¡¸aÜ+(d’̽Ïï }ÉÉÉÜ™¹9Ÿ¿Ú‘œsîY¾çœçœó<IJ¢iÚ•nà0ÀG¶0ó/²²²~©ëz—¬%‰Dr2¬‚Ô" +] š™ç矽ËÌ%ápøgXÖšD"‘BŸSUµÀ·O¶]ˆèÓ4———?/kP"‘H¡OQt]÷D" @€‘ƒH‚…Ð4m€RÓ† ¹6•mmme÷ߧ¬]‰D"…>‰ƒÁ‹‰¨À• Hþ %†al”5-‘H¤ÐÛL(ú3¯p+W‚³{†™óÃáðNYó‰zI‚Ñu]‰D"7X `œYw2ó:f^U^^~H¶„D"…^’‚ÁàÕDTà‚$ã3¯ÌÊÊz@×õ¨l‰D +½d(..žªªj5€kR¨X¯2ó’p8ügÙB‰zÉ Ñu}t$¹ÀÜ)ZÌ?˜¦™_QQÑ,[L"‘B/9I,X N:õ¿èƧA‘»<äñxîÑuý lA‰D +½ä8ƒA€uD4+ ‹ÿ>½¹¹ùÑ7š²5%)ô’£())kšæj"º€’æŸS§(J~iié6Ù²‰úa®ë§D"‘eá Oc¿VUµxõêÕoÊ––H¤ÐKB¡ÐW˜¹Àyþ̃Dt_ffæzéY"‘B?lÿ¦ªêº¸vï0óRéY"‘BïhJJJÆZ–Uà[H;ü`ÙDD‹ËÊÊ6É!‘H¡w .Ì9rdƒwì4,O(ŠR\ZZú¬‰D +}Zs¼öÙá™™ß ¢óñ‡û‰( @–Me= `t‡,‘¤ª¬‚ÿ£¤¤ä¢ìììŸQÀ6)ü‹Š¢|“™G‘wÀ35Ñ;–eÍ&¢O¸Ä†É;@^FFÆ×}>ßÞúúú—eÏ‘HäŠ>å),,<Óív¯†=îƒð3²²²×uÝ +ƒˆè»ƒHg·aç@(ºÂ²¬j"ºÔ®ºcæ¿«ªš_ZZúÙ“$’ÔÄ5œ?^×uWGGÇÝŠ¢,gæÓmʶ€áñx*u]?<” —••=§ëº·££ãÛDT`lÂW +DŸ·,k»¦i?êîî^ºfÍšÊa%‘È}J iÚT¸ÐÆl7š¦¹´¢¢bwåùo·‰¬èã&±Ób±hódÚÒ™ˆö[–u¯t‡,‘H¡O¶ÀO°öºþ€Ã0ž>N¹+ô¯†Ñ¯¯ûâââóTU]kó÷¾ûÞ¿È!&‘$Ÿacº9Ê}ð÷Ðs hÿ°Ôãñü(Y+ÜØîáZMÓæ¨0Æl/ðgMÓþ`±a-r¨I$Rè)ðJ$¹-‰è°Ï}° àÎÎΕUUUûS¡ ÃxúöÛoŸyúé§ß‚ž«£gÚí5ækšö°t‡,‘$G›n‚Á ˆªxm«P¢¿š¦YP^^þÊ@þ.Q¦›¾(((8=33s€»aßÛ÷è燺®[rèI$Rè…XºtéDÓ4+\oã7¶0s~8~j0l§Ð!LWUµŠ™¯²±y¶ÆÜ)4Èá'‘؃£L7Y™™™AÓ4‹aŸûàƒÌ¼<++ë¡tóôÛu|1 ^ÛùL±![/3×iš&Ý!K$6á'] ¿“™™ù:€6‰¼`ƒeYÓÃáðºtv營òx<Ó™9À!›v’ LÓ|YÓ4]×uŠIb\ZSRRr©eYÕ®°1Û˲òËËË· U‚Á`ð‡Dô_ƒøÓA›nú"œ­(Ê +ô˜‘ìZHwȉú>>îƒßPdƯ‡Z„þ5Ã0†üÑW ˜­(Ê:Ù66ës̼8¿$‡¦D2t¤>æ>8ß4MˆN³)Û€°Çã)×u½}8tŒØnŧiÚõ*œkC¶WÑ6MÓ¤;d‰dI+}0¼väÈ‘;6‰<ø™ªªç†¡‘?úû ÃØèñx¦X›ðìè“7š¦ùª¦iÁ… fÊa*‘ˆ‘¦›’’’‹,˪0ÏÆl_oFM“XJ™núbéÒ¥LÓ\ àFÛáu"*,++ûƒ®‰…þ(÷Á·pÛ”í>f.>â>ØÆÝJÊ ý4MËC;…ÏÚ˜íÓ±w +»ä°•H¾MN9,X ƒÁů¸Ý&‘ïDþ‚p8ü˜|½Ù?†aÔx<žYÌ|€}6e;ˆ¶kš¶N×õÓd+H$i¼¢ƒWQ€é6fû‡˜yàõ$~wÚ¬èæ(wÈ°ÉYÜwÈ---?ظq£)‡±D’&BŸ$÷Á»Ðc‡:¾ÿQôD¸J+¡?B(:Ÿ™×ø²Ù¾ÂÌápø¯r(K$ý“ôë•@`”¢(«`£û`fþ€~àÀ7lØÐæm˜Œb»¡klv‡<ˆþ¢iÚ\.×¢U«VµÊ!-‘¤ÐqŒ—gÛ”­ à®®®”qì4Ž¸C3fÌ]D´À©6d{M4¯iÚÖe-+//?$[B"ù?’bº ƒÙŠ¢¬cæÙ6fûœ¢(ù¥¥¥/¦bC˜n^5 cz*~S(:ƒ™—Ã^wÈïX)Ý!K$Iú`0x.UÂF÷ÁÌÜ +`ñ`ÝK¡’o›‰sN®m›h‹eY‹Ãáp£æ’áŽ-¦]×=±›vº>`uWW×úªªªÙÔÉÃ0Œí®ƒ×XGD“m˜àgQ½¦i¿fæ¢p8ü–l Ép%á÷èƒÁàw"‘H2Ü_hFXŠ|ꇟêêêš@ƒî‰HºC– kf> ƒŸ³È³ñ{Ñs]rsº5„“M7}s‡lø6ì3!¾ÍÌËÂáðcrèK¤Ð PTTt–Ë媄CÜÛE0üÝ2\„þ¨ î2ô¼Ÿ¸Ü®<™ùYÒ²d¸0d6z]×3"‘H3kluF+*++Û†i¦u ŽØî+' ÞHD€ñ _Ý}À6MÓžˆF£E•••û¤HœÌ¬¸C¡Ð5‘HÄN÷ÁÀQ±È;f² +‡ÃE£Ñó`³;dUU_Ó4-¨ëz†l‰S2݃Á1;¼îƒwÄîÃ?뤆0ݼbÆgœTÉr‡ÌÌKÂáð¥,H¤Ð÷ˆÒ©Dt/€;áp÷ÁRè“GIIÉçbñ€/±1[éYâ8d£_°`:eÊ”ïÑ=ΰ©Œ]ª„ÃáðÙdÇÒÒÒgu]ŸÙÑÑñm"ªp– Ùq‡ü3/‡ÃŸÈ– ›}0Ì™ifÚX¾?Ñ’dº–+úÔ@Ó´1‚°Ñ2€˜ù>éYâx¡_¶lÙäh4ºöº~Àâd¸n­ðÎeÂ.ã\»D¥ÃÊøT7«£Þ€V÷(µóm«èŸ4[ §"‡;þg†¾«ËÎö (Š²À—lÌv{ÌœS;Ü"//ÏÕÝÝý5"º +Àùè¹E¡=Áwv2óÏžO+¡¹^ +`€,›Êó 3¯H†ûà·×^~z—Õõ(×ɾ{òó"“õÝ©…Ûÿž„þ<ôÜ¿·s73¬Ü!ggg_¦(ÊΓ]ý¤ù_"º©®®îýTzŠÝi.ƒÍèÞ²²²ì®„·×^~z·ÕUàbÙO±¢!º~Já–ßÛñí·ßî¶Ù2tXoYÖj'»CÎÉÉñÑ_`Ÿo*ÇÀÌ{,Ëò555½›’B g¸?ö Ä.6Ñâ²²²¦dUBK¥÷)Økšrmªª\2±`sK22稪fæoÚhVh‰]ÇüÓ3//o\4} ö~;•çëëësÐã{+u„> Þ;lµËñÓûJ<ORq·VÌþÿBöKáuÌÓSŠ¶}!™%HFœf~ôÀw: RÙ¿ðù|OøOÙ§ŕ论ºº‡RFèƒÁàÑã6­†:‰¨Ê4ÍÒdo}÷V\2²Ü¯8GvË!=¢/O-Üò§d–A×u¥³³ó&f.0Î.±‡Ã·9¡ c&›ç \‡‚ý]]]ç¿ð %» TRR2Ö²¬×`ó7¦iWTT4§B+´®™µ‚™tÙ‡Œ7ÌŒO.:oÑÉ.ÈQ— òdÚ ö×8àU­âóù6˜%»ò­ê«ëêê +’Þ°Ìü}D~§¢(ó ÃøZªˆü[á™g3S‘ìŠCÊ4µëÔÛS¡ ååå‡ ÃÐLÓœÁÌ¿µa@—¤{ãùýþÿ”"?ä €»rss“~kIaæk˜þGîöx<³JKKÿžJ `ªJ%€SdWrVµ–_6.U +SQQчÿÀü#Y] +…>•®6oÞ¼S™¹Rvß!'ò¬“.ôHÌÙ€•Ñht¢aêºM¥šo)Ÿågà›²&„ѬðÊT+”aO†q 3ß`o"õ¦¥k£E"‘€±²û&fõûý_N¶Ðõ=Ù¿‘7Uݳ +­“}/¡µ|Û•³¼©X°p8üXggç "ºÀ.@˜yd:¶VÌ´P ûmB©¾úê«3“•ùPF€Úàó†a\UVVörªÖvë)³¿{ýõ G0RµpUUUûËÊʘ`ãpo,˲VÃ>ÿAÃséÃ<íСCw¤³ÐàÇã5 ã™T®ìfÃ{* íö@óZÖx¤r ÃxÃ0Œ|ÀÎáØJ~¿ÿ* dµ…UyyyI9¿ú(€õ.0 cCªÙáûÄÅ%¯ýl\Æ`Í{º7åŸÐ†ñŒÇã™àŽØÂeX——çbæµ²£Úƨh4zoR¤Odv2 ceºÔpkÕ¥“ؤE‚É<ÐÇë3ñlâ!¹f7¡s$§ú7Ç*‚ÁàËDT7T'Þ +A§pDô+fvºÏ~ðï΂´nÉÍͽ¿¶¶ÖÖ¤K ;ÒJ¼,UÔ½ÃÇwuZñG’n­ºtLuÈÎXXÁòfÃû‹©ÚÖ·ÒáûUUm·, NgÎœ9g@üå/uuußpz]ùýþ›™ù»C¥¹–e=À€íúÀÖÊYWñUÁdV9]ä€Mµ½ÜRs'ÚŸ FJ«å®=µp»Ý+ŒH¢[Q”%N¯§¹sçŽff#n‘»G0Ùœœœ[ÏE/ô[ñº™©J0™×öÂzÇOˆ³ów0G *Ë¢ +±/«¹Òë“òšäææ^LDw &ó`mmí+Ã`BŒ_ÀÌ|#€„†Q¥×kßù•ã…þôƒtÓ…V¹ŒÂÙwlívr=ñ“ T&®Žûù½ö¬Èê Õð¦H¿aëÃc™êX–U@HâŸV:½žbï –Ä ô“õõõõ–eåCÌô2ÁãñJ¡^«ôž b¡SnÿyjñÖ?:½Sïy»õ6Ÿí­Î(™q÷®Ã–4u“&¶¨Ç¬=§xo”2›\rrr¾‚žë¤"¬¨¯¯?0 &Ä0z¿/hSUµ›üRpUòù|çJ¡Ýv‹Û!AŽ·C¾S:猘[ߣÙ4©pëcGþÏäâ-¿H(f*áÝë玖r›®¾úêL"½N¹cüøñ8½®²³³ç£ç¦ÍQ;{^SSSóΑÿïr¹D^ÿgQ©zš×z/ÓBÂDôÀ䢭¯:½SwfZËœÞûÓ9Ÿ¨÷ÖT!äC,bÎXWwTƒ$)>|x€©Bc‚9ãƦ“ë)//Ï¥(Jü¹Þ›–eõ:”‰~…`}þ§ÏçKøù•c…^±P A;¤¢Do‡|£böEÔãªúèî÷øäÂmÇD³ŸT¸e;?ëØ(l.¿T›¶¿ß?ž™ïLæ7 Ï:½®¢Ñèí8ö}AISSÓ1WÊMÓ,‡èùUOû„j±#…¾µböW¸Rl5å“ ^üØéZ!« +½ßS„Ë]Üß¿·¬î"d2Åe@b+Ì|€QID8>~Cì}Á}q?×Õ××÷n´©©©ƒˆDw©³ü~ÿw¤Ð€Ýë§e2 ?ë~iÊ„)œÞ©›×̺ yq’ž’¿éƒþþfZñŽ}1»"ƒ¿ÖRî/åײ³³/p‹HDTU__ßâôºÊÈÈXŽÞfLKQ”Å8Î ›ººº_2³Øù³1wnâί'ô®®Ó˜"¶ÊEÝàl;äîõÓ2¦øë”»;wžÐé[ûáŽj¯ ulUÏêy.H ©ª*jxOUÕR§WTnnîÅâßü¤¶¶vû‰þVUÕ|"š16vg_ +ý‰ØSåÏàeB£ôÿ&nu¼Rí½ˆãææà }W׉þv†¾« DÅbõŒÏœ;êÐw!I(~¿ÿëÌ|¹àj³¤¦¦æ°Óë*ö¾àèÅÇ'–e”øÆ&ƒŸaI¢Â:JèÙäU´C+Ž·Cî©òŽÑ=qÊû·IÅÛ~s²iL)Üò{{ƪwJçœ!å81ÌŸ?$3W&óBCCÃcN¯+ŸÏw-âÞQiccãI»=±,Køü*vw_ +}´¬=‡A7 îr×N*~¡Õù+ÄÌEU¶aHQ¹€È‹áÓ;3Ì{ IíííÅÎ[ÌóqíÓN ù)þ:åëû÷ï¯H:ûˆ„ý:ý{ì¿úc{#=×)…ìYeNü-kgÏÇÌÑ#‹¶Øc夂m¯xXhjî~£böER–‡–ììì‰b㊟hhhxÞéuÕ×û" +ìÚub3f<û÷ï_Áó+EQªòò†öüÊBß²fö71;$ˆB3îÞåh;d?â?ÕîÎA¯ªÕî®èñ}2X\ +¡’¡]Á)Jzy!0m–e9þq[?ï þZWW÷»Á¤›DÍ¿Ÿ‰Ýå—B„½—Œ$p¹`2›&/Ùò3ǯæ+½ßŸïf"š)ÔžDšššˆÃ«ŠE9ÆŒID+†"ñØd!ºˆº+;;{HίÒZèd@ÌyØ­˜!§þÖªK'P'¬¿V¼í™¡ÊcZñ¶gø­`ƒ.ßSå/åzpÌ›7ïT¢ +ž«¯¯ßèôºÊÉɹ@vÜj~å»_Ö!z~Õ3 _¡o©œ™K Ñx•á K^r¼2ðèx¹—ª yЃXš"+ÁQ–‰{!‘H¤ÀYI˜±€Žfþüù#‰(þøγÏ>û¡¡Ì'6iè‚É|>vÇø =?¹@„gºV:<ªÒéºÏð€„ª‰›‡ÜoÉÄ‚Í-LX'˜Ì­ÍkgΖ²=0|>ßùDEúÑÆÆÆ^WíííEˆ;×S%!î—Çÿ0€‚ÉTÅîú/¡o}³õf3ÅR¡ÀdÝÙvÈgõ<ˆ÷ó{ížHÂü–tG=«¼/Ò'‹Ö1ƒ¤| 7U w4¤ò1-sz=ÅÞã~þmmmí3‰ÈoãƦè-S<(t~•vBßlxO±¨PÕL)Úòk§wêI§º½!0Qy^l8ÄÌK…vl ì=kgÝ åûäðûýW1óW“¹¯®®îC§×Uï "»56‰_Ñr¿ß?èó«´zrÑRÚ!AηC¾S:ç âŸc÷ +˜(¦´mû)€„Äž©ò=Ý;BÊøññz½nf®L济ŽŽû^W999~ñçzÕ6¹_?¿ê¹óï|¡o^3ç|€‹ ÿpJáö—œÞ©ûhYà»íx/@:,…­|ˆùH9§óçºeĈß0]pµX¸uëÖn‡W•‚žHNG›ßw¹\«íÈ<6™T ¶Ó­±ØÎzb«‚vH+“ïD«Ïð€ŒÇ§mÛjW&oo"Â/„&e@k©œ9QÊyßäååÉÌ¢á.ÿ\WW÷G§×U?ï –Úé~96©¼'2YÅ®[øü*m„¾uí¬/|­˜pнç-Úî|;dï˜ÞáÝ®€ÝåpQ4 M ‰,"Åñ/‹iš+ŒH¢Û4Í%N¯§~Þ¼P__ÿS;ËQSSs˜ˆ– +&“{à<¡ßòˆ×Í&‰†|íÀ¨cn 8Ž–ŠY×Ü˯63Œã…L–¼ô.B~ˆ˜ñÍ–òY~)ë½ÉÍͽ˜™ï4<ÐÔÔôªÓë*‰„Ðû\cï,»ËRWW÷ϯˆ¨rþüù#'ôgÄ 1;$-™}‡³í»×OË$¢øƒ¹Ý‘¶Èšd•É¥dTØ#Ò¯Y¥jÖÈ^`5_ @HâCUUW:½žbï +â„òçMI*’›d„ίboœ#ô¯UzÏd{]FŒ?M-Üò'§wj‘ð€‰[Õ7u±&Ø~³ZFκIÊ{~¿ÿ«Dt¥ØN‰—×ÔÔ|ìôºbærô>×k‹F£Ád–©±±±‰ˆ~.˜L0ö&ÀBïé´C²EŽ·CExÀD1¹pÛ¯Àüœàvµ¬Ùðž:ÜEþꫯÎdfQ3æKgŸ}öƒ ñ*"újœð§„ûåØd#t~¥('~•ÒBßR1뀿'$àL nyÍñ+—cãåv&<`¢ Vóˆ<1 7ï€îD:t(ÀÁUnA"žû§}½/H%÷ËMMMï‘hoÆÞ¤·ÐÇìÍ"vÈ½Ñ ·îôÁßg¼\âA…Lت>°ùE~$6Y  ¹üÒó†«ÈÇ^FŠ½:fþŸ†††g^Wçû¾ ˜Jî—£Ñh3ïZÇö¼ 8¡Ž§¬Ð·Vz¯c@ÈIDúy‹6tôJ¾¿ð€]ÝËS­¬–Õ½ À'Id@QË1La>f×6P"ªª;½žòòòÎ$¢øW¤Ï544<™JåljjêÀ±~wªq3}>ß Ï¯RRè[õ<B7EØ:éÐÇÛ!0QL+Þ±„U‚íz]k嬫†áj~€›'Šµµµµ­N¯«>Þ¤¬ûåØäóœ`2e±·é%ôÖ)ÂvH¶€|Òí¿'k'ý„Ü1áEÇ¡ÈzBg&hí–G¼îa¤ó³k(ï¹Ýî2§WT?ï RÚýrl:¿Š½H¡ßSåO‚vHÿ3µhk½Ó;u?á †"<`¢˜¡ïêbb!6|æôÃ|ûpQyŸÏ÷ æ¸]ÛÀ ÙùÜ?‰«ùø÷)ï~96 ýH0™‚ÜÜÜóÒFèÙ¤ÕNPv‹Ç_§ì3< á7C0QL-Üö0ýE¬£Ð}ï”Î9Ãéí{)z.±©¾¾þgN¯«~Þ¤…ûe˲–y×aYVyZ}Ïí{cqÕ´ÂÍo;½S³©V >< ¢¤·GÅe- òRyLW†¹ÂéíÜÞÞ^Œ¸hHí*‰÷ZšLúy_6î—÷bçW®óûýW¥´Ð÷s{d «ù·;–ñÅiQŒi  ù1ÕÕuÚbå~¿ÿ:f¾ÀFG£Ñ¨Ïç{ˆ~F+›ššöxǹw/Þ|óMtwwÇm¤cÆŒÁÔ©S‘™™9 4çÎ;6##c]4½±ë€Gê5¶‘P¼\" +¤ÒsÿD-@pìû‚½ÑhTOçjjjzÕçó=ˆžCôÁ¶ÿ]¹¹¹ÿ][[»3%L7lªaˆÙ!“=ÉnÞ¨˜}w3Á%(<à¼yóNõù|ÑÑÿ㵹̈f·Ã IDAT¼Åçó­8Ù¾”““3Êçó=ÂÌϸÀØžUðÏvoU¡ý=Oîr#:€çn¶óò+¯Èy†™àZ£ZÌÌ`檪Í>Ÿï¤ïßwvvbçÎxã7Žù#«üýû÷cûöíØ·oß@&¹oddd슙fúòå$½¦®®î×N}½/`f}Ó&G¸=>¿Š½)@Ò…¾uíeW¸A,'#z’ÝØ°³³ó±˜Ÿ7Ýçó°,W_}u&Õ¸lj{iZÀv»ðà–“ üQaygd—IŸ;Á?= À#>Ÿï„ò,Ë®]»ðÉ''vÍFñúë¯ã7Þ˜s¢›=Ÿ™Î̉zåøxÁ¤Ÿ÷/}öÙ?tÂ÷Õ×× "¡ó+"º2''ç+Iz~rÊ–%zcâŽÃ•NïÔv‡ôûýÿÁÌ=à\~ùå—_x¼pèС•.=Ù·¼§¢î­ã[™G·gàp×€ìÙ+ü~ÿ¬ãýƒ·ß~íí»Àµoß¾ÅsçÎ}ãùçŸ÷ù|cêëëô±²¸ƒˆ-ÐÞMh|[Å—ÏëûâÌÿ¶ :\ÁŦi^àïñÿaÿþý8rð<®Gÿ®g$tH=F/òù|9Yè£Ñèè}®×éÔ÷óù|O¡çÜi°,JŠÐïz`Æ)ÜAs“¹”,es"÷À– Õ`2?7¹xÛo—<_*p­Ï¥(Êt}ˆPî`Åóµ|ù¼¾'·*"ßêïKèÛÚD"¼aÊüùóGþíoë•HìµâgÛ5ø6·aø±®©©é §~œ¢(…–e]…Þ±oÂŒ¤˜nFveN€Xä¨a 3À–+ÑþlDâó²¬3ú¡Aûk9Сôó{OÐg™úºa3 ]H{û1u0bĈÓXÛüpåÃ؃)ÇR[[»›™š,’Qðd›CÒ"@QÍœDÁUe?è;Ýn•ûù]ø[û,“è#(Ó4©ƒqãÆ퇘ÏqIßœàlç}:ÛIŠé¦å“‘oMu¨,t_¸ @¢bGÈL¥gà¾=UÞ''l}?髪ºÍ²m®ê°«Ÿ  •ˆf&Ñ3Gô-ô§y.…µ½Pî3ÚÒ¨Q£ðÁƒ¾ÐôJ,D\/6nÜhú|¾—ÌJP×°¼=L&“sŽ2c¸EY àËNýØìììù³ÑG“"ôŸÓk¢-•³Ÿ|y>rSÆ…–;¨œÄ›•3?cByé¨Iy”eâ^ßMÐ6ñyŸÏ× `ê þüO ‡úY‘üÀ „þÒ±}O<*0ãSŒ—>œÐ+Šò§¾~?ýôÓ¡ª*LsPšù«ãü·Ÿ'P误¯ÿ/§«¼Ïç 0ŽZD|)''ç+ ¿wÚ·æåå¹¢Ñh•ànà™äÝ£­ˆlƹQîtü‹Ø‰EÛ_°!îç[›+/»,Q+C"ºcmsȲ¬‚~·Ž.×:^&Ÿ3ÚÂœO÷/¸_»°Êàtþµµµ¯ô9dd`âĉƒÙ ½cšf¿Îù:::Öx)ÝåfŸÏçuú˜8pà@€Ýqb¶öꫯÎtÚ·F£Ñ» xˆoYVeÒ„~jÑæÍ üTh²`ÒöTÌ™ìôŽíV2îðQ¯Å(ÌjæÄîÕÕÕýôOD‹ßìï¿×ÔÔü“™oÈ’¡ß¿¬.¥ÿ?™<ÆÂu øðô-ÇsçñþÁøñã1zôè|?&L˜PÚ—Ùæ[·ní&¢ï q&GÀ#HÑXÐCÅ®]»ºˆ(~‘75æ“ÞI«ùq FÂÌ¿khhøߤvr¹4"~)<™åp8–4í'ƽq;¢ì=kgݨ<;::Ì|?N|¿´ˆÕÕÕpÒnhhø_f.;±w+Àw.éÂÙ£N|^pÍùQÌÒç +ûE¹ñ駟þäDÂ=}útœqƉ=dddà /Ä9眳û$&ÑÌ|€D¹öú|¾o9}LÔÕÕýÀ_ãDm™ßïï Õü½èí~y tÑ${柒¿éD#Ó_‹¸ähö´zÀθMåÞŠKF&"¿­[·¶744,Råsý˜LTå⺺ºûOv¥ÞÐа”™³ã·ÞGsᙌyäN<9¹Kòçvît)Ê7Ï;åÇs~mmmíIí¤ÜnLŸ>çŸ><ϱËgEÁ¸qã0kÖ¬“šŽªƒ?»\®‹˜ù‡:ú˜dDo¥•åååâô1±£·s£˜ù>'|[ì%¹èyKõWâIwS9Y›uŠçVç z{B\ÍO.ðÒ {ãàszM´yÍÌbåé£~>§Cq¡ÇÓ]Bˆ‰â¥ÙÙÙSUU½™G8ÔÝݽ}Ó¦ÁùÚihhx~îܹ³322¾ÆÌWŽ=…çŽÉçŸêa\:ÖĬñæ€íîs~Mmí3—_~y½ªª×Ñå1Ça"ÚÃÌÿS___3˜òžuÖY8묳ÐÖÖÖËý)§œUÜÏššš|×ëõ.1bÄe>­#ñŽ7 ,Ä>F5˾ªÙï÷?çÄí–ìììG7§÷FbaU÷™ù_±+HÓ4dI‚eeeCb6i­ô^ÇÀokæ{“ ·<âôULKåìß|ôU«Àš>¥hû›éø=­å—cÅz]d‹ÊÀo§mý÷¡(OIIÉ,˲ëúù †a<=åðù|¸UdÛnšæEN~1«§1D´ûho DÔTWW—ƒ4 ˆž““sýJ0™[ëëëü¯Ýg*|Ø䢭ÇØÛ<Ø-¾¯µêÒÓœ.ô¦Å蹯~„,‚R–®ßê%j‡Œ¸T¥ÐiílYVÀ'Id*Šb8}<Äü*õÚÑ2óå~¿ÿëéø=^¯w‰zä}¡¾¾¾×™YʜΫ°âím\ÒãSUïqzÇ>/°µ õq+Úo´”Ïò§Û·4¯9,f‡$ zbÁ槵sccã>" +øNDÿáóùòœ>&Æ×ÇùWÄ|Ö§§À¡5¯eå#îEÊýÄ¢í/ƒXÌôBXØž}Ó;v—™y€÷{}¹BëXOŸkuÌ bEÔù^{VdµSÛyÿþýÕ^Læý¹cv +7n4EÉûùœ˜Ïú´ÁçóKDB^8‰èçMñ¿§”0¨]ÝË!>ËM +¯uºÐ_l8¦øÝËÌ–Q³oN—oh­œµŒ±NÍKgܽë°SÛy×®]]Ì,*V3º»»ïѲ¶¶ö"ŠÈÎΞ˜.ßÛÁ‰„Um‹F£}ºÈN)¡ŸÚyLB7H˜ð¥=•³¯vzǞܶåÇ÷ºY@Ìe͆÷ÔT/û{ºw†À9iɶŸ:½cÏúÿ"( «/¿üòÓ^W¦i.AÜùUºœSø|>3ÿ§Ø.™ÃMMM寮ÐÀ䉓Bœ½m Xàµ[ñºÜ©I‡e‘šÞ7 ΂‹KR½ì‘Q¶Cñb¢ô¼U1PE;¿NWe™Ó멱±±Àº¸Ÿ¿‘››››êM+÷ _º3ó·Û]q¼ RKÀnØhZÌù¢Ö1‡Èñ’§nndp¯kXÊo^3çüT-s³á= ±h@LOL.Üö<† µµµ¯0ó«ú…9993œ^W1ßôïÇ­ôEÏ‚ŠßïÿÄÝkjj"i#ô0­xÛ3 üN¨cƒõÖòËÆ9½c[¦»=.›AH]·ä‚°Ò­vkfÑ +ˆ_¹bpMÌ{겸º›™““sK*–wîܹ£™YÔ¼ô\CCÓ'Ú2¤$jÏvUä)øh‹LÝéû¼à¦w˜ãìÝŒ¯¶Vκ*ÕÊ»*d‡!à7|LD'uÈžÒBa°á3‹Î¾Ö5³ÿÃé{jÑ–_€P×[ùÞ×*½g&»l»×ÏÍL¢vÈš)…[7b˜S[[û ýBXóuîh\.WñçWD)±#Œ…õÏt_]]ÝIÅxNù—”SÚ¶ýÀ ‚†ƒòV=ÏãôŽ­€£÷Óç1nâIp]Qa;$ÈʇäE¶`t4]éôJª©©y@eÜŽæ+>Ÿï‹É,W^^žKQ”*Ád^ëèè¸ÿäµ!Å!–ÂVü}ñ2™G.tzÇžT¸e;Ò{Ž£;›×z/NV™šË/=íÌüÃ)…Û_‚P__ßBD¢BqÛp;hšæ1çWÖz½É;¿ŠF£·C0< 3/ÙºuëI¿­H ß(“Š·7¡'°²HÕ”4Þsß±9ïõPU,$ïZ¢–CÐie²ãÕ UUK¼'´|¤“455uQüuÜé#FŒø^2Ê3gÎœ3G!¢?544üi ¸•h½ímÔyŒ ¯rºL+Þ±ÐÛë!W¶VÌþªÝei)÷Î'à:¡étïy‹¶I¼Yâ0³ð+èŸÏw½Ó몮®î—Ì\·"^™——gûùUFFÆr"î(:£Ñè€cã¦ÐOXòÒ» „ÅR¡o7Wz}NïØí‡;ŽñzÈÄkw¯ŸfÛµºgõ<+2/°ë­Ã§ÜIŸ444<áó+¬ñz½#†Á(Þuï˜h4ªÛY†ììì‹Ü%´ða~p0ÁdÒ*Z¼›2*MV÷Šh‡T§“;ßÁ0CßÕEL¸Ÿ§¸ºN[lW&Ž:x‰Ú!á*øœ^•’~¼qÏñ÷ż†ÊÊÊZâôŠª­­ÝàÇq?/77׶ó+EQª!¾uï`'§´Ñy¿S:ç 0 Ù!ßê:þù¹ÕÁ`0[êùqWõÏ3ó‚É„|>Ÿãϯ,Ë*AÜùUÌNÂñù|×ø¼à¬®oÚ´é #…^×õS4M3¼ àšæαx¿{Œè:¨|÷ú¹£Þ±• ÐÛëá(6NÑ•i.0èF2YAcÛpÕkšöd0t¼ ˜@Ä/ÿˆ£I;•XÔ®^ßIDWúýþë™oì%²è-©­ ÿ=h-Háv¡`0øH$ò*€ Žr„ÕxøXbjǪ]fÐé{RÁ¶Wâ£v1èæ–µ³ç$*ÏæµÞ‹ÁbvÈ]‘ 8hþËlLÑËš¦éº®;þ=Ä@‰ù :¿"¢où|>ÇŸ_íß¿âϯ˜×äå%îÍÁƒ˜*²4%:æLú } ø·P(ô<ýÀ§ãÿûGæ(¼ÖyŽ`.\øÆÚYӜޱûˆÚ¥ÀBu¢ÜBEU°C¶[ØÚÞç˜ `E$y= ~GÊ{o\.W%€V‘¦Òî|‡‚~¢vMÌM–“Áï÷'¢å‚Éüº®®®AhwŸJP\\ˆž6Ø?ÀˆD";B¡ãkœÀ,±‹ˆ~(8YÆ|¥;š>¢v)è9§>¿ÊÉɹ@¶`;”455u¤¥ÐQ¡P¨Ì²¬-DôyÑôÞî:ow‰½df`õ;¥sÎpzÇî#jW›.ás +ËÂ}°CF¡âù¶!q~3ÿ1 +ýjéÒ¥‡«ØG£Ñ¥Dô‘@–e9þüª¯¨]Ì|¹Ïçû¦HºóçÏIõmàÔ544ü|¨¾Õ6¡×uÝ «ªº‡™5Cö¿©íX,4 ŸÞ™i-szÇî;j½¥rfî`Ól®¼ì20„âq¾Ô>mÖÐÝncæLÓÜ­iÚº`0x*†MMMû-Ë}/ñµ˜ÏtGÓOÔ®òùóçúüª½½½€Èµ@‹ˆD=öÚ/ôÁ`ðªH$²“ˆª™ùô¡NÿcsvE&ˆm㘿¿{íe3œÞ±ûŽÚ¥Tó“ Ô *H)d‡ÝÖÖ6¨LÙÙÙÑóîGd¡òX]]ݶ¡ü΄ +½¦iS4M{ŠˆþàÂDæµ¥}*Ú-¡³8—j™ÕN€ ƒ ‡øØðc3[ßjðª|Oåì¯3HÈùBÛ4D9¡Ýð "ªž2eÊ ¡PÈ?\„¾¦¦& +@4XËgLÓü®Óë*µë·½~DÅyyy“19–â¨Çƒà`4òÃð„Œ°@ 0JÓ´u^p-+Uví}¯ûôŸˆ¥Bóš+¼_vzÇžrhËOp¬×ÃÕ͆÷¤Í{+.ÉÄBaÙ"–{gs׸v|3ÍbæZMÓžÒ4m†õõõOø£àêrU̇ºÓ)Dï¨]YÑht@¯srrü¾)XŽ²M›6}ÒB¯ëº¢iÚ튢¼ +`ÄNœ,VF£Ñi_èþã°ULPm§;ßdÐOÔ®³ÈE'Ÿ·Cq Û!G¨Ñ›23=3™ù&ûlúük¼¬iš¡ëú)NW/Ó4óÑû~ œž‘‘áøÀ/õõõ-À1znðûýW @KE¹ì>pàÀÚD|ß }0ÌîììÜàgÛÔ>\d†^YYÙF:,Ó"Q·­Ó”îSïvzÇžT¼½‰¿ˆ[¿-n^3ç„×_Z*gNd&!;$2©pËv]×­p8ü˜Çã¹=þZºløü,ÁH$òjÌ‚c£,Å|—ÿ@0™»c¾ÔËåZ¸¨]Ì\}2ç;>Ÿï&"š)¸ë ìÚµ+!ý_XèƒÁ๚¦=IDõÌ<Û¦6Ù àó†aÜ`F/'üÓ[üZ¨Â+ZË/çøŽMÑzGíÊ ¶Nx-Œ ”AÌùI,äáÑ»Á ÃЈèbQsÃø4ý4 +=þÍ©íÌÌ+ˆÄqŠ`Ö)OMMÍa¢cvµ—îÝ»÷¸¯[çÍ›w*чM­««ûm¢¾MDè]š¦éDô2€6­Š>p‡Çã™eÆ3ýÚH)¡] ŸÑ¬ðJ§wì K^z—Ž±³óµ­kg}ñ8«ù\´C¨tZñŽ>M5eee¯†q €/@ðÖÈ„pŽ¢(š¦=Àqö膆†CCàXkžÏç»Æéc¢®®î˜¨]̼*&æ}‰DBÆ +dÛMD þ""ôÅ„Û‚A°À†alÐuý¸O¼§n~ÖÿÛš×ÎœíôŽí¢Ìr{z}¹Ik·<â=Æc\Od.EôfÒë±P‡ÇÅ0Œ§÷ïß?“{\7|bCU€-ËúCìQ[“©ŽùVw2–e{~ÕÙÙ¹¬“Íù +M6ÔÕÕ½œ’BÏ̧ÙTñ&¢‹ ÃXlÆ“ý#·šQÂ["uC¬$Ìoê¬ê›:ˆX‹“¼égÄǬæG;€˜’)0C?9;ä† ºÃáð:"š›èMª$Ë¡Mm)Š"z~5õСCßwú⧱±±‰ˆ~§w‹rrr.èCË!véäŸÌ¼<Ñß”²¾§‰¨™™¿bÆ—ÊÊÊ^Œ€1s‰Ø¢9­k½×;½cO.Üö+€j{}:A­Òû/ß͆÷Tb¶CÆBˆ²²² ÃX à2µ ŠÚÚÚF"zR0™yyyŽ?¿ŠF£AÄŸ_Ź5ðûýWÑW…$†yeÌðúƒÌœÿÑGM‡ÃO‰$4¥pÛÏA¨û5ïéÞNïØ +!?nÅ<Æ üß9…‹Kˆ¸64†al7 ã +fþ +3·B2`TU-Š°2*Þëôzjjjz—ˆÊã~¾Æçó}¼^¯›™E¯Bî<ûì³²e|§ÒÖÀEQ. ‡Ãë6lØÐ-¾++&ò!‚ À„È(:½cO*ܲÀã~¾£¥bÖ%ÍkæœO ÑW–O*ØöÊP”5?ÕÕÕ5€à”¦¦æf<¿Âåää8þü*V0󞸟×z½^·Çã¹Àg„ÄWQò7nÜh‡92e„¾ÀÃ0î(--}H,°u ®êC͆×ñÁ©-î^ŠÞŸ*ULa;¤Úݵb(ËZUUÕaFز¬ lœÌ‡1Ï”o +m‰D¥Ãª¾Çú­™îñxŠ‰HhWÃÌ¿‹¹^°gÇžäºÜGD·{<ž\Ã0¶&*r¹4’È"•V;]¦ïتÞs®ã«b ÀúÄÐ΄Ø!ËËËß3 ãEQæáX/„’þ¬D0™ìœœœN¯«†††'<×ÛR@ËÑa°t&ú:eª}€•grYYÙ뺞ÐÕØ”üM°èƒâo5Wz}Nï؇"ë¼>„IJ*,,<û¨¼bN»äÊ…iåÔâ-I[Õdeff¡ç5ìH›²ý€™o ‡ÃvR[ú|¾Åªe¯Âbæ¹ [R¡0ñ+Ò4ízkL°© ]öx<÷èº~0•Ð²Æ{÷ʾ9èN´ ‡GÍž¬×DìÎ[×u%‰Ü÷¸é +xIDAT@GâM4GˆG£ÑŠÊÊÊ6§µg^^ž+Öø7Ù»»ð᪆††%)4F¥¨¨hd|…¼@÷xF$ÿ·h ¢5γ)KÀÝÝÝ÷­Y³Fz3•H¡?Éíöx˲tÿ…¡‰¯x2¼ND…eeeÍ™ž”””\dYV€y6f[¯(ÊâÒÒÒm²$Rè¦i^ô<¡öÙø-O3s~8Þ%›5=(,,<Óív¯p ·MÙ¾ÉÌ ÃáðS²$Rè‡ í˜;… +múžny<ž©ÙJò,X°@2eÊ÷EYn£#½ÃVy<žûu]o—­ ‘B?„èº>"‰dÙòQDû-˺·¥¥å7n”þµSˆ`0xU˜nS– àq˲J’éø€Õ뫪ª:äp•H.ôÀ¿b†.°À(›V“‘áñxªt]ïŽ$ +]»u¾]›*ô¸-ÐÊËËß“ÃT"FB„¥K—~Ú4Í2ØëNáuf^‡ÿ8\:G0œ³ÃÛé>¸ ÀbÃ06Ëá)‘ c¡?‚¦i—¡ÇÊå6fëxwÈÁ`ðÔX™;aŸûà½Ì”q%)ô}~C0¼‘ˆÂÆÙ”g7€‡˜yy8þÄ)áˆû`"ºÀ6eŽF£•••mrHJ$Rèû¥¨¨h¤Ëå*à±)Û˜ù>'¸Cƒ¹13ÍL³Ýhšf¨¢¢¢YE‰D +ýI£iÚ4¥ؘíö˜9§6ÝêkÙ²e“£ÑèzØë>x€Ã0ž‘CP"‘B/"øW¢çþýÅ6f›6îcX›ÂøÀ2Çó#]×£røI$Rè…Ñu݉Dn° +À§lʶÀz˲V§¨;ä#ge°Ï}pÀƒtÃ0Èa'‘H¡OÄê~ À]\6eû.3—¤Ò-’`0˜³Ã_fc¶¶,« ¼¼ü59Ü$)ô ' +]ÈÌk\mc¶›cáìš’õÝK—.`šæØè>˜ˆš-Ë*n $)ôÉZÙ^«(J3Oµ)Kð¸išŠŠŠ½v}çQŒ´)ۃ̼\º–H¤Ð'£Ü!ß `´MÙÚæ9IîƒUE/--}_-‰D +}ÊPRR2Þ²,Àm°É#53sÈ0Œ øžKLÓ¬&¢ÏÙXõè‰ò´U)‰D +}Ê¢iš=îrìÊ“™ŸUU5¿´´t‡hZÉp àMņaüÒmD"…>]êCÓ´ëT˜hSž€'ˆ¨°¬¬ìÃþñ÷Áèy<Ʀ2w(÷x<庮·Ën#‘H¡O;t]‰D°×Âá¸C…B_ŠÝ"ºÀ®MzÜ—”——¿#{ŠD"…>í ç(ŠR +{Ý!¿FDKÊÊÊþtÿ 3¯ƒîƒ™ùEEQòËÊÊž“=C"‘Bï84MËC;…ÏÚ˜íÓ±û÷/ù!Iîƒ?`æ@VVÖ㺮[²7H$Rè‹®ëJGGÇ·‰¨ÀY6eÛ à¡ÎÎΕ7Úì>¸@uì*èDzH$Rè‡ ¡PèSîcæÛ¨6eÛ`„ŸYóÆ)ƒ£K$R臵àŸ;ý²ƒ>kzîÃ?-[X"‘B/‰¡iÚå&¥ñg´(óxX"‘B/‚ÁàµD´©a¿?`uggçúªªªÙ:‰zÉQPP•™™¹À2§$càqUUC«W¯~W¶ˆD"…^’ Š‹‹§*ŠRID×Ù˜í?EÉ/--ý»l‰D +½Ä&ÀEQÖø·f³—™ƒ©¯V"‘H¡võ o$¢0€qC˜n@8VTVV¶Éj–H$Rè“LQQÑH—ËU @)˜ÜF%†a¼!kV"‘H¡O14M› À‚AüùNô܇FÖ¤D"‘BŸâ”””|Þ²¬*ŸÄ?ÿÀ2Çó#]×£²ö$‰ú4aáÂ…™#GŽÌgfˆNëãŸD + + + + Logo - Ocramius Proxy Manager + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Logo - Ocramius Proxy Manager + November 2013 + + + Maestro Pivetta + + + + + MIT + + + + + Marco Pivetta + + + Logo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Autoloader/Autoloader.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Autoloader/Autoloader.php new file mode 100644 index 0000000..91a6fc2 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Autoloader/Autoloader.php @@ -0,0 +1,69 @@ + + * @license MIT + */ +class Autoloader implements AutoloaderInterface +{ + /** + * @var \ProxyManager\FileLocator\FileLocatorInterface + */ + protected $fileLocator; + + /** + * @var \ProxyManager\Inflector\ClassNameInflectorInterface + */ + protected $classNameInflector; + + /** + * @param \ProxyManager\FileLocator\FileLocatorInterface $fileLocator + * @param \ProxyManager\Inflector\ClassNameInflectorInterface $classNameInflector + */ + public function __construct(FileLocatorInterface $fileLocator, ClassNameInflectorInterface $classNameInflector) + { + $this->fileLocator = $fileLocator; + $this->classNameInflector = $classNameInflector; + } + + /** + * {@inheritDoc} + */ + public function __invoke($className) + { + if (class_exists($className, false) || ! $this->classNameInflector->isProxyClassName($className)) { + return false; + } + + $file = $this->fileLocator->getProxyFileName($className); + + if (! file_exists($file)) { + return false; + } + + return (bool) require_once $file; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Autoloader/AutoloaderInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Autoloader/AutoloaderInterface.php new file mode 100644 index 0000000..9670f98 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Autoloader/AutoloaderInterface.php @@ -0,0 +1,37 @@ + + * @license MIT + */ +interface AutoloaderInterface +{ + /** + * Callback to allow the object to be handled as autoloader - tries to autoload the given class name + * + * @param string $className + * + * @return bool + */ + public function __invoke($className); +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php new file mode 100644 index 0000000..b0dcbb0 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php @@ -0,0 +1,178 @@ + + * @license MIT + */ +class Configuration +{ + const DEFAULT_PROXY_NAMESPACE = 'ProxyManagerGeneratedProxy'; + + /** + * @var string|null + */ + protected $proxiesTargetDir; + + /** + * @var string + */ + protected $proxiesNamespace = self::DEFAULT_PROXY_NAMESPACE; + + /** + * @var \ProxyManager\GeneratorStrategy\GeneratorStrategyInterface|null + */ + protected $generatorStrategy; + + /** + * @var callable|null + */ + protected $proxyAutoloader; + + /** + * @var \ProxyManager\Inflector\ClassNameInflectorInterface|null + */ + protected $classNameInflector; + + /** + * @deprecated deprecated since version 0.5 + */ + public function setAutoGenerateProxies() + { + } + + /** + * @return bool + * @deprecated deprecated since version 0.5 + */ + public function doesAutoGenerateProxies() + { + return true; + } + + /** + * @param \ProxyManager\Autoloader\AutoloaderInterface $proxyAutoloader + */ + public function setProxyAutoloader(AutoloaderInterface $proxyAutoloader) + { + $this->proxyAutoloader = $proxyAutoloader; + } + + /** + * @return \ProxyManager\Autoloader\AutoloaderInterface + */ + public function getProxyAutoloader() + { + if (null === $this->proxyAutoloader) { + $this->proxyAutoloader = new Autoloader( + new FileLocator($this->getProxiesTargetDir()), + $this->getClassNameInflector() + ); + } + + return $this->proxyAutoloader; + } + + /** + * @param string $proxiesNamespace + */ + public function setProxiesNamespace($proxiesNamespace) + { + $this->proxiesNamespace = $proxiesNamespace; + } + + /** + * @return string + */ + public function getProxiesNamespace() + { + return $this->proxiesNamespace; + } + + /** + * @param string $proxiesTargetDir + */ + public function setProxiesTargetDir($proxiesTargetDir) + { + $this->proxiesTargetDir = (string) $proxiesTargetDir; + } + + /** + * @return null|string + */ + public function getProxiesTargetDir() + { + if (null === $this->proxiesTargetDir) { + $this->proxiesTargetDir = sys_get_temp_dir(); + } + + return $this->proxiesTargetDir; + } + + /** + * @param \ProxyManager\GeneratorStrategy\GeneratorStrategyInterface $generatorStrategy + */ + public function setGeneratorStrategy(GeneratorStrategyInterface $generatorStrategy) + { + $this->generatorStrategy = $generatorStrategy; + } + + /** + * @return \ProxyManager\GeneratorStrategy\GeneratorStrategyInterface + */ + public function getGeneratorStrategy() + { + if (null === $this->generatorStrategy) { + $this->generatorStrategy = new FileWriterGeneratorStrategy(new FileLocator($this->getProxiesTargetDir())); + } + + return $this->generatorStrategy; + } + + /** + * @param \ProxyManager\Inflector\ClassNameInflectorInterface $classNameInflector + */ + public function setClassNameInflector(ClassNameInflectorInterface $classNameInflector) + { + $this->classNameInflector = $classNameInflector; + } + + /** + * @return \ProxyManager\Inflector\ClassNameInflectorInterface + */ + public function getClassNameInflector() + { + if (null === $this->classNameInflector) { + $this->classNameInflector = new ClassNameInflector($this->getProxiesNamespace()); + } + + return $this->classNameInflector; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/DisabledMethodException.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/DisabledMethodException.php new file mode 100644 index 0000000..42f4eda --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/DisabledMethodException.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class DisabledMethodException extends BadMethodCallException implements ExceptionInterface +{ + const NAME = __CLASS__; + + /** + * @param string $method + * + * @return self + */ + public static function disabledMethod($method) + { + return new self(sprintf('Method "%s" is forcefully disabled', (string) $method)); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/ExceptionInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/ExceptionInterface.php new file mode 100644 index 0000000..34c7d86 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/ExceptionInterface.php @@ -0,0 +1,29 @@ + + * @license MIT + */ +interface ExceptionInterface +{ +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/InvalidProxiedClassException.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/InvalidProxiedClassException.php new file mode 100644 index 0000000..fff18b7 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/InvalidProxiedClassException.php @@ -0,0 +1,41 @@ + + * @license MIT + */ +class InvalidProxiedClassException extends InvalidArgumentException implements ExceptionInterface +{ + /** + * @param ReflectionClass $reflection + * + * @return self + */ + public static function interfaceNotSupported(ReflectionClass $reflection) + { + return new self(sprintf('Provided interface "%s" cannot be proxied', $reflection->getName())); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/InvalidProxyDirectoryException.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/InvalidProxyDirectoryException.php new file mode 100644 index 0000000..cb5d0ea --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/InvalidProxyDirectoryException.php @@ -0,0 +1,40 @@ + + * @license MIT + */ +class InvalidProxyDirectoryException extends InvalidArgumentException implements ExceptionInterface +{ + /** + * @param string $directory + * + * @return self + */ + public static function proxyDirectoryNotFound($directory) + { + return new self(sprintf('Provided directory "%s" does not exist', (string) $directory)); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/UnsupportedProxiedClassException.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/UnsupportedProxiedClassException.php new file mode 100644 index 0000000..68f8215 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Exception/UnsupportedProxiedClassException.php @@ -0,0 +1,47 @@ + + * @license MIT + */ +class UnsupportedProxiedClassException extends LogicException implements ExceptionInterface +{ + /** + * @param ReflectionProperty $property + * + * @return self + */ + public static function unsupportedLocalizedReflectionProperty(ReflectionProperty $property) + { + return new self( + sprintf( + 'Provided reflection property "%s" of class "%s" is private and cannot be localized in PHP 5.3', + $property->getName(), + $property->getDeclaringClass()->getName() + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AbstractBaseFactory.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AbstractBaseFactory.php new file mode 100644 index 0000000..b3de2aa --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AbstractBaseFactory.php @@ -0,0 +1,97 @@ + + * @license MIT + */ +abstract class AbstractBaseFactory +{ + /** + * @var \ProxyManager\Configuration + */ + protected $configuration; + + /** + * @var \ProxyManager\Inflector\ClassNameInflectorInterface + */ + protected $inflector; + + /** + * Cached generated class names + * + * @var string[] + */ + protected $generatedClasses = array(); + + /** + * @var \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator + */ + protected $generator; + + /** + * @param \ProxyManager\Configuration $configuration + */ + public function __construct(Configuration $configuration = null) + { + $this->configuration = $configuration ?: new Configuration(); + // localizing some properties for performance + $this->inflector = $this->configuration->getClassNameInflector(); + } + + /** + * Generate a proxy from a class name + * @param string $className + * @return string proxy class name + */ + protected function generateProxy($className) + { + if (! isset($this->generatedClasses[$className])) { + $this->generatedClasses[$className] = $this->inflector->getProxyClassName( + $className, + array('factory' => get_class($this)) + ); + } + + $proxyClassName = $this->generatedClasses[$className]; + + if (! class_exists($proxyClassName)) { + $className = $this->inflector->getUserClassName($className); + $phpClass = new ClassGenerator($proxyClassName); + + $this->getGenerator()->generate(new ReflectionClass($className), $phpClass); + $this->configuration->getGeneratorStrategy()->generate($phpClass); + $this->configuration->getProxyAutoloader()->__invoke($proxyClassName); + } + + return $proxyClassName; + } + + /** + * @return \ProxyManager\ProxyGenerator\ProxyGeneratorInterface + */ + abstract protected function getGenerator(); +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AbstractLazyFactory.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AbstractLazyFactory.php new file mode 100644 index 0000000..690bfa1 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AbstractLazyFactory.php @@ -0,0 +1,46 @@ + + * @license MIT + */ +abstract class AbstractLazyFactory extends AbstractBaseFactory +{ + /** + * Creates a new lazy proxy instance of the given class with + * the given initializer + * + * @param string $className name of the class to be proxied + * @param \Closure $initializer initializer to be passed to the proxy + * + * @return \ProxyManager\Proxy\LazyLoadingInterface + */ + public function createProxy($className, Closure $initializer) + { + $proxyClassName = $this->generateProxy($className); + + return new $proxyClassName($initializer); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AccessInterceptorScopeLocalizerFactory.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AccessInterceptorScopeLocalizerFactory.php new file mode 100644 index 0000000..629b676 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AccessInterceptorScopeLocalizerFactory.php @@ -0,0 +1,54 @@ + + * @license MIT + */ +class AccessInterceptorScopeLocalizerFactory extends AbstractBaseFactory +{ + /** + * @param object $instance the object to be localized within the access interceptor + * @param \Closure[] $prefixInterceptors an array (indexed by method name) of interceptor closures to be called + * before method logic is executed + * @param \Closure[] $suffixInterceptors an array (indexed by method name) of interceptor closures to be called + * after method logic is executed + * + * @return \ProxyManager\Proxy\AccessInterceptorInterface + */ + public function createProxy($instance, array $prefixInterceptors = array(), array $suffixInterceptors = array()) + { + $proxyClassName = $this->generateProxy(get_class($instance)); + + return new $proxyClassName($instance, $prefixInterceptors, $suffixInterceptors); + } + + /** + * {@inheritDoc} + */ + protected function getGenerator() + { + return $this->generator ?: $this->generator = new AccessInterceptorScopeLocalizerGenerator(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php new file mode 100644 index 0000000..c18d95d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php @@ -0,0 +1,55 @@ + + * @license MIT + */ +class AccessInterceptorValueHolderFactory extends AbstractBaseFactory +{ + /** + * @param object $instance the object to be wrapped within the value holder + * @param \Closure[] $prefixInterceptors an array (indexed by method name) of interceptor closures to be called + * before method logic is executed + * @param \Closure[] $suffixInterceptors an array (indexed by method name) of interceptor closures to be called + * after method logic is executed + * + * @return \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface + */ + public function createProxy($instance, array $prefixInterceptors = array(), array $suffixInterceptors = array()) + { + $className = get_class($instance); + $proxyClassName = $this->generateProxy($className); + + return new $proxyClassName($instance, $prefixInterceptors, $suffixInterceptors); + } + + /** + * {@inheritDoc} + */ + protected function getGenerator() + { + return $this->generator ?: $this->generator = new AccessInterceptorValueHolderGenerator(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/LazyLoadingGhostFactory.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/LazyLoadingGhostFactory.php new file mode 100644 index 0000000..80fdbae --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/LazyLoadingGhostFactory.php @@ -0,0 +1,41 @@ + + * @license MIT + * + * @method GhostObjectInterface createProxy($className, \Closure $initializer) + */ +class LazyLoadingGhostFactory extends AbstractLazyFactory +{ + /** + * {@inheritDoc} + */ + protected function getGenerator() + { + return $this->generator ?: $this->generator = new LazyLoadingGhostGenerator(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/LazyLoadingValueHolderFactory.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/LazyLoadingValueHolderFactory.php new file mode 100644 index 0000000..5891c26 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/LazyLoadingValueHolderFactory.php @@ -0,0 +1,41 @@ + + * @license MIT + * + * @method VirtualProxyInterface createProxy($className, \Closure $initializer) + */ +class LazyLoadingValueHolderFactory extends AbstractLazyFactory +{ + /** + * {@inheritDoc} + */ + protected function getGenerator() + { + return $this->generator ?: $this->generator = new LazyLoadingValueHolderGenerator(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/NullObjectFactory.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/NullObjectFactory.php new file mode 100644 index 0000000..121f6ba --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/NullObjectFactory.php @@ -0,0 +1,51 @@ + + * @license MIT + */ +class NullObjectFactory extends AbstractBaseFactory +{ + /** + * @param object $instanceOrClassName the object to be wrapped or interface to transform to null object + * + * @return \ProxyManager\Proxy\NullobjectInterface + */ + public function createProxy($instanceOrClassName) + { + $className = is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName; + $proxyClassName = $this->generateProxy($className); + + return new $proxyClassName(); + } + + /** + * {@inheritDoc} + */ + protected function getGenerator() + { + return $this->generator ?: $this->generator = new NullObjectGenerator(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/BaseAdapter.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/BaseAdapter.php new file mode 100644 index 0000000..814d327 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/BaseAdapter.php @@ -0,0 +1,81 @@ + + * @license MIT + */ +abstract class BaseAdapter implements AdapterInterface +{ + /** + * Adapter client + * + * @var \Zend\Server\Client + */ + protected $client; + + /** + * Service name mapping + * + * @var string[] + */ + protected $map = array(); + + /** + * Constructor + * + * @param Client $client + * @param array $map map of service names to their aliases + */ + public function __construct(Client $client, array $map = array()) + { + $this->client = $client; + $this->map = $map; + } + + /** + * {@inheritDoc} + */ + public function call($wrappedClass, $method, array $params = array()) + { + $serviceName = $this->getServiceName($wrappedClass, $method); + + if (isset($this->map[$serviceName])) { + $serviceName = $this->map[$serviceName]; + } + + return $this->client->call($serviceName, $params); + } + + /** + * Get the service name will be used by the adapter + * + * @param string $wrappedClass + * @param string $method + * + * @return string Service name + */ + abstract protected function getServiceName($wrappedClass, $method); +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/JsonRpc.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/JsonRpc.php new file mode 100644 index 0000000..aff2700 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/JsonRpc.php @@ -0,0 +1,36 @@ + + * @license MIT + */ +class JsonRpc extends BaseAdapter +{ + /** + * {@inheritDoc} + */ + protected function getServiceName($wrappedClass, $method) + { + return $wrappedClass . '.' . $method; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/Soap.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/Soap.php new file mode 100644 index 0000000..69de386 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/Soap.php @@ -0,0 +1,36 @@ + + * @license MIT + */ +class Soap extends BaseAdapter +{ + /** + * {@inheritDoc} + */ + protected function getServiceName($wrappedClass, $method) + { + return (string) $method; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/XmlRpc.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/XmlRpc.php new file mode 100644 index 0000000..0485ccd --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/XmlRpc.php @@ -0,0 +1,36 @@ + + * @license MIT + */ +class XmlRpc extends BaseAdapter +{ + /** + * {@inheritDoc} + */ + protected function getServiceName($wrappedClass, $method) + { + return $wrappedClass . '.' . $method; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/AdapterInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/AdapterInterface.php new file mode 100644 index 0000000..4168f9d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/AdapterInterface.php @@ -0,0 +1,37 @@ + + * @license MIT + */ +interface AdapterInterface +{ + /** + * Call remote object + * + * @param string $wrappedClass + * @param string $method + * @param array $params + */ + public function call($wrappedClass, $method, array $params = array()); +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObjectFactory.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObjectFactory.php new file mode 100644 index 0000000..f65049b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObjectFactory.php @@ -0,0 +1,71 @@ + + * @license MIT + */ +class RemoteObjectFactory extends AbstractBaseFactory +{ + /** + * @var AdapterInterface + */ + protected $adapter; + + /** + * {@inheritDoc} + * + * @param AdapterInterface $adapter + * @param Configuration $configuration + */ + public function __construct(AdapterInterface $adapter, Configuration $configuration = null) + { + parent::__construct($configuration); + + $this->adapter = $adapter; + } + + /** + * @param string|object $instanceOrClassName + * + * @return \ProxyManager\Proxy\RemoteObjectInterface + */ + public function createProxy($instanceOrClassName) + { + $className = is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName; + $proxyClassName = $this->generateProxy($className); + + return new $proxyClassName($this->adapter); + } + + /** + * {@inheritDoc} + */ + protected function getGenerator() + { + return $this->generator ?: $this->generator = new RemoteObjectGenerator(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/FileLocator/FileLocator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/FileLocator/FileLocator.php new file mode 100644 index 0000000..197595e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/FileLocator/FileLocator.php @@ -0,0 +1,57 @@ + + * @license MIT + */ +class FileLocator implements FileLocatorInterface +{ + /** + * @var string + */ + protected $proxiesDirectory; + + /** + * @param string $proxiesDirectory + * + * @throws \ProxyManager\Exception\InvalidProxyDirectoryException + */ + public function __construct($proxiesDirectory) + { + $this->proxiesDirectory = realpath($proxiesDirectory); + + if (false === $this->proxiesDirectory) { + throw InvalidProxyDirectoryException::proxyDirectoryNotFound($proxiesDirectory); + } + } + + /** + * {@inheritDoc} + */ + public function getProxyFileName($className) + { + return $this->proxiesDirectory . DIRECTORY_SEPARATOR . str_replace('\\', '', $className) . '.php'; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/FileLocator/FileLocatorInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/FileLocator/FileLocatorInterface.php new file mode 100644 index 0000000..2980c5d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/FileLocator/FileLocatorInterface.php @@ -0,0 +1,37 @@ + + * @license MIT + */ +interface FileLocatorInterface +{ + /** + * Retrieves the file name for the given proxy + * + * @param $className + * + * @return mixed + */ + public function getProxyFileName($className); +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/ClassGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/ClassGenerator.php new file mode 100644 index 0000000..0304c42 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/ClassGenerator.php @@ -0,0 +1,54 @@ + + * @license MIT + */ +class ClassGenerator extends ZendClassGenerator +{ + /** + * {@inheritDoc} + */ + public function setExtendedClass($extendedClass) + { + if ($extendedClass) { + $extendedClass = '\\' . trim($extendedClass, '\\'); + } + + return parent::setExtendedClass($extendedClass); + } + + /** + * {@inheritDoc} + */ + public function setImplementedInterfaces(array $interfaces) + { + foreach ($interfaces as & $interface) { + $interface = '\\' . trim($interface, '\\'); + } + + return parent::setImplementedInterfaces($interfaces); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/MagicMethodGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/MagicMethodGenerator.php new file mode 100644 index 0000000..e0bd1f8 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/MagicMethodGenerator.php @@ -0,0 +1,47 @@ + + * @license MIT + */ +class MagicMethodGenerator extends MethodGenerator +{ + public function __construct(ReflectionClass $originalClass, $name, array $parameters = array()) + { + parent::__construct( + $name, + $parameters, + static::FLAG_PUBLIC, + null, + $originalClass->hasMethod($name) ? '{@inheritDoc}' : null + ); + + $this->setReturnsReference(strtolower($name) === '__get'); + + if ($originalClass->hasMethod($name)) { + $this->setReturnsReference($originalClass->getMethod($name)->returnsReference()); + } + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/MethodGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/MethodGenerator.php new file mode 100644 index 0000000..cffd6af --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/MethodGenerator.php @@ -0,0 +1,161 @@ + + * @license MIT + */ +class MethodGenerator extends ZendMethodGenerator +{ + /** + * @var bool + */ + protected $returnsReference = false; + + /** + * @param boolean $returnsReference + */ + public function setReturnsReference($returnsReference) + { + $this->returnsReference = (bool) $returnsReference; + } + + /** + * @return boolean + */ + public function returnsReference() + { + return $this->returnsReference; + } + + /** + * @override enforces generation of \ProxyManager\Generator\MethodGenerator + * + * {@inheritDoc} + */ + public static function fromReflection(MethodReflection $reflectionMethod) + { + /* @var $method self */ + $method = new static(); + + $method->setSourceContent($reflectionMethod->getContents(false)); + $method->setSourceDirty(false); + + if ($reflectionMethod->getDocComment() != '') { + $method->setDocBlock(DocBlockGenerator::fromReflection($reflectionMethod->getDocBlock())); + } + + $method->setFinal($reflectionMethod->isFinal()); + $method->setVisibility(self::extractVisibility($reflectionMethod)); + + foreach ($reflectionMethod->getParameters() as $reflectionParameter) { + $method->setParameter(ParameterGenerator::fromReflection($reflectionParameter)); + } + + $method->setStatic($reflectionMethod->isStatic()); + $method->setName($reflectionMethod->getName()); + $method->setBody($reflectionMethod->getBody()); + $method->setReturnsReference($reflectionMethod->returnsReference()); + + return $method; + } + + /** + * Retrieves the visibility for the given method reflection + * + * @param MethodReflection $reflectionMethod + * + * @return string + */ + private static function extractVisibility(MethodReflection $reflectionMethod) + { + if ($reflectionMethod->isPrivate()) { + return static::VISIBILITY_PRIVATE; + } + + if ($reflectionMethod->isProtected()) { + return static::VISIBILITY_PROTECTED; + } + + return static::VISIBILITY_PUBLIC; + } + + /** + * @override fixes by-reference return value in zf2's method generator + * + * {@inheritDoc} + */ + public function generate() + { + $output = ''; + $indent = $this->getIndentation(); + + if (null !== ($docBlock = $this->getDocBlock())) { + $docBlock->setIndentation($indent); + + $output .= $docBlock->generate(); + } + + $output .= $indent . $this->generateMethodDeclaration() . self::LINE_FEED . $indent . '{' . self::LINE_FEED; + + if ($this->body) { + $output .= preg_replace('#^(.+?)$#m', $indent . $indent . '$1', trim($this->body)) + . self::LINE_FEED; + } + + $output .= $indent . '}' . self::LINE_FEED; + + return $output; + } + + /** + * @return string + */ + private function generateMethodDeclaration() + { + $output = $this->generateVisibility() + . ' function ' + . (($this->returnsReference()) ? '& ' : '') + . $this->getName() . '('; + + $parameterOutput = array(); + + foreach ($this->getParameters() as $parameter) { + $parameterOutput[] = $parameter->generate(); + } + + return $output . implode(', ', $parameterOutput) . ')'; + } + + /** + * @return string + */ + private function generateVisibility() + { + return $this->isAbstract() ? 'abstract ' : (($this->isFinal()) ? 'final ' : '') + . ($this->getVisibility() . (($this->isStatic()) ? ' static' : '')); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/ParameterGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/ParameterGenerator.php new file mode 100644 index 0000000..7c28b7e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/ParameterGenerator.php @@ -0,0 +1,133 @@ + + * @license MIT + */ +class ParameterGenerator extends ZendParameterGenerator +{ + /** + * @override - uses `static` to instantiate the parameter + * + * {@inheritDoc} + */ + public static function fromReflection(ParameterReflection $reflectionParameter) + { + /* @var $param self */ + $param = new static(); + + $param->setName($reflectionParameter->getName()); + $param->setPosition($reflectionParameter->getPosition()); + + $type = static::extractParameterType($reflectionParameter); + + if (null !== $type) { + $param->setType($type); + } + + if ($reflectionParameter->isOptional()) { + $param->setDefaultValue($reflectionParameter->getDefaultValue()); + } + + $param->setPassedByReference($reflectionParameter->isPassedByReference()); + + return $param; + } + + /** + * Retrieves the type of a reflection parameter (null if none is found) + * + * @param ParameterReflection $reflectionParameter + * + * @return string|null + */ + private static function extractParameterType(ParameterReflection $reflectionParameter) + { + if ($reflectionParameter->isArray()) { + return 'array'; + } + + if (method_exists($reflectionParameter, 'isCallable') && $reflectionParameter->isCallable()) { + return 'callable'; + } + + if ($typeClass = $reflectionParameter->getClass()) { + return $typeClass->getName(); + } + + return null; + } + + /** + * @return string + */ + public function generate() + { + return $this->getGeneratedType() + . (true === $this->passedByReference ? '&' : '') + . '$' . $this->name + . $this->generateDefaultValue(); + } + + /** + * @return string + */ + private function generateDefaultValue() + { + if (null === $this->defaultValue) { + return ''; + } + + if (is_string($this->defaultValue)) { + return ' = ' . ValueGenerator::escape($this->defaultValue); + } + + if ($this->defaultValue instanceof ValueGenerator) { + $this->defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE); + } + + return ' = ' . $this->defaultValue; + } + + /** + * Retrieves the generated parameter type + * + * @return string + */ + private function getGeneratedType() + { + if (! $this->type || in_array($this->type, static::$simple)) { + return ''; + } + + if ('array' === $this->type || 'callable' === $this->type) { + return $this->type . ' '; + } + + return '\\' . trim($this->type, '\\') . ' '; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/Util/UniqueIdentifierGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/Util/UniqueIdentifierGenerator.php new file mode 100644 index 0000000..4bb2b77 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/Util/UniqueIdentifierGenerator.php @@ -0,0 +1,53 @@ + + * @license MIT + */ +abstract class UniqueIdentifierGenerator +{ + const VALID_IDENTIFIER_FORMAT = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/'; + const DEFAULT_IDENTIFIER = 'g'; + + /** + * Generates a valid unique identifier from the given name + * + * @param string $name + * + * @return string + */ + public static function getIdentifier($name) + { + return str_replace( + '.', + '', + uniqid( + preg_match(static::VALID_IDENTIFIER_FORMAT, $name) + ? $name + : static::DEFAULT_IDENTIFIER, + true + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/BaseGeneratorStrategy.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/BaseGeneratorStrategy.php new file mode 100644 index 0000000..1e77120 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/BaseGeneratorStrategy.php @@ -0,0 +1,38 @@ + + * @license MIT + */ +class BaseGeneratorStrategy implements GeneratorStrategyInterface +{ + /** + * {@inheritDoc} + */ + public function generate(ClassGenerator $classGenerator) + { + return $classGenerator->generate(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/EvaluatingGeneratorStrategy.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/EvaluatingGeneratorStrategy.php new file mode 100644 index 0000000..bdb4688 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/EvaluatingGeneratorStrategy.php @@ -0,0 +1,69 @@ + + * @license MIT + */ +class EvaluatingGeneratorStrategy implements GeneratorStrategyInterface +{ + /** + * @var bool flag indicating whether {@see eval} can be used + */ + private $canEval = true; + + /** + * Constructor + */ + public function __construct() + { + $this->canEval = ! ini_get('suhosin.executor.disable_eval'); + } + + /** + * Evaluates the generated code before returning it + * + * {@inheritDoc} + */ + public function generate(ClassGenerator $classGenerator) + { + $code = $classGenerator->generate(); + + if (! $this->canEval) { + // @codeCoverageIgnoreStart + $fileName = sys_get_temp_dir() . '/EvaluatingGeneratorStrategy.php.tmp.' . uniqid('', true); + + file_put_contents($fileName, " + * @license MIT + */ +class FileWriterGeneratorStrategy implements GeneratorStrategyInterface +{ + /** + * @var \ProxyManager\FileLocator\FileLocatorInterface + */ + protected $fileLocator; + + /** + * @param \ProxyManager\FileLocator\FileLocatorInterface $fileLocator + */ + public function __construct(FileLocatorInterface $fileLocator) + { + $this->fileLocator = $fileLocator; + } + + /** + * Write generated code to disk and return the class code + * + * {@inheritDoc} + */ + public function generate(ClassGenerator $classGenerator) + { + $className = trim($classGenerator->getNamespaceName(), '\\') + . '\\' . trim($classGenerator->getName(), '\\'); + $generatedCode = $classGenerator->generate(); + $fileName = $this->fileLocator->getProxyFileName($className); + $tmpFileName = $fileName . '.' . uniqid('', true); + + // renaming files is necessary to avoid race conditions when the same file is written multiple times + // in a short time period + file_put_contents($tmpFileName, " + * @license MIT + */ +interface GeneratorStrategyInterface +{ + /** + * Generate the provided class + * + * @param ClassGenerator $classGenerator + * + * @return string the class body + */ + public function generate(ClassGenerator $classGenerator); +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/ClassNameInflector.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/ClassNameInflector.php new file mode 100644 index 0000000..c911b25 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/ClassNameInflector.php @@ -0,0 +1,98 @@ + + * @license MIT + */ +class ClassNameInflector implements ClassNameInflectorInterface +{ + /** + * @var string + */ + protected $proxyNamespace; + + /** + * @var int + */ + private $proxyMarkerLength; + + /** + * @var string + */ + private $proxyMarker; + + /** + * @var \ProxyManager\Inflector\Util\ParameterEncoder + */ + private $parameterEncoder; + + /** + * @param string $proxyNamespace + */ + public function __construct($proxyNamespace) + { + $this->proxyNamespace = (string) $proxyNamespace; + $this->proxyMarker = '\\' . static::PROXY_MARKER . '\\'; + $this->proxyMarkerLength = strlen($this->proxyMarker); + $this->parameterEncoder = new ParameterEncoder(); + } + + /** + * {@inheritDoc} + */ + public function getUserClassName($className) + { + $className = ltrim($className, '\\'); + + if (false === $position = strrpos($className, $this->proxyMarker)) { + return $className; + } + + return substr( + $className, + $this->proxyMarkerLength + $position, + strrpos($className, '\\') - ($position + $this->proxyMarkerLength) + ); + } + + /** + * {@inheritDoc} + */ + public function getProxyClassName($className, array $options = array()) + { + return $this->proxyNamespace + . $this->proxyMarker + . $this->getUserClassName($className) + . '\\' . $this->parameterEncoder->encodeParameters($options); + } + + /** + * {@inheritDoc} + */ + public function isProxyClassName($className) + { + return false !== strrpos($className, $this->proxyMarker); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/ClassNameInflectorInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/ClassNameInflectorInterface.php new file mode 100644 index 0000000..db46a78 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/ClassNameInflectorInterface.php @@ -0,0 +1,61 @@ + + * @license MIT + */ +interface ClassNameInflectorInterface +{ + /** + * Marker for proxy classes - classes containing this marker are considered proxies + */ + const PROXY_MARKER = '__PM__'; + + /** + * Retrieve the class name of a user-defined class + * + * @param string $className + * + * @return string + */ + public function getUserClassName($className); + + /** + * Retrieve the class name of the proxy for the given user-defined class name + * + * @param string $className + * @param array $options arbitrary options to be used for the generated class name + * + * @return mixed + */ + public function getProxyClassName($className, array $options = array()); + + /** + * Retrieve whether the provided class name is a proxy + * + * @param string $className + * + * @return bool + */ + public function isProxyClassName($className); +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/Util/ParameterEncoder.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/Util/ParameterEncoder.php new file mode 100644 index 0000000..82d6d8c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/Util/ParameterEncoder.php @@ -0,0 +1,41 @@ + + * @license MIT + */ +class ParameterEncoder +{ + /** + * Converts the given parameters into a set of characters that are safe to + * use in a class name + * + * @param array $parameters + * + * @return string + */ + public function encodeParameters(array $parameters) + { + return strtr(base64_encode(serialize($parameters)), '+/=', '†‡•'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/AccessInterceptorInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/AccessInterceptorInterface.php new file mode 100644 index 0000000..49d70f2 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/AccessInterceptorInterface.php @@ -0,0 +1,64 @@ + + * @license MIT + */ +interface AccessInterceptorInterface extends ProxyInterface +{ + /** + * Set or remove the prefix interceptor for a method + * + * @link https://github.com/Ocramius/ProxyManager/blob/master/docs/access-interceptor-value-holder.md + * + * A prefix interceptor should have a signature like following: + * + * + * $prefixInterceptor = function ($proxy, $instance, $method, $params, & $returnEarly) {}; + * + * + * @param string $methodName name of the intercepted method + * @param \Closure|null $prefixInterceptor interceptor closure or null to unset the currently active interceptor + * + * @return void + */ + public function setMethodPrefixInterceptor($methodName, \Closure $prefixInterceptor = null); + + /** + * Set or remove the suffix interceptor for a method + * + * @link https://github.com/Ocramius/ProxyManager/blob/master/docs/access-interceptor-value-holder.md + * + * A prefix interceptor should have a signature like following: + * + * + * $suffixInterceptor = function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) {}; + * + * + * @param string $methodName name of the intercepted method + * @param \Closure|null $suffixInterceptor interceptor closure or null to unset the currently active interceptor + * + * @return void + */ + public function setMethodSuffixInterceptor($methodName, \Closure $suffixInterceptor = null); +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/Exception/RemoteObjectException.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/Exception/RemoteObjectException.php new file mode 100644 index 0000000..636a029 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/Exception/RemoteObjectException.php @@ -0,0 +1,31 @@ + + * @license MIT + */ +class RemoteObjectException extends RuntimeException +{ +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/FallbackValueHolderInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/FallbackValueHolderInterface.php new file mode 100644 index 0000000..bf4bc2a --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/FallbackValueHolderInterface.php @@ -0,0 +1,29 @@ + + * @license MIT + */ +interface FallbackValueHolderInterface extends ProxyInterface +{ +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/GhostObjectInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/GhostObjectInterface.php new file mode 100644 index 0000000..77df518 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/GhostObjectInterface.php @@ -0,0 +1,29 @@ + + * @license MIT + */ +interface GhostObjectInterface extends LazyLoadingInterface +{ +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/LazyLoadingInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/LazyLoadingInterface.php new file mode 100644 index 0000000..1da90e6 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/LazyLoadingInterface.php @@ -0,0 +1,64 @@ + + * @license MIT + */ +interface LazyLoadingInterface extends ProxyInterface +{ + /** + * Set or unset the initializer for the proxy instance + * + * @link https://github.com/Ocramius/ProxyManager/blob/master/docs/lazy-loading-value-holder.md#lazy-initialization + * + * An initializer should have a signature like following: + * + * + * $initializer = function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) {}; + * + * + * @param \Closure|null $initializer + * + * @return mixed + */ + public function setProxyInitializer(\Closure $initializer = null); + + /** + * @return \Closure|null + */ + public function getProxyInitializer(); + + /** + * Force initialization of the proxy + * + * @return bool true if the proxy could be initialized + */ + public function initializeProxy(); + + /** + * Retrieves current initialization status of the proxy + * + * @return bool + */ + public function isProxyInitialized(); +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/NullObjectInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/NullObjectInterface.php new file mode 100644 index 0000000..cd41115 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/NullObjectInterface.php @@ -0,0 +1,29 @@ + + * @license MIT + */ +interface NullObjectInterface extends ProxyInterface +{ +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/ProxyInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/ProxyInterface.php new file mode 100644 index 0000000..7d402b4 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/ProxyInterface.php @@ -0,0 +1,29 @@ + + * @license MIT + */ +interface ProxyInterface +{ +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/RemoteObjectInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/RemoteObjectInterface.php new file mode 100644 index 0000000..264fa5e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/RemoteObjectInterface.php @@ -0,0 +1,29 @@ + + * @license MIT + */ +interface RemoteObjectInterface extends ProxyInterface +{ +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/SmartReferenceInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/SmartReferenceInterface.php new file mode 100644 index 0000000..2380b32 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/SmartReferenceInterface.php @@ -0,0 +1,29 @@ + + * @license MIT + */ +interface SmartReferenceInterface extends ProxyInterface +{ +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/ValueHolderInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/ValueHolderInterface.php new file mode 100644 index 0000000..126d543 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/ValueHolderInterface.php @@ -0,0 +1,33 @@ + + * @license MIT + */ +interface ValueHolderInterface extends ProxyInterface +{ + /** + * @return object|null the wrapped value + */ + public function getWrappedValueHolderValue(); +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/VirtualProxyInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/VirtualProxyInterface.php new file mode 100644 index 0000000..fc108c7 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/VirtualProxyInterface.php @@ -0,0 +1,29 @@ + + * @license MIT + */ +interface VirtualProxyInterface extends LazyLoadingInterface, ValueHolderInterface +{ +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/MagicWakeup.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/MagicWakeup.php new file mode 100644 index 0000000..5b7c19d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/MagicWakeup.php @@ -0,0 +1,50 @@ + + * @license MIT + */ +class MagicWakeup extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct(ReflectionClass $originalClass) + { + parent::__construct($originalClass, '__wakeup'); + + /* @var $publicProperties \ReflectionProperty[] */ + $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC); + $unsetProperties = array(); + + foreach ($publicProperties as $publicProperty) { + $unsetProperties[] = '$this->' . $publicProperty->getName(); + } + + $this->setBody($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");" : ''); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptor.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptor.php new file mode 100644 index 0000000..85ba613 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptor.php @@ -0,0 +1,50 @@ + + * @license MIT + */ +class SetMethodPrefixInterceptor extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(PropertyGenerator $prefixInterceptor) + { + parent::__construct('setMethodPrefixInterceptor'); + + $interceptor = new ParameterGenerator('prefixInterceptor'); + + $interceptor->setType('Closure'); + $interceptor->setDefaultValue(null); + $this->setParameter(new ParameterGenerator('methodName')); + $this->setParameter($interceptor); + $this->setDocblock('{@inheritDoc}'); + $this->setBody('$this->' . $prefixInterceptor->getName() . '[$methodName] = $prefixInterceptor;'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptor.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptor.php new file mode 100644 index 0000000..74cf81f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptor.php @@ -0,0 +1,50 @@ + + * @license MIT + */ +class SetMethodSuffixInterceptor extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(PropertyGenerator $suffixInterceptor) + { + parent::__construct('setMethodSuffixInterceptor'); + + $interceptor = new ParameterGenerator('suffixInterceptor'); + + $interceptor->setType('Closure'); + $interceptor->setDefaultValue(null); + $this->setParameter(new ParameterGenerator('methodName')); + $this->setParameter($interceptor); + $this->setDocblock('{@inheritDoc}'); + $this->setBody('$this->' . $suffixInterceptor->getName() . '[$methodName] = $suffixInterceptor;'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodPrefixInterceptors.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodPrefixInterceptors.php new file mode 100644 index 0000000..7462d6e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodPrefixInterceptors.php @@ -0,0 +1,43 @@ + + * @license MIT + */ +class MethodPrefixInterceptors extends PropertyGenerator +{ + /** + * Constructor + */ + public function __construct() + { + parent::__construct(UniqueIdentifierGenerator::getIdentifier('methodPrefixInterceptors')); + + $this->setDefaultValue(array()); + $this->setVisibility(self::VISIBILITY_PRIVATE); + $this->setDocblock('@var \\Closure[] map of interceptors to be called per-method before execution'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodSuffixInterceptors.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodSuffixInterceptors.php new file mode 100644 index 0000000..2b809a6 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodSuffixInterceptors.php @@ -0,0 +1,43 @@ + + * @license MIT + */ +class MethodSuffixInterceptors extends PropertyGenerator +{ + /** + * Constructor + */ + public function __construct() + { + parent::__construct(UniqueIdentifierGenerator::getIdentifier('methodSuffixInterceptors')); + + $this->setDefaultValue(array()); + $this->setVisibility(self::VISIBILITY_PRIVATE); + $this->setDocblock('@var \\Closure[] map of interceptors to be called per-method after execution'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Constructor.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Constructor.php new file mode 100644 index 0000000..a52ecc9 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Constructor.php @@ -0,0 +1,92 @@ + + * @license MIT + */ +class Constructor extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct('__construct'); + + $localizedObject = new ParameterGenerator('localizedObject'); + $prefix = new ParameterGenerator('prefixInterceptors'); + $suffix = new ParameterGenerator('suffixInterceptors'); + + $localizedObject->setType($originalClass->getName()); + $prefix->setDefaultValue(array()); + $suffix->setDefaultValue(array()); + $prefix->setType('array'); + $suffix->setType('array'); + + $this->setParameter($localizedObject); + $this->setParameter($prefix); + $this->setParameter($suffix); + + $localizedProperties = array(); + + foreach ($originalClass->getProperties() as $originalProperty) { + if (PHP_VERSION_ID < 50400 && $originalProperty->isPrivate()) { + // @codeCoverageIgnoreStart + throw UnsupportedProxiedClassException::unsupportedLocalizedReflectionProperty($originalProperty); + // @codeCoverageIgnoreEnd + } + + $propertyName = $originalProperty->getName(); + + if ($originalProperty->isPrivate()) { + $localizedProperties[] = "\\Closure::bind(function () use (\$localizedObject) {\n " + . '$this->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";\n" + . '}, $this, ' . var_export($originalProperty->getDeclaringClass()->getName(), true) + . ')->__invoke();'; + } else { + $localizedProperties[] = '$this->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";"; + } + } + + $this->setDocblock( + "@override constructor to setup interceptors\n\n" + . "@param \\" . $originalClass->getName() . " \$localizedObject\n" + . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" + . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic" + ); + $this->setBody( + (empty($localizedProperties) ? '' : implode("\n\n", $localizedProperties) . "\n\n") + . '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" + . '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;" + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/InterceptedMethod.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/InterceptedMethod.php new file mode 100644 index 0000000..b865ca0 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/InterceptedMethod.php @@ -0,0 +1,67 @@ + + * @license MIT + */ +class InterceptedMethod extends MethodGenerator +{ + /** + * @param \Zend\Code\Reflection\MethodReflection $originalMethod + * @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors + * @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors + * + * @return self + */ + public static function generateMethod( + MethodReflection $originalMethod, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + /* @var $method self */ + $method = static::fromReflection($originalMethod); + $forwardedParams = array(); + + foreach ($originalMethod->getParameters() as $parameter) { + $forwardedParams[] = '$' . $parameter->getName(); + } + + $method->setDocblock('{@inheritDoc}'); + $method->setBody( + InterceptorGenerator::createInterceptedMethodBody( + '$returnValue = parent::' + . $originalMethod->getName() . '(' . implode(', ', $forwardedParams) . ');', + $method, + $prefixInterceptors, + $suffixInterceptors + ) + ); + + return $method; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicClone.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicClone.php new file mode 100644 index 0000000..98e9b19 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicClone.php @@ -0,0 +1,53 @@ + + * @license MIT + */ +class MagicClone extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct($originalClass, '__clone'); + + $this->setBody( + InterceptorGenerator::createInterceptedMethodBody( + $originalClass->hasMethod('__clone') ? '$returnValue = parent::__clone();' : '$returnValue = null;', + $this, + $prefixInterceptors, + $suffixInterceptors + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicGet.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicGet.php new file mode 100644 index 0000000..b6c241f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicGet.php @@ -0,0 +1,73 @@ + + * @license MIT + */ +class MagicGet extends MagicMethodGenerator +{ + /** + * @param ReflectionClass $originalClass + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct($originalClass, '__get', array(new ParameterGenerator('name'))); + + $override = $originalClass->hasMethod('__get'); + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + if ($override) { + $callParent = '$returnValue = & parent::__get($name);'; + } else { + $callParent = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_GET, + 'name', + null, + null, + 'returnValue' + ); + } + + $this->setBody( + InterceptorGenerator::createInterceptedMethodBody( + $callParent, + $this, + $prefixInterceptors, + $suffixInterceptors + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicIsset.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicIsset.php new file mode 100644 index 0000000..0021e22 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicIsset.php @@ -0,0 +1,73 @@ + + * @license MIT + */ +class MagicIsset extends MagicMethodGenerator +{ + /** + * @param ReflectionClass $originalClass + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct($originalClass, '__isset', array(new ParameterGenerator('name'))); + + $override = $originalClass->hasMethod('__isset'); + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + if ($override) { + $callParent = '$returnValue = & parent::__isset($name);'; + } else { + $callParent = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_ISSET, + 'name', + null, + null, + 'returnValue' + ); + } + + $this->setBody( + InterceptorGenerator::createInterceptedMethodBody( + $callParent, + $this, + $prefixInterceptors, + $suffixInterceptors + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSet.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSet.php new file mode 100644 index 0000000..c247808 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSet.php @@ -0,0 +1,77 @@ + + * @license MIT + */ +class MagicSet extends MagicMethodGenerator +{ + /** + * @param \ReflectionClass $originalClass + * @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors + * @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct( + $originalClass, + '__set', + array(new ParameterGenerator('name'), new ParameterGenerator('value')) + ); + + $override = $originalClass->hasMethod('__set'); + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + if ($override) { + $callParent = '$returnValue = & parent::__set($name, $value);'; + } else { + $callParent = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_SET, + 'name', + 'value', + null, + 'returnValue' + ); + } + + $this->setBody( + InterceptorGenerator::createInterceptedMethodBody( + $callParent, + $this, + $prefixInterceptors, + $suffixInterceptors + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSleep.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSleep.php new file mode 100644 index 0000000..3ea4a25 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSleep.php @@ -0,0 +1,57 @@ + + * @license MIT + */ +class MagicSleep extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct($originalClass, '__sleep'); + + $callParent = $originalClass->hasMethod('__sleep') + ? '$returnValue = & parent::__sleep();' + : '$returnValue = array_keys((array) $this);'; + + $this->setBody( + InterceptorGenerator::createInterceptedMethodBody( + $callParent, + $this, + $prefixInterceptors, + $suffixInterceptors + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicUnset.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicUnset.php new file mode 100644 index 0000000..b2edaaf --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicUnset.php @@ -0,0 +1,73 @@ + + * @license MIT + */ +class MagicUnset extends MagicMethodGenerator +{ + /** + * @param ReflectionClass $originalClass + * @param PropertyGenerator $prefixInterceptors + * @param PropertyGenerator $suffixInterceptors + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct($originalClass, '__unset', array(new ParameterGenerator('name'))); + + $override = $originalClass->hasMethod('__unset'); + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + if ($override) { + $callParent = '$returnValue = & parent::__unset($name);'; + } else { + $callParent = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_UNSET, + 'name', + null, + null, + 'returnValue' + ); + } + + $this->setBody( + InterceptorGenerator::createInterceptedMethodBody( + $callParent, + $this, + $prefixInterceptors, + $suffixInterceptors + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Util/InterceptorGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Util/InterceptorGenerator.php new file mode 100644 index 0000000..7ca4fcc --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Util/InterceptorGenerator.php @@ -0,0 +1,83 @@ + + * @license MIT + * + * @internal - this class is just here as a small utility for this component, + * don't use it in your own code + */ +class InterceptorGenerator +{ + /** + * @param string $methodBody the body of the previously generated code. + * It MUST assign the return value to a variable + * `$returnValue` instead of directly returning + * @param \ProxyManager\Generator\MethodGenerator $method + * @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors + * @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors + * + * @return string + */ + public static function createInterceptedMethodBody( + $methodBody, + MethodGenerator $method, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + $name = var_export($method->getName(), true); + $prefixInterceptors = $prefixInterceptors->getName(); + $suffixInterceptors = $suffixInterceptors->getName(); + $params = array(); + + foreach ($method->getParameters() as $parameter) { + $parameterName = $parameter->getName(); + $params[] = var_export($parameterName, true) . ' => $' . $parameter->getName(); + } + + $paramsString = 'array(' . implode(', ', $params) . ')'; + + // @todo do we actually want to keep the value like in a value holder? + return "if (isset(\$this->$prefixInterceptors" . "[$name])) {\n" + . " \$returnEarly = false;\n" + . " \$prefixReturnValue = \$this->$prefixInterceptors" . "[$name]->__invoke(" + . "\$this, \$this, $name, $paramsString, \$returnEarly);\n\n" + . " if (\$returnEarly) {\n" + . " return \$prefixReturnValue;\n" + . " }\n" + . "}\n\n" + . $methodBody . "\n\n" + . "if (isset(\$this->$suffixInterceptors" . "[$name])) {\n" + . " \$returnEarly = false;\n" + . " \$suffixReturnValue = \$this->$suffixInterceptors" . "[$name]->__invoke(" + . "\$this, \$this, $name, $paramsString, \$returnValue, \$returnEarly);\n\n" + . " if (\$returnEarly) {\n" + . " return \$suffixReturnValue;\n" + . " }\n" + . "}\n\n" + . "return \$returnValue;"; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php new file mode 100644 index 0000000..dabb29a --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php @@ -0,0 +1,108 @@ + + * @license MIT + */ +class AccessInterceptorScopeLocalizerGenerator implements ProxyGeneratorInterface +{ + /** + * {@inheritDoc} + */ + public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator) + { + if ($originalClass->isInterface()) { + throw InvalidProxiedClassException::interfaceNotSupported($originalClass); + } + + $classGenerator->setExtendedClass($originalClass->getName()); + $classGenerator->setImplementedInterfaces(array('ProxyManager\\Proxy\\AccessInterceptorInterface')); + $classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors()); + $classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodPrefixInterceptors()); + + $methods = ProxiedMethodsFilter::getProxiedMethods( + $originalClass, + array('__get', '__set', '__isset', '__unset', '__clone', '__sleep') + ); + + /* @var $methods \ReflectionMethod[] */ + foreach ($methods as $method) { + $classGenerator->addMethodFromGenerator( + InterceptedMethod::generateMethod( + new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), + $prefixInterceptors, + $suffixInterceptors + ) + ); + } + + $classGenerator->addMethodFromGenerator( + new Constructor($originalClass, $prefixInterceptors, $suffixInterceptors) + ); + $classGenerator->addMethodFromGenerator(new SetMethodPrefixInterceptor($prefixInterceptors)); + $classGenerator->addMethodFromGenerator(new SetMethodSuffixInterceptor($suffixInterceptors)); + $classGenerator->addMethodFromGenerator( + new MagicGet($originalClass, $prefixInterceptors, $suffixInterceptors) + ); + $classGenerator->addMethodFromGenerator( + new MagicSet($originalClass, $prefixInterceptors, $suffixInterceptors) + ); + $classGenerator->addMethodFromGenerator( + new MagicIsset($originalClass, $prefixInterceptors, $suffixInterceptors) + ); + $classGenerator->addMethodFromGenerator( + new MagicUnset($originalClass, $prefixInterceptors, $suffixInterceptors) + ); + $classGenerator->addMethodFromGenerator( + new MagicSleep($originalClass, $prefixInterceptors, $suffixInterceptors) + ); + $classGenerator->addMethodFromGenerator( + new MagicClone($originalClass, $prefixInterceptors, $suffixInterceptors) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php new file mode 100644 index 0000000..a2e9c8a --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Constructor.php @@ -0,0 +1,79 @@ + + * @license MIT + */ +class Constructor extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $valueHolder, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct('__construct'); + + $prefix = new ParameterGenerator('prefixInterceptors'); + $suffix = new ParameterGenerator('suffixInterceptors'); + + $prefix->setDefaultValue(array()); + $suffix->setDefaultValue(array()); + $prefix->setType('array'); + $suffix->setType('array'); + + $this->setParameter(new ParameterGenerator('wrappedObject')); + $this->setParameter($prefix); + $this->setParameter($suffix); + + /* @var $publicProperties \ReflectionProperty[] */ + $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC); + $unsetProperties = array(); + + foreach ($publicProperties as $publicProperty) { + $unsetProperties[] = '$this->' . $publicProperty->getName(); + } + + $this->setDocblock( + "@override constructor to setup interceptors\n\n" + . "@param \\" . $originalClass->getName() . " \$wrappedObject\n" + . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" + . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic" + ); + $this->setBody( + ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') + . '$this->' . $valueHolder->getName() . " = \$wrappedObject;\n" + . '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" + . '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;" + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/InterceptedMethod.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/InterceptedMethod.php new file mode 100644 index 0000000..46aab2d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/InterceptedMethod.php @@ -0,0 +1,70 @@ + + * @license MIT + */ +class InterceptedMethod extends MethodGenerator +{ + /** + * @param \Zend\Code\Reflection\MethodReflection $originalMethod + * @param \Zend\Code\Generator\PropertyGenerator $valueHolderProperty + * @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors + * @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors + * + * @return self + */ + public static function generateMethod( + MethodReflection $originalMethod, + PropertyGenerator $valueHolderProperty, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + /* @var $method self */ + $method = static::fromReflection($originalMethod); + $forwardedParams = array(); + + foreach ($originalMethod->getParameters() as $parameter) { + $forwardedParams[] = '$' . $parameter->getName(); + } + + $method->setDocblock('{@inheritDoc}'); + $method->setBody( + InterceptorGenerator::createInterceptedMethodBody( + '$returnValue = $this->' . $valueHolderProperty->getName() . '->' + . $originalMethod->getName() . '(' . implode(', ', $forwardedParams) . ');', + $method, + $valueHolderProperty, + $prefixInterceptors, + $suffixInterceptors + ) + ); + + return $method; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicClone.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicClone.php new file mode 100644 index 0000000..764ba77 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicClone.php @@ -0,0 +1,58 @@ + + * @license MIT + */ +class MagicClone extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $valueHolderProperty, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + parent::__construct($originalClass, '__clone'); + + $valueHolder = $valueHolderProperty->getName(); + $prefix = $prefixInterceptors->getName(); + $suffix = $suffixInterceptors->getName(); + + $this->setBody( + "\$this->$valueHolder = clone \$this->$valueHolder;\n\n" + . "foreach (\$this->$prefix as \$key => \$value) {\n" + . " \$this->$prefix" . "[\$key] = clone \$value;\n" + . "}\n\n" + . "foreach (\$this->$suffix as \$key => \$value) {\n" + . " \$this->$suffix" . "[\$key] = clone \$value;\n" + . "}" + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicGet.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicGet.php new file mode 100644 index 0000000..77e6c0c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicGet.php @@ -0,0 +1,78 @@ + + * @license MIT + */ +class MagicGet extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $valueHolder, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors, + PublicPropertiesMap $publicProperties + ) { + parent::__construct($originalClass, '__get', array(new ParameterGenerator('name'))); + + $override = $originalClass->hasMethod('__get'); + $valueHolderName = $valueHolder->getName(); + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + $callParent = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_GET, + 'name', + 'value', + $valueHolder, + 'returnValue' + ); + + if (! $publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' $returnValue = & $this->' . $valueHolderName . '->$name;' + . "\n} else {\n $callParent\n}\n\n"; + } + + $this->setBody( + InterceptorGenerator::createInterceptedMethodBody( + $callParent, + $this, + $valueHolder, + $prefixInterceptors, + $suffixInterceptors + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicIsset.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicIsset.php new file mode 100644 index 0000000..daa6b74 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicIsset.php @@ -0,0 +1,78 @@ + + * @license MIT + */ +class MagicIsset extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $valueHolder, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors, + PublicPropertiesMap $publicProperties + ) { + parent::__construct($originalClass, '__isset', array(new ParameterGenerator('name'))); + + $override = $originalClass->hasMethod('__isset'); + $valueHolderName = $valueHolder->getName(); + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + $callParent = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_ISSET, + 'name', + 'value', + $valueHolder, + 'returnValue' + ); + + if (! $publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' $returnValue = isset($this->' . $valueHolderName . '->$name);' + . "\n} else {\n $callParent\n}\n\n"; + } + + $this->setBody( + InterceptorGenerator::createInterceptedMethodBody( + $callParent, + $this, + $valueHolder, + $prefixInterceptors, + $suffixInterceptors + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicSet.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicSet.php new file mode 100644 index 0000000..f79747d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicSet.php @@ -0,0 +1,82 @@ + + * @license MIT + */ +class MagicSet extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $valueHolder, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors, + PublicPropertiesMap $publicProperties + ) { + parent::__construct( + $originalClass, + '__set', + array(new ParameterGenerator('name'), new ParameterGenerator('value')) + ); + + $override = $originalClass->hasMethod('__set'); + $valueHolderName = $valueHolder->getName(); + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + $callParent = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_SET, + 'name', + 'value', + $valueHolder, + 'returnValue' + ); + + if (! $publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' $returnValue = ($this->' . $valueHolderName . '->$name = $value);' + . "\n} else {\n $callParent\n}\n\n"; + } + + $this->setBody( + InterceptorGenerator::createInterceptedMethodBody( + $callParent, + $this, + $valueHolder, + $prefixInterceptors, + $suffixInterceptors + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php new file mode 100644 index 0000000..1484c14 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnset.php @@ -0,0 +1,80 @@ + + * @license MIT + */ +class MagicUnset extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $valueHolder, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors, + PublicPropertiesMap $publicProperties + ) { + parent::__construct($originalClass, '__unset', array(new ParameterGenerator('name'))); + + $override = $originalClass->hasMethod('__unset'); + $valueHolderName = $valueHolder->getName(); + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + $callParent = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_UNSET, + 'name', + 'value', + $valueHolder, + 'returnValue' + ); + + if (! $publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' unset($this->' . $valueHolderName . '->$name);' + . "\n} else {\n $callParent\n}\n\n"; + } + + $callParent .= '$returnValue = false;'; + + $this->setBody( + InterceptorGenerator::createInterceptedMethodBody( + $callParent, + $this, + $valueHolder, + $prefixInterceptors, + $suffixInterceptors + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Util/InterceptorGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Util/InterceptorGenerator.php new file mode 100644 index 0000000..b713a1e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Util/InterceptorGenerator.php @@ -0,0 +1,85 @@ + + * @license MIT + * + * @internal - this class is just here as a small utility for this component, + * don't use it in your own code + */ +class InterceptorGenerator +{ + /** + * @param string $methodBody the body of the previously generated code. + * It MUST assign the return value to a variable + * `$returnValue` instead of directly returning + * @param \ProxyManager\Generator\MethodGenerator $method + * @param \Zend\Code\Generator\PropertyGenerator $valueHolder + * @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors + * @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors + * + * @return string + */ + public static function createInterceptedMethodBody( + $methodBody, + MethodGenerator $method, + PropertyGenerator $valueHolder, + PropertyGenerator $prefixInterceptors, + PropertyGenerator $suffixInterceptors + ) { + $name = var_export($method->getName(), true); + $valueHolder = $valueHolder->getName(); + $prefixInterceptors = $prefixInterceptors->getName(); + $suffixInterceptors = $suffixInterceptors->getName(); + $params = array(); + + foreach ($method->getParameters() as $parameter) { + $parameterName = $parameter->getName(); + $params[] = var_export($parameterName, true) . ' => $' . $parameter->getName(); + } + + $paramsString = 'array(' . implode(', ', $params) . ')'; + + return "if (isset(\$this->$prefixInterceptors" . "[$name])) {\n" + . " \$returnEarly = false;\n" + . " \$prefixReturnValue = \$this->$prefixInterceptors" . "[$name]->__invoke(" + . "\$this, \$this->$valueHolder, $name, $paramsString, \$returnEarly);\n\n" + . " if (\$returnEarly) {\n" + . " return \$prefixReturnValue;\n" + . " }\n" + . "}\n\n" + . $methodBody . "\n\n" + . "if (isset(\$this->$suffixInterceptors" . "[$name])) {\n" + . " \$returnEarly = false;\n" + . " \$suffixReturnValue = \$this->$suffixInterceptors" . "[$name]->__invoke(" + . "\$this, \$this->$valueHolder, $name, $paramsString, \$returnValue, \$returnEarly);\n\n" + . " if (\$returnEarly) {\n" + . " return \$suffixReturnValue;\n" + . " }\n" + . "}\n\n" + . "return \$returnValue;"; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php new file mode 100644 index 0000000..6abac1f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php @@ -0,0 +1,130 @@ + + * @license MIT + */ +class AccessInterceptorValueHolderGenerator implements ProxyGeneratorInterface +{ + /** + * {@inheritDoc} + */ + public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator) + { + $publicProperties = new PublicPropertiesMap($originalClass); + $interfaces = array( + 'ProxyManager\\Proxy\\AccessInterceptorInterface', + 'ProxyManager\\Proxy\\ValueHolderInterface', + ); + + if ($originalClass->isInterface()) { + $interfaces[] = $originalClass->getName(); + } else { + $classGenerator->setExtendedClass($originalClass->getName()); + } + + $classGenerator->setImplementedInterfaces($interfaces); + $classGenerator->addPropertyFromGenerator($valueHolder = new ValueHolderProperty()); + $classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors()); + $classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodSuffixInterceptors()); + $classGenerator->addPropertyFromGenerator($publicProperties); + + foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) { + $classGenerator->addMethodFromGenerator( + InterceptedMethod::generateMethod( + new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), + $valueHolder, + $prefixInterceptors, + $suffixInterceptors + ) + ); + } + + $classGenerator->addMethodFromGenerator( + new Constructor($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors) + ); + $classGenerator->addMethodFromGenerator( + new GetWrappedValueHolderValue($valueHolder) + ); + $classGenerator->addMethodFromGenerator( + new SetMethodPrefixInterceptor($prefixInterceptors) + ); + $classGenerator->addMethodFromGenerator( + new SetMethodSuffixInterceptor($suffixInterceptors) + ); + + $classGenerator->addMethodFromGenerator( + new MagicGet($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties) + ); + + $classGenerator->addMethodFromGenerator( + new MagicSet($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties) + ); + + $classGenerator->addMethodFromGenerator( + new MagicIsset($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties) + ); + + $classGenerator->addMethodFromGenerator( + new MagicUnset($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties) + ); + + $classGenerator->addMethodFromGenerator( + new MagicClone($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors) + ); + $classGenerator->addMethodFromGenerator( + new MagicSleep($originalClass, $valueHolder) + ); + $classGenerator->addMethodFromGenerator( + new MagicWakeup($originalClass, $valueHolder) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/CallInitializer.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/CallInitializer.php new file mode 100644 index 0000000..92be722 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/CallInitializer.php @@ -0,0 +1,67 @@ + + * @license MIT + */ +class CallInitializer extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct( + PropertyGenerator $initializerProperty, + PropertyGenerator $publicPropertiesDefaults, + PropertyGenerator $initializationTracker + ) { + parent::__construct(UniqueIdentifierGenerator::getIdentifier('callInitializer')); + $this->setDocblock("Triggers initialization logic for this ghost object"); + + $this->setParameters(array( + new ParameterGenerator('methodName'), + new ParameterGenerator('parameters', 'array'), + )); + + $this->setVisibility(static::VISIBILITY_PRIVATE); + + $initializer = $initializerProperty->getName(); + $initialization = $initializationTracker->getName(); + + $this->setBody( + 'if ($this->' . $initialization . ' || ! $this->' . $initializer . ') {' . "\n return;\n}\n\n" + . "\$this->" . $initialization . " = true;\n\n" + . "foreach (self::\$" . $publicPropertiesDefaults->getName() . " as \$key => \$default) {\n" + . " \$this->\$key = \$default;\n" + . "}\n\n" + . '$this->' . $initializer . '->__invoke' + . '($this, $methodName, $parameters, $this->' . $initializer . ');' . "\n\n" + . "\$this->" . $initialization . " = false;" + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/Constructor.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/Constructor.php new file mode 100644 index 0000000..95c7380 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/Constructor.php @@ -0,0 +1,58 @@ + + * @license MIT + */ +class Constructor extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty) + { + parent::__construct('__construct'); + + $this->setParameter(new ParameterGenerator('initializer')); + + /* @var $publicProperties \ReflectionProperty[] */ + $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC); + $unsetProperties = array(); + + foreach ($publicProperties as $publicProperty) { + $unsetProperties[] = '$this->' . $publicProperty->getName(); + } + + $this->setDocblock("@override constructor for lazy initialization\n\n@param \\Closure|null \$initializer"); + $this->setBody( + ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') + . '$this->' . $initializerProperty->getName() . ' = $initializer;' + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/GetProxyInitializer.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/GetProxyInitializer.php new file mode 100644 index 0000000..5b1d75a --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/GetProxyInitializer.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class GetProxyInitializer extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(PropertyGenerator $initializerProperty) + { + parent::__construct('getProxyInitializer'); + $this->setDocblock('{@inheritDoc}'); + $this->setBody('return $this->' . $initializerProperty->getName() . ';'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/InitializeProxy.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/InitializeProxy.php new file mode 100644 index 0000000..cf5d417 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/InitializeProxy.php @@ -0,0 +1,47 @@ + + * @license MIT + */ +class InitializeProxy extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(PropertyGenerator $initializerProperty, ZendMethodGenerator $callInitializer) + { + parent::__construct('initializeProxy'); + $this->setDocblock('{@inheritDoc}'); + + $this->setBody( + 'return $this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() + . '(\'initializeProxy\', array());' + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/IsProxyInitialized.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/IsProxyInitialized.php new file mode 100644 index 0000000..110ef31 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/IsProxyInitialized.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class IsProxyInitialized extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(PropertyGenerator $initializerProperty) + { + parent::__construct('isProxyInitialized'); + $this->setDocblock('{@inheritDoc}'); + $this->setBody('return ! $this->' . $initializerProperty->getName() . ';'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/LazyLoadingMethodInterceptor.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/LazyLoadingMethodInterceptor.php new file mode 100644 index 0000000..c5ce434 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/LazyLoadingMethodInterceptor.php @@ -0,0 +1,71 @@ + + * @license MIT + */ +class LazyLoadingMethodInterceptor extends MethodGenerator +{ + /** + * @param \Zend\Code\Reflection\MethodReflection $originalMethod + * @param \Zend\Code\Generator\PropertyGenerator $initializerProperty + * @param \Zend\Code\Generator\MethodGenerator $callInitializer + * + * @return LazyLoadingMethodInterceptor|static + */ + public static function generateMethod( + MethodReflection $originalMethod, + PropertyGenerator $initializerProperty, + ZendMethodGenerator $callInitializer + ) { + /* @var $method self */ + $method = static::fromReflection($originalMethod); + $parameters = $originalMethod->getParameters(); + $methodName = $originalMethod->getName(); + $initializerParams = array(); + $forwardedParams = array(); + + foreach ($parameters as $parameter) { + $parameterName = $parameter->getName(); + $initializerParams[] = var_export($parameterName, true) . ' => $' . $parameterName; + $forwardedParams[] = '$' . $parameterName; + } + + $method->setBody( + '$this->' . $initializerProperty->getName() + . ' && $this->' . $callInitializer->getName() + . '(' . var_export($methodName, true) + . ', array(' . implode(', ', $initializerParams) . "));\n\n" + . 'return parent::' + . $methodName . '(' . implode(', ', $forwardedParams) . ');' + ); + $method->setDocblock('{@inheritDoc}'); + + return $method; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicClone.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicClone.php new file mode 100644 index 0000000..34d999b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicClone.php @@ -0,0 +1,50 @@ + + * @license MIT + */ +class MagicClone extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + MethodGenerator $callInitializer + ) { + parent::__construct($originalClass, '__clone'); + + $this->setBody( + '$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() + . '(\'__clone\', array());' + . ($originalClass->hasMethod('__clone') ? "\n\nparent::__clone();" : '') + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGet.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGet.php new file mode 100644 index 0000000..6ede469 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGet.php @@ -0,0 +1,77 @@ + + * @license MIT + */ +class MagicGet extends MagicMethodGenerator +{ + /** + * @param \ReflectionClass $originalClass + * @param \Zend\Code\Generator\PropertyGenerator $initializerProperty + * @param \Zend\Code\Generator\MethodGenerator $callInitializer + * @param \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap $publicProperties + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + MethodGenerator $callInitializer, + PublicPropertiesMap $publicProperties + ) { + parent::__construct($originalClass, '__get', array(new ParameterGenerator('name'))); + + $override = $originalClass->hasMethod('__get'); + $callParent = ''; + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + if (! $publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' return $this->$name;' + . "\n}\n\n"; + } + + if ($override) { + $callParent .= 'return parent::__get($name);'; + } else { + $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_GET, + 'name' + ); + } + + $this->setBody( + '$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() + . '(\'__get\', array(\'name\' => $name));' + . "\n\n" . $callParent + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicIsset.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicIsset.php new file mode 100644 index 0000000..6c0f676 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicIsset.php @@ -0,0 +1,77 @@ + + * @license MIT + */ +class MagicIsset extends MagicMethodGenerator +{ + /** + * @param \ReflectionClass $originalClass + * @param \Zend\Code\Generator\PropertyGenerator $initializerProperty + * @param \Zend\Code\Generator\MethodGenerator $callInitializer + * @param \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap $publicProperties + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + MethodGenerator $callInitializer, + PublicPropertiesMap $publicProperties + ) { + parent::__construct($originalClass, '__isset', array(new ParameterGenerator('name'))); + + $override = $originalClass->hasMethod('__isset'); + $callParent = ''; + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + if (! $publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' return isset($this->$name);' + . "\n}\n\n"; + } + + if ($override) { + $callParent .= 'return parent::__isset($name);'; + } else { + $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_ISSET, + 'name' + ); + } + + $this->setBody( + '$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() + . '(\'__isset\', array(\'name\' => $name));' + . "\n\n" . $callParent + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSet.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSet.php new file mode 100644 index 0000000..76edc50 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSet.php @@ -0,0 +1,81 @@ + + * @license MIT + */ +class MagicSet extends MagicMethodGenerator +{ + /** + * @param \ReflectionClass $originalClass + * @param \Zend\Code\Generator\PropertyGenerator $initializerProperty + * @param \Zend\Code\Generator\MethodGenerator $callInitializer + * @param \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap $publicProperties + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + MethodGenerator $callInitializer, + PublicPropertiesMap $publicProperties + ) { + parent::__construct( + $originalClass, + '__set', + array(new ParameterGenerator('name'), new ParameterGenerator('value')) + ); + + $override = $originalClass->hasMethod('__set'); + $callParent = ''; + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + if (! $publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' return ($this->$name = $value);' + . "\n}\n\n"; + } + + if ($override) { + $callParent .= 'return parent::__set($name, $value);'; + } else { + $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_SET, + 'name', + 'value' + ); + } + + $this->setBody( + '$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() + . '(\'__set\', array(\'name\' => $name, \'value\' => $value));' . "\n\n" . $callParent + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSleep.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSleep.php new file mode 100644 index 0000000..a8036b2 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSleep.php @@ -0,0 +1,50 @@ + + * @license MIT + */ +class MagicSleep extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + MethodGenerator $callInitializer + ) { + parent::__construct($originalClass, '__sleep'); + + $this->setBody( + '$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() + . '(\'__sleep\', array());' . "\n\n" + . ($originalClass->hasMethod('__sleep') ? 'return parent::__sleep();' : 'return array_keys((array) $this);') + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicUnset.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicUnset.php new file mode 100644 index 0000000..7ad1357 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicUnset.php @@ -0,0 +1,78 @@ + + * @license MIT + */ +class MagicUnset extends MagicMethodGenerator +{ + /** + * @param \ReflectionClass $originalClass + * @param \Zend\Code\Generator\PropertyGenerator $initializerProperty + * @param \Zend\Code\Generator\MethodGenerator $callInitializer + * @param \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap $publicProperties + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + MethodGenerator $callInitializer, + PublicPropertiesMap $publicProperties + ) { + parent::__construct($originalClass, '__unset', array(new ParameterGenerator('name'))); + + $override = $originalClass->hasMethod('__unset'); + $callParent = ''; + + $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); + + if (! $publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' unset($this->$name);' + . "\n\n return;" + . "\n}\n\n"; + } + + if ($override) { + $callParent .= "return parent::__unset(\$name);"; + } else { + $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_UNSET, + 'name' + ); + } + + $this->setBody( + '$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() + . '(\'__unset\', array(\'name\' => $name));' + . "\n\n" . $callParent + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php new file mode 100644 index 0000000..30e37bb --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php @@ -0,0 +1,49 @@ + + * @license MIT + */ +class SetProxyInitializer extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(PropertyGenerator $initializerProperty) + { + parent::__construct('setProxyInitializer'); + + $initializerParameter = new ParameterGenerator('initializer'); + + $initializerParameter->setType('Closure'); + $initializerParameter->setDefaultValue(null); + $this->setParameter($initializerParameter); + $this->setDocblock('{@inheritDoc}'); + $this->setBody('$this->' . $initializerProperty->getName() . ' = $initializer;'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializationTracker.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializationTracker.php new file mode 100644 index 0000000..41b10d9 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializationTracker.php @@ -0,0 +1,43 @@ + + * @license MIT + */ +class InitializationTracker extends PropertyGenerator +{ + /** + * Constructor + */ + public function __construct() + { + parent::__construct(UniqueIdentifierGenerator::getIdentifier('initializationTracker')); + + $this->setVisibility(self::VISIBILITY_PRIVATE); + $this->setDocblock('@var bool tracks initialization status - true while the object is initializing'); + $this->setDefaultValue(false); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializerProperty.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializerProperty.php new file mode 100644 index 0000000..3a3a650 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializerProperty.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class InitializerProperty extends PropertyGenerator +{ + /** + * Constructor + */ + public function __construct() + { + parent::__construct(UniqueIdentifierGenerator::getIdentifier('initializer')); + + $this->setVisibility(self::VISIBILITY_PRIVATE); + $this->setDocblock('@var \\Closure|null initializer responsible for generating the wrapped object'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php new file mode 100644 index 0000000..6a42fb1 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php @@ -0,0 +1,104 @@ + + * @license MIT + */ +class LazyLoadingGhostGenerator implements ProxyGeneratorInterface +{ + /** + * {@inheritDoc} + */ + public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator) + { + $interfaces = array('ProxyManager\\Proxy\\GhostObjectInterface'); + $publicProperties = new PublicPropertiesMap($originalClass); + $publicPropertiesDefaults = new PublicPropertiesDefaults($originalClass); + + if ($originalClass->isInterface()) { + $interfaces[] = $originalClass->getName(); + } else { + $classGenerator->setExtendedClass($originalClass->getName()); + } + + $classGenerator->setImplementedInterfaces($interfaces); + $classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty()); + $classGenerator->addPropertyFromGenerator($initializationTracker = new InitializationTracker()); + $classGenerator->addPropertyFromGenerator($publicProperties); + $classGenerator->addPropertyFromGenerator($publicPropertiesDefaults); + + $init = new CallInitializer($initializer, $publicPropertiesDefaults, $initializationTracker); + + $classGenerator->addMethodFromGenerator($init); + + foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) { + $classGenerator->addMethodFromGenerator( + LazyLoadingMethodInterceptor::generateMethod( + new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), + $initializer, + $init + ) + ); + } + + $classGenerator->addMethodFromGenerator(new Constructor($originalClass, $initializer)); + + $classGenerator->addMethodFromGenerator(new MagicGet($originalClass, $initializer, $init, $publicProperties)); + $classGenerator->addMethodFromGenerator(new MagicSet($originalClass, $initializer, $init, $publicProperties)); + $classGenerator->addMethodFromGenerator(new MagicIsset($originalClass, $initializer, $init, $publicProperties)); + $classGenerator->addMethodFromGenerator(new MagicUnset($originalClass, $initializer, $init, $publicProperties)); + $classGenerator->addMethodFromGenerator(new MagicClone($originalClass, $initializer, $init)); + $classGenerator->addMethodFromGenerator(new MagicSleep($originalClass, $initializer, $init)); + + $classGenerator->addMethodFromGenerator(new SetProxyInitializer($initializer)); + $classGenerator->addMethodFromGenerator(new GetProxyInitializer($initializer)); + $classGenerator->addMethodFromGenerator(new InitializeProxy($initializer, $init)); + $classGenerator->addMethodFromGenerator(new IsProxyInitialized($initializer)); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/Constructor.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/Constructor.php new file mode 100644 index 0000000..5607d15 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/Constructor.php @@ -0,0 +1,61 @@ + + * @license MIT + */ +class Constructor extends MethodGenerator +{ + /** + * Constructor + * + * @param ReflectionClass $originalClass Reflection of the class to proxy + * @param PropertyGenerator $initializerProperty Initializer property + */ + public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty) + { + parent::__construct('__construct'); + + $this->setParameter(new ParameterGenerator('initializer')); + + /* @var $publicProperties \ReflectionProperty[] */ + $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC); + $unsetProperties = array(); + + foreach ($publicProperties as $publicProperty) { + $unsetProperties[] = '$this->' . $publicProperty->getName(); + } + + $this->setDocblock("@override constructor for lazy initialization\n\n@param \\Closure|null \$initializer"); + $this->setBody( + ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') + . '$this->' . $initializerProperty->getName() . ' = $initializer;' + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/GetProxyInitializer.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/GetProxyInitializer.php new file mode 100644 index 0000000..3dd0854 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/GetProxyInitializer.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class GetProxyInitializer extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(PropertyGenerator $initializerProperty) + { + parent::__construct('getProxyInitializer'); + $this->setDocblock('{@inheritDoc}'); + $this->setBody('return $this->' . $initializerProperty->getName() . ';'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/InitializeProxy.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/InitializeProxy.php new file mode 100644 index 0000000..4c358b1 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/InitializeProxy.php @@ -0,0 +1,49 @@ + + * @license MIT + */ +class InitializeProxy extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(PropertyGenerator $initializerProperty, PropertyGenerator $valueHolderProperty) + { + parent::__construct('initializeProxy'); + $this->setDocblock('{@inheritDoc}'); + + $initializer = $initializerProperty->getName(); + + $this->setBody( + 'return $this->' . $initializer . ' && $this->' . $initializer + . '->__invoke($this->' . $valueHolderProperty->getName() + . ', $this, \'initializeProxy\', array(), $this->' . $initializer . ');' + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/IsProxyInitialized.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/IsProxyInitialized.php new file mode 100644 index 0000000..34fdd0b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/IsProxyInitialized.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class IsProxyInitialized extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(PropertyGenerator $valueHolderProperty) + { + parent::__construct('isProxyInitialized'); + $this->setDocblock('{@inheritDoc}'); + $this->setBody('return null !== $this->' . $valueHolderProperty->getName() . ';'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/LazyLoadingMethodInterceptor.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/LazyLoadingMethodInterceptor.php new file mode 100644 index 0000000..b4ce370 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/LazyLoadingMethodInterceptor.php @@ -0,0 +1,72 @@ + + * @license MIT + */ +class LazyLoadingMethodInterceptor extends MethodGenerator +{ + /** + * @param \Zend\Code\Reflection\MethodReflection $originalMethod + * @param \Zend\Code\Generator\PropertyGenerator $initializerProperty + * @param \Zend\Code\Generator\PropertyGenerator $valueHolderProperty + * + * @return LazyLoadingMethodInterceptor|static + */ + public static function generateMethod( + MethodReflection $originalMethod, + PropertyGenerator $initializerProperty, + PropertyGenerator $valueHolderProperty + ) { + /* @var $method self */ + $method = static::fromReflection($originalMethod); + $initializerName = $initializerProperty->getName(); + $valueHolderName = $valueHolderProperty->getName(); + $parameters = $originalMethod->getParameters(); + $methodName = $originalMethod->getName(); + $initializerParams = array(); + $forwardedParams = array(); + + foreach ($parameters as $parameter) { + $parameterName = $parameter->getName(); + $initializerParams[] = var_export($parameterName, true) . ' => $' . $parameterName; + $forwardedParams[] = '$' . $parameterName; + } + + $method->setBody( + '$this->' . $initializerName + . ' && $this->' . $initializerName + . '->__invoke($this->' . $valueHolderName . ', $this, ' . var_export($methodName, true) + . ', array(' . implode(', ', $initializerParams) . '), $this->' . $initializerName . ");\n\n" + . 'return $this->' . $valueHolderName . '->' + . $methodName . '(' . implode(', ', $forwardedParams) . ');' + ); + $method->setDocblock('{@inheritDoc}'); + + return $method; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicClone.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicClone.php new file mode 100644 index 0000000..d62c46a --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicClone.php @@ -0,0 +1,53 @@ + + * @license MIT + */ +class MagicClone extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + PropertyGenerator $valueHolderProperty + ) { + parent::__construct($originalClass, '__clone'); + + $initializer = $initializerProperty->getName(); + $valueHolder = $valueHolderProperty->getName(); + + $this->setBody( + '$this->' . $initializer . ' && $this->' . $initializer + . '->__invoke($this->' . $valueHolder + . ', $this, \'__clone\', array(), $this->' . $initializer . ');' . "\n\n" + . '$this->' . $valueHolder . ' = clone $this->' . $valueHolder . ';' + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGet.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGet.php new file mode 100644 index 0000000..ea7fcbc --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGet.php @@ -0,0 +1,69 @@ + + * @license MIT + */ +class MagicGet extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + PropertyGenerator $valueHolderProperty, + PublicPropertiesMap $publicProperties + ) { + parent::__construct($originalClass, '__get', array(new ParameterGenerator('name'))); + + $this->setDocblock(($originalClass->hasMethod('__get') ? "{@inheritDoc}\n" : '') . '@param string $name'); + + $initializer = $initializerProperty->getName(); + $valueHolder = $valueHolderProperty->getName(); + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' return $this->' . $valueHolder . '->$name;' + . "\n}\n\n"; + + $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_GET, + 'name', + null, + $valueHolderProperty + ); + + $this->setBody( + '$this->' . $initializer . ' && $this->' . $initializer + . '->__invoke($this->' . $valueHolder . ', $this, \'__get\', array(\'name\' => $name), $this->' + . $initializer . ');' + . "\n\n" . $callParent + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicIsset.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicIsset.php new file mode 100644 index 0000000..09e4a85 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicIsset.php @@ -0,0 +1,72 @@ + + * @license MIT + */ +class MagicIsset extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + PropertyGenerator $valueHolderProperty, + PublicPropertiesMap $publicProperties + ) { + parent::__construct($originalClass, '__isset', array(new ParameterGenerator('name'))); + + $initializer = $initializerProperty->getName(); + $valueHolder = $valueHolderProperty->getName(); + $callParent = ''; + + $this->setDocblock(($originalClass->hasMethod('__isset') ? "{@inheritDoc}\n" : '') . '@param string $name'); + + if (! $publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' return isset($this->' . $valueHolder . '->$name);' + . "\n}\n\n"; + } + + $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_ISSET, + 'name', + null, + $valueHolderProperty + ); + + $this->setBody( + '$this->' . $initializer . ' && $this->' . $initializer + . '->__invoke($this->' . $valueHolder . ', $this, \'__isset\', array(\'name\' => $name), $this->' + . $initializer . ');' . "\n\n" . $callParent + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSet.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSet.php new file mode 100644 index 0000000..b797b57 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSet.php @@ -0,0 +1,79 @@ + + * @license MIT + */ +class MagicSet extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + PropertyGenerator $valueHolderProperty, + PublicPropertiesMap $publicProperties + ) { + parent::__construct( + $originalClass, + '__set', + array(new ParameterGenerator('name'), new ParameterGenerator('value')) + ); + + $initializer = $initializerProperty->getName(); + $valueHolder = $valueHolderProperty->getName(); + $callParent = ''; + + $this->setDocblock( + ($originalClass->hasMethod('__set') ? "{@inheritDoc}\n" : '') . "@param string \$name\n@param mixed \$value" + ); + + if (! $publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' return ($this->' . $valueHolder . '->$name = $value);' + . "\n}\n\n"; + } + + $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_SET, + 'name', + 'value', + $valueHolderProperty + ); + + $this->setBody( + '$this->' . $initializer . ' && $this->' . $initializer + . '->__invoke($this->' . $valueHolder . ', $this, ' + . '\'__set\', array(\'name\' => $name, \'value\' => $value), $this->' . $initializer . ');' + . "\n\n" . $callParent + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleep.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleep.php new file mode 100644 index 0000000..20051c8 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleep.php @@ -0,0 +1,53 @@ + + * @license MIT + */ +class MagicSleep extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + PropertyGenerator $valueHolderProperty + ) { + parent::__construct($originalClass, '__sleep'); + + $initializer = $initializerProperty->getName(); + $valueHolder = $valueHolderProperty->getName(); + + $this->setBody( + '$this->' . $initializer . ' && $this->' . $initializer + . '->__invoke($this->' . $valueHolder . ', $this, \'__sleep\', array(), $this->' + . $initializer . ');' . "\n\n" + . 'return array(' . var_export($valueHolder, true) . ');' + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicUnset.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicUnset.php new file mode 100644 index 0000000..7ee256e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicUnset.php @@ -0,0 +1,72 @@ + + * @license MIT + */ +class MagicUnset extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct( + ReflectionClass $originalClass, + PropertyGenerator $initializerProperty, + PropertyGenerator $valueHolderProperty, + PublicPropertiesMap $publicProperties + ) { + parent::__construct($originalClass, '__unset', array(new ParameterGenerator('name'))); + + $initializer = $initializerProperty->getName(); + $valueHolder = $valueHolderProperty->getName(); + $callParent = ''; + + $this->setDocblock(($originalClass->hasMethod('__isset') ? "{@inheritDoc}\n" : '') . '@param string $name'); + + if (! $publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" + . ' unset($this->' . $valueHolder . '->$name);' . "\n\n return;" + . "\n}\n\n"; + } + + $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_UNSET, + 'name', + null, + $valueHolderProperty + ); + + $this->setBody( + '$this->' . $initializer . ' && $this->' . $initializer + . '->__invoke($this->' . $valueHolder . ', $this, \'__unset\', array(\'name\' => $name), $this->' + . $initializer . ');' . "\n\n" . $callParent + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializer.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializer.php new file mode 100644 index 0000000..db3400f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializer.php @@ -0,0 +1,49 @@ + + * @license MIT + */ +class SetProxyInitializer extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(PropertyGenerator $initializerProperty) + { + parent::__construct('setProxyInitializer'); + + $initializerParameter = new ParameterGenerator('initializer'); + + $initializerParameter->setType('Closure'); + $initializerParameter->setDefaultValue(null); + $this->setParameter($initializerParameter); + $this->setDocblock('{@inheritDoc}'); + $this->setBody('$this->' . $initializerProperty->getName() . ' = $initializer;'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/InitializerProperty.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/InitializerProperty.php new file mode 100644 index 0000000..3173065 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/InitializerProperty.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class InitializerProperty extends PropertyGenerator +{ + /** + * Constructor + */ + public function __construct() + { + parent::__construct(UniqueIdentifierGenerator::getIdentifier('initializer')); + + $this->setVisibility(self::VISIBILITY_PRIVATE); + $this->setDocblock('@var \\Closure|null initializer responsible for generating the wrapped object'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/ValueHolderProperty.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/ValueHolderProperty.php new file mode 100644 index 0000000..7053e6d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/ValueHolderProperty.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class ValueHolderProperty extends PropertyGenerator +{ + /** + * Constructor + */ + public function __construct() + { + parent::__construct(UniqueIdentifierGenerator::getIdentifier('valueHolder')); + + $this->setVisibility(self::VISIBILITY_PRIVATE); + $this->setDocblock('@var \\Closure|null initializer responsible for generating the wrapped object'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php new file mode 100644 index 0000000..b7ded41 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php @@ -0,0 +1,111 @@ + + * @license MIT + */ +class LazyLoadingValueHolderGenerator implements ProxyGeneratorInterface +{ + /** + * {@inheritDoc} + */ + public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator) + { + $interfaces = array('ProxyManager\\Proxy\\VirtualProxyInterface'); + $publicProperties = new PublicPropertiesMap($originalClass); + + if ($originalClass->isInterface()) { + $interfaces[] = $originalClass->getName(); + } else { + $classGenerator->setExtendedClass($originalClass->getName()); + } + + $classGenerator->setImplementedInterfaces($interfaces); + $classGenerator->addPropertyFromGenerator($valueHolder = new ValueHolderProperty()); + $classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty()); + $classGenerator->addPropertyFromGenerator($publicProperties); + + foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) { + $classGenerator->addMethodFromGenerator( + LazyLoadingMethodInterceptor::generateMethod( + new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), + $initializer, + $valueHolder + ) + ); + } + + $classGenerator->addMethodFromGenerator(new Constructor($originalClass, $initializer)); + + $classGenerator->addMethodFromGenerator( + new MagicGet($originalClass, $initializer, $valueHolder, $publicProperties) + ); + $classGenerator->addMethodFromGenerator( + new MagicSet($originalClass, $initializer, $valueHolder, $publicProperties) + ); + $classGenerator->addMethodFromGenerator( + new MagicIsset($originalClass, $initializer, $valueHolder, $publicProperties) + ); + $classGenerator->addMethodFromGenerator( + new MagicUnset($originalClass, $initializer, $valueHolder, $publicProperties) + ); + $classGenerator->addMethodFromGenerator(new MagicClone($originalClass, $initializer, $valueHolder)); + $classGenerator->addMethodFromGenerator(new MagicSleep($originalClass, $initializer, $valueHolder)); + $classGenerator->addMethodFromGenerator(new MagicWakeup($originalClass)); + + $classGenerator->addMethodFromGenerator(new SetProxyInitializer($initializer)); + $classGenerator->addMethodFromGenerator(new GetProxyInitializer($initializer)); + $classGenerator->addMethodFromGenerator(new InitializeProxy($initializer, $valueHolder)); + $classGenerator->addMethodFromGenerator(new IsProxyInitialized($valueHolder)); + + $classGenerator->addMethodFromGenerator(new GetWrappedValueHolderValue($valueHolder)); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/Constructor.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/Constructor.php new file mode 100644 index 0000000..79dc165 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/Constructor.php @@ -0,0 +1,55 @@ + + * @license MIT + */ +class Constructor extends MethodGenerator +{ + /** + * Constructor + * + * @param ReflectionClass $originalClass Reflection of the class to proxy + */ + public function __construct(ReflectionClass $originalClass) + { + parent::__construct('__construct'); + + /* @var $publicProperties \ReflectionProperty[] */ + $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC); + $nullableProperties = array(); + + foreach ($publicProperties as $publicProperty) { + $nullableProperties[] = '$this->' . $publicProperty->getName() . ' = null;'; + } + + $this->setDocblock("@override constructor for null object initialization"); + if ($nullableProperties) { + $this->setBody(implode("\n", $nullableProperties)); + } + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptor.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptor.php new file mode 100644 index 0000000..2b63e50 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptor.php @@ -0,0 +1,53 @@ + + * @license MIT + */ +class NullObjectMethodInterceptor extends MethodGenerator +{ + /** + * @param \Zend\Code\Reflection\MethodReflection $originalMethod + * + * @return NullObjectMethodInterceptor|static + */ + public static function generateMethod(MethodReflection $originalMethod) + { + /* @var $method self */ + $method = static::fromReflection($originalMethod); + + if ($originalMethod->returnsReference()) { + $reference = UniqueIdentifierGenerator::getIdentifier('ref'); + + $method->setBody("\$$reference = null;\nreturn \$$reference;"); + } else { + $method->setBody(''); + } + + return $method; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php new file mode 100644 index 0000000..67f597b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php @@ -0,0 +1,69 @@ + + * @license MIT + */ +class NullObjectGenerator implements ProxyGeneratorInterface +{ + /** + * {@inheritDoc} + */ + public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator) + { + $interfaces = array('ProxyManager\\Proxy\\NullObjectInterface'); + + if ($originalClass->isInterface()) { + $interfaces[] = $originalClass->getName(); + } else { + foreach ($originalClass->getInterfaceNames() as $name) { + $interfaces[] = $name; + } + } + + $classGenerator->setImplementedInterfaces($interfaces); + + /* @var $methods \ReflectionMethod[] */ + foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) { + $classGenerator->addMethodFromGenerator( + NullObjectMethodInterceptor::generateMethod( + new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()) + ) + ); + } + + $classGenerator->addMethodFromGenerator(new Constructor($originalClass)); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/PropertyGenerator/PublicPropertiesDefaults.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/PropertyGenerator/PublicPropertiesDefaults.php new file mode 100644 index 0000000..d13d7c7 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/PropertyGenerator/PublicPropertiesDefaults.php @@ -0,0 +1,58 @@ + + * @license MIT + */ +class PublicPropertiesDefaults extends PropertyGenerator +{ + /** + * @var bool[] + */ + private $publicProperties = array(); + + /** + * @param \ReflectionClass $originalClass + */ + public function __construct(ReflectionClass $originalClass) + { + parent::__construct(UniqueIdentifierGenerator::getIdentifier('publicPropertiesDefaults')); + + $defaults = $originalClass->getDefaultProperties(); + + foreach ($originalClass->getProperties(ReflectionProperty::IS_PUBLIC) as $publicProperty) { + $name = $publicProperty->getName(); + $this->publicProperties[$name] = $defaults[$name]; + } + + $this->setDefaultValue($this->publicProperties); + $this->setVisibility(self::VISIBILITY_PRIVATE); + $this->setStatic(true); + $this->setDocblock('@var mixed[] map of default property values of the parent class'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/PropertyGenerator/PublicPropertiesMap.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/PropertyGenerator/PublicPropertiesMap.php new file mode 100644 index 0000000..8b26a7e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/PropertyGenerator/PublicPropertiesMap.php @@ -0,0 +1,63 @@ + + * @license MIT + */ +class PublicPropertiesMap extends PropertyGenerator +{ + /** + * @var bool[] + */ + private $publicProperties = array(); + + /** + * @param \ReflectionClass $originalClass + */ + public function __construct(ReflectionClass $originalClass) + { + parent::__construct(UniqueIdentifierGenerator::getIdentifier('publicProperties')); + + foreach ($originalClass->getProperties(ReflectionProperty::IS_PUBLIC) as $publicProperty) { + $this->publicProperties[$publicProperty->getName()] = true; + } + + $this->setDefaultValue($this->publicProperties); + $this->setVisibility(self::VISIBILITY_PRIVATE); + $this->setStatic(true); + $this->setDocblock('@var bool[] map of public properties of the parent class'); + } + + /** + * @return bool whether there are no public properties + */ + public function isEmpty() + { + return empty($this->publicProperties); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ProxyGeneratorInterface.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ProxyGeneratorInterface.php new file mode 100644 index 0000000..df88aa8 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ProxyGeneratorInterface.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +interface ProxyGeneratorInterface +{ + /** + * Apply modifications to the provided $classGenerator to proxy logic from $originalClass + * + * @param \ReflectionClass $originalClass + * @param \Zend\Code\Generator\ClassGenerator $classGenerator + * + * @return void + */ + public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator); +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/Constructor.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/Constructor.php new file mode 100644 index 0000000..1a3ae69 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/Constructor.php @@ -0,0 +1,63 @@ + + * @license MIT + */ +class Constructor extends MethodGenerator +{ + /** + * Constructor + * + * @param ReflectionClass $originalClass Reflection of the class to proxy + * @param PropertyGenerator $adapter Adapter property + */ + public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapter) + { + parent::__construct('__construct'); + + $adapterName = $adapter->getName(); + + $this->setParameter(new ParameterGenerator($adapterName, 'ProxyManager\Factory\RemoteObject\AdapterInterface')); + + $this->setDocblock( + '@override constructor for remote object control\n\n' + . '@param \\ProxyManager\\Factory\\RemoteObject\\AdapterInterface \$adapter' + ); + + $body = '$this->' . $adapterName . ' = $' . $adapterName . ';'; + + foreach ($originalClass->getProperties() as $property) { + if ($property->isPublic() && ! $property->isStatic()) { + $body .= "\nunset(\$this->" . $property->getName() . ');'; + } + } + + $this->setBody($body); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicGet.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicGet.php new file mode 100644 index 0000000..e321263 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicGet.php @@ -0,0 +1,49 @@ + + * @license MIT + */ +class MagicGet extends MagicMethodGenerator +{ + /** + * Constructor + * @param ReflectionClass $originalClass + * @param \Zend\Code\Generator\PropertyGenerator $adapterProperty + */ + public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapterProperty) + { + parent::__construct($originalClass, '__get', array(new ParameterGenerator('name'))); + + $this->setDocblock('@param string $name'); + $this->setBody( + '$return = $this->' . $adapterProperty->getName() . '->call(' . var_export($originalClass->getName(), true) + . ', \'__get\', array($name));' . "\n\n" . 'return $return;' + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicIsset.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicIsset.php new file mode 100644 index 0000000..cf24797 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicIsset.php @@ -0,0 +1,50 @@ + + * @license MIT + */ +class MagicIsset extends MagicMethodGenerator +{ + /** + * Constructor + * @param ReflectionClass $originalClass + * @param \Zend\Code\Generator\PropertyGenerator $adapterProperty + */ + public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapterProperty) + { + parent::__construct($originalClass, '__isset', array(new ParameterGenerator('name'))); + + $this->setDocblock('@param string $name'); + $this->setBody( + '$return = $this->' . $adapterProperty->getName() . '->call(' . var_export($originalClass->getName(), true) + . ', \'__isset\', array($name));' . "\n\n" + . 'return $return;' + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicSet.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicSet.php new file mode 100644 index 0000000..6efaaf2 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicSet.php @@ -0,0 +1,54 @@ + + * @license MIT + */ +class MagicSet extends MagicMethodGenerator +{ + /** + * Constructor + * @param ReflectionClass $originalClass + * @param \Zend\Code\Generator\PropertyGenerator $adapterProperty + */ + public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapterProperty) + { + parent::__construct( + $originalClass, + '__set', + array(new ParameterGenerator('name'), new ParameterGenerator('value')) + ); + + $this->setDocblock('@param string \$name\n@param mixed \$value'); + $this->setBody( + '$return = $this->' . $adapterProperty->getName() . '->call(' . var_export($originalClass->getName(), true) + . ', \'__set\', array($name, $value));' . "\n\n" + . 'return $return;' + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicUnset.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicUnset.php new file mode 100644 index 0000000..ffe34fb --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/MagicUnset.php @@ -0,0 +1,51 @@ + + * @license MIT + */ +class MagicUnset extends MagicMethodGenerator +{ + /** + * Constructor + * + * @param ReflectionClass $originalClass + * @param PropertyGenerator $adapterProperty + */ + public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapterProperty) + { + parent::__construct($originalClass, '__unset', array(new ParameterGenerator('name'))); + + $this->setDocblock('@param string $name'); + $this->setBody( + '$return = $this->' . $adapterProperty->getName() . '->call(' . var_export($originalClass->getName(), true) + . ', \'__unset\', array($name));' . "\n\n" + . 'return $return;' + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/RemoteObjectMethod.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/RemoteObjectMethod.php new file mode 100644 index 0000000..3d0d1de --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/RemoteObjectMethod.php @@ -0,0 +1,63 @@ + + * @license MIT + */ +class RemoteObjectMethod extends MethodGenerator +{ + /** + * @param \Zend\Code\Reflection\MethodReflection $originalMethod + * @param \Zend\Code\Generator\PropertyGenerator $adapterProperty + * @param \ReflectionClass $originalClass + * + * @return RemoteObjectMethod|static + */ + public static function generateMethod( + MethodReflection $originalMethod, + PropertyGenerator $adapterProperty, + ReflectionClass $originalClass + ) { + /* @var $method self */ + $method = static::fromReflection($originalMethod); + $parameters = $originalMethod->getParameters(); + $list = array(); + + foreach ($parameters as $parameter) { + $list[] = '$' . $parameter->getName(); + } + + $method->setBody( + '$return = $this->' . $adapterProperty->getName() . '->call(' . var_export($originalClass->getName(), true) + . ', ' . var_export($originalMethod->getName(), true) . ', array('. implode(', ', $list) .'));' . "\n\n" + . 'return $return;' + ); + + return $method; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/PropertyGenerator/AdapterProperty.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/PropertyGenerator/AdapterProperty.php new file mode 100644 index 0000000..10b3dc6 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/PropertyGenerator/AdapterProperty.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class AdapterProperty extends PropertyGenerator +{ + /** + * Constructor + */ + public function __construct() + { + parent::__construct(UniqueIdentifierGenerator::getIdentifier('adapter')); + + $this->setVisibility(self::VISIBILITY_PRIVATE); + $this->setDocblock('@var \\ProxyManager\\Factory\\RemoteObject\\AdapterInterface Remote web service adapter'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php new file mode 100644 index 0000000..d84f02f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php @@ -0,0 +1,84 @@ + + * @license MIT + */ +class RemoteObjectGenerator implements ProxyGeneratorInterface +{ + /** + * {@inheritDoc} + */ + public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator) + { + $interfaces = array('ProxyManager\\Proxy\\RemoteObjectInterface'); + + if ($originalClass->isInterface()) { + $interfaces[] = $originalClass->getName(); + } else { + $classGenerator->setExtendedClass($originalClass->getName()); + } + + $classGenerator->setImplementedInterfaces($interfaces); + $classGenerator->addPropertyFromGenerator($adapter = new AdapterProperty()); + + $methods = ProxiedMethodsFilter::getProxiedMethods( + $originalClass, + array('__get', '__set', '__isset', '__unset') + ); + + foreach ($methods as $method) { + $classGenerator->addMethodFromGenerator( + RemoteObjectMethod::generateMethod( + new MethodReflection( + $method->getDeclaringClass()->getName(), + $method->getName() + ), + $adapter, + $originalClass + ) + ); + } + + $classGenerator->addMethodFromGenerator(new Constructor($originalClass, $adapter)); + $classGenerator->addMethodFromGenerator(new MagicGet($originalClass, $adapter)); + $classGenerator->addMethodFromGenerator(new MagicSet($originalClass, $adapter)); + $classGenerator->addMethodFromGenerator(new MagicIsset($originalClass, $adapter)); + $classGenerator->addMethodFromGenerator(new MagicUnset($originalClass, $adapter)); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/ProxiedMethodsFilter.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/ProxiedMethodsFilter.php new file mode 100644 index 0000000..6024e33 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/ProxiedMethodsFilter.php @@ -0,0 +1,56 @@ + + * @license MIT + */ +class ProxiedMethodsFilter +{ + /** + * @param ReflectionClass $class reflection class from which methods should be extracted + * @param string[] $excluded methods to be ignored + * + * @return ReflectionMethod[] + */ + public static function getProxiedMethods( + ReflectionClass $class, + array $excluded = array('__get', '__set', '__isset', '__unset', '__clone', '__sleep', '__wakeup') + ) { + $ignored = array_flip(array_map('strtolower', $excluded)); + + return array_filter( + $class->getMethods(ReflectionMethod::IS_PUBLIC), + function (ReflectionMethod $method) use ($ignored) { + return ! ( + $method->isConstructor() + || isset($ignored[strtolower($method->getName())]) + || $method->isFinal() + || $method->isStatic() + ); + } + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/PublicScopeSimulator.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/PublicScopeSimulator.php new file mode 100644 index 0000000..571767c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/PublicScopeSimulator.php @@ -0,0 +1,190 @@ + + * @license MIT + */ +class PublicScopeSimulator +{ + const OPERATION_SET = 'set'; + const OPERATION_GET = 'get'; + const OPERATION_ISSET = 'isset'; + const OPERATION_UNSET = 'unset'; + + /** + * Generates code for simulating access to a property from the scope that is accessing a proxy. + * This is done by introspecting `debug_backtrace()` and then binding a closure to the scope + * of the parent caller. + * + * @param string $operationType operation to execute: one of 'get', 'set', 'isset' or 'unset' + * @param string $nameParameter name of the `name` parameter of the magic method + * @param string|null $valueParameter name of the `value` parameter of the magic method + * @param PropertyGenerator $valueHolder name of the property containing the target object from which + * to read the property. `$this` if none provided + * @param string|null $returnPropertyName name of the property to which we want to assign the result of + * the operation. Return directly if none provided + * + * @return string + * + * @throws \InvalidArgumentException + */ + public static function getPublicAccessSimulationCode( + $operationType, + $nameParameter, + $valueParameter = null, + PropertyGenerator $valueHolder = null, + $returnPropertyName = null + ) { + $byRef = self::getByRefReturnValue($operationType); + $value = static::OPERATION_SET === $operationType ? ', $value' : ''; + $target = '$this'; + + if ($valueHolder) { + $target = '$this->' . $valueHolder->getName(); + } + + return '$realInstanceReflection = new \\ReflectionClass(get_parent_class($this));' . "\n\n" + . 'if (! $realInstanceReflection->hasProperty($' . $nameParameter . ')) {' . "\n" + . ' $targetObject = ' . $target . ';' . "\n\n" + . self::getUndefinedPropertyNotice($operationType, $nameParameter) + . ' ' . self::getOperation($operationType, $nameParameter, $valueParameter) . ";\n" + . " return;\n" + . '}' . "\n\n" + . '$targetObject = ' . self::getTargetObject($valueHolder) . ";\n" + . '$accessor = function ' . $byRef . '() use ($targetObject, $name' . $value . ') {' . "\n" + . ' ' . self::getOperation($operationType, $nameParameter, $valueParameter) . "\n" + . "};\n" + . self::getScopeReBind() + . ( + $returnPropertyName + ? '$' . $returnPropertyName . ' = ' . $byRef . '$accessor();' + : '$returnValue = ' . $byRef . '$accessor();' . "\n\n" . 'return $returnValue;' + ); + } + + /** + * This will generate code that triggers a notice if access is attempted on a non-existing property + * + * @param string $operationType + * @param string $nameParameter + * + * @return string + */ + private static function getUndefinedPropertyNotice($operationType, $nameParameter) + { + if (static::OPERATION_GET !== $operationType) { + return ''; + } + + // + return ' $backtrace = debug_backtrace(false);' . "\n" + . ' trigger_error(\'Undefined property: \' . get_parent_class($this) . \'::$\' . $' + . $nameParameter + . ' . \' in \' . $backtrace[0][\'file\'] . \' on line \' . $backtrace[0][\'line\'], \E_USER_NOTICE);' + . "\n"; + } + + /** + * Defines whether the given operation produces a reference. + * + * Note: if the object is a wrapper, the wrapped instance is accessed directly. If the object + * is a ghost or the proxy has no wrapper, then an instance of the parent class is created via + * on-the-fly unserialization + * + * @param string $operationType + * + * @return string + */ + private static function getByRefReturnValue($operationType) + { + return (static::OPERATION_GET === $operationType || static::OPERATION_SET === $operationType) ? '& ' : ''; + } + + /** + * Retrieves the logic to fetch the object on which access should be attempted + * + * @param PropertyGenerator $valueHolder + * + * @return string + */ + private static function getTargetObject(PropertyGenerator $valueHolder = null) + { + if ($valueHolder) { + return '$this->' . $valueHolder->getName(); + } + + return 'unserialize(sprintf(\'O:%d:"%s":0:{}\', strlen(get_parent_class($this)), get_parent_class($this)))'; + } + + /** + * @param string $operationType + * @param string $nameParameter + * @param string|null $valueParameter + * + * @return string + * + * @throws \InvalidArgumentException + */ + private static function getOperation($operationType, $nameParameter, $valueParameter) + { + switch ($operationType) { + case static::OPERATION_GET: + return 'return $targetObject->$' . $nameParameter . ";"; + case static::OPERATION_SET: + if (! $valueParameter) { + throw new \InvalidArgumentException('Parameter $valueParameter not provided'); + } + + return 'return $targetObject->$' . $nameParameter . ' = $' . $valueParameter . ';'; + case static::OPERATION_ISSET: + return 'return isset($targetObject->$' . $nameParameter . ');'; + case static::OPERATION_UNSET: + return 'unset($targetObject->$' . $nameParameter . ');'; + } + + throw new \InvalidArgumentException(sprintf('Invalid operation "%s" provided', $operationType)); + } + + /** + * Generates code to bind operations to the parent scope if supported by the current PHP version + * + * @return string + */ + private static function getScopeReBind() + { + if (PHP_VERSION_ID < 50400) { + // @codeCoverageIgnoreStart + return ''; + // @codeCoverageIgnoreEnd + } + + return ' $backtrace = debug_backtrace(true);' . "\n" + . ' $scopeObject = isset($backtrace[1][\'object\'])' + . ' ? $backtrace[1][\'object\'] : new \stdClass();' . "\n" + . ' $accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));' . "\n"; + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/GetWrappedValueHolderValue.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/GetWrappedValueHolderValue.php new file mode 100644 index 0000000..7db81d3 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/GetWrappedValueHolderValue.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class GetWrappedValueHolderValue extends MethodGenerator +{ + /** + * Constructor + */ + public function __construct(PropertyGenerator $valueHolderProperty) + { + parent::__construct('getWrappedValueHolderValue'); + $this->setDocblock('{@inheritDoc}'); + $this->setBody('return $this->' . $valueHolderProperty->getName() . ';'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/MagicSleep.php b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/MagicSleep.php new file mode 100644 index 0000000..17aa0fd --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ValueHolder/MethodGenerator/MagicSleep.php @@ -0,0 +1,42 @@ + + * @license MIT + */ +class MagicSleep extends MagicMethodGenerator +{ + /** + * Constructor + */ + public function __construct(ReflectionClass $originalClass, PropertyGenerator $valueHolderProperty) + { + parent::__construct($originalClass, '__sleep'); + + $this->setBody('return array(' . var_export($valueHolderProperty->getName(), true) . ');'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/Bootstrap.php b/core/vendor/ocramius/proxy-manager/tests/Bootstrap.php new file mode 100644 index 0000000..9f84dcd --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/Bootstrap.php @@ -0,0 +1,39 @@ +add('ProxyManagerTest\\', __DIR__); +$loader->add('ProxyManagerTestAsset\\', __DIR__); + +unset($files, $file, $loader); diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Autoloader/AutoloaderTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Autoloader/AutoloaderTest.php new file mode 100644 index 0000000..0a662c2 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Autoloader/AutoloaderTest.php @@ -0,0 +1,130 @@ + + * @license MIT + */ +class AutoloaderTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \ProxyManager\Autoloader\Autoloader + */ + protected $autoloader; + + /** + * @var \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $fileLocator; + + /** + * @var \ProxyManager\Inflector\ClassNameInflectorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $classNameInflector; + + /** + * @covers \ProxyManager\Autoloader\Autoloader::__construct + */ + public function setUp() + { + $this->fileLocator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface'); + $this->classNameInflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface'); + $this->autoloader = new Autoloader($this->fileLocator, $this->classNameInflector); + } + + /** + * @covers \ProxyManager\Autoloader\Autoloader::__invoke + */ + public function testWillNotAutoloadUserClasses() + { + $className = 'Foo\\' . UniqueIdentifierGenerator::getIdentifier('Bar'); + $this + ->classNameInflector + ->expects($this->once()) + ->method('isProxyClassName') + ->with($className) + ->will($this->returnValue(false)); + + $this->assertFalse($this->autoloader->__invoke($className)); + } + + /** + * @covers \ProxyManager\Autoloader\Autoloader::__invoke + */ + public function testWillNotAutoloadNonExistingClass() + { + $className = 'Foo\\' . UniqueIdentifierGenerator::getIdentifier('Bar'); + $this + ->classNameInflector + ->expects($this->once()) + ->method('isProxyClassName') + ->with($className) + ->will($this->returnValue(true)); + $this + ->fileLocator + ->expects($this->once()) + ->method('getProxyFileName') + ->will($this->returnValue(__DIR__ . '/non-existing')); + + $this->assertFalse($this->autoloader->__invoke($className)); + } + + /** + * @covers \ProxyManager\Autoloader\Autoloader::__invoke + */ + public function testWillNotAutoloadExistingClass() + { + $this->assertFalse($this->autoloader->__invoke(__CLASS__)); + } + + /** + * @covers \ProxyManager\Autoloader\Autoloader::__invoke + */ + public function testWillAutoloadExistingFile() + { + $namespace = 'Foo'; + $className = UniqueIdentifierGenerator::getIdentifier('Bar'); + $fqcn = $namespace . '\\' . $className; + $fileName = sys_get_temp_dir() . '/foo_' . uniqid() . '.php'; + + file_put_contents($fileName, 'classNameInflector + ->expects($this->once()) + ->method('isProxyClassName') + ->with($fqcn) + ->will($this->returnValue(true)); + $this + ->fileLocator + ->expects($this->once()) + ->method('getProxyFileName') + ->will($this->returnValue($fileName)); + + $this->assertTrue($this->autoloader->__invoke($fqcn)); + $this->assertTrue(class_exists($fqcn, false)); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ConfigurationTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ConfigurationTest.php new file mode 100644 index 0000000..3435463 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ConfigurationTest.php @@ -0,0 +1,124 @@ + + * @license MIT + */ +class ConfigurationTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \ProxyManager\Configuration + */ + protected $configuration; + + /** + * {@inheritDoc} + */ + public function setUp() + { + $this->configuration = new Configuration(); + } + + /** + * @covers \ProxyManager\Configuration::getProxiesNamespace + * @covers \ProxyManager\Configuration::setProxiesNamespace + */ + public function testGetSetProxiesNamespace() + { + $this->assertSame( + 'ProxyManagerGeneratedProxy', + $this->configuration->getProxiesNamespace(), + 'Default setting check for BC' + ); + + $this->configuration->setProxiesNamespace('foo'); + $this->assertSame('foo', $this->configuration->getProxiesNamespace()); + } + + /** + * @covers \ProxyManager\Configuration::getClassNameInflector + * @covers \ProxyManager\Configuration::setClassNameInflector + */ + public function testSetGetClassNameInflector() + { + $this->assertInstanceOf( + 'ProxyManager\\Inflector\\ClassNameInflectorInterface', + $this->configuration->getClassNameInflector() + ); + + $inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface'); + + $this->configuration->setClassNameInflector($inflector); + $this->assertSame($inflector, $this->configuration->getClassNameInflector()); + } + + /** + * @covers \ProxyManager\Configuration::getGeneratorStrategy + * @covers \ProxyManager\Configuration::setGeneratorStrategy + */ + public function testSetGetGeneratorStrategy() + { + + $this->assertInstanceOf( + 'ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface', + $this->configuration->getGeneratorStrategy() + ); + + $strategy = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface'); + + $this->configuration->setGeneratorStrategy($strategy); + $this->assertSame($strategy, $this->configuration->getGeneratorStrategy()); + } + + /** + * @covers \ProxyManager\Configuration::getProxiesTargetDir + * @covers \ProxyManager\Configuration::setProxiesTargetDir + */ + public function testSetGetProxiesTargetDir() + { + $this->assertTrue(is_dir($this->configuration->getProxiesTargetDir())); + + $this->configuration->setProxiesTargetDir(__DIR__); + $this->assertSame(__DIR__, $this->configuration->getProxiesTargetDir()); + } + + /** + * @covers \ProxyManager\Configuration::getProxyAutoloader + * @covers \ProxyManager\Configuration::setProxyAutoloader + */ + public function testSetGetProxyAutoloader() + { + $this->assertInstanceOf( + 'ProxyManager\\Autoloader\\AutoloaderInterface', + $this->configuration->getProxyAutoloader() + ); + + $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface'); + + $this->configuration->setProxyAutoloader($autoloader); + $this->assertSame($autoloader, $this->configuration->getProxyAutoloader()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/DisabledMethodExceptionTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/DisabledMethodExceptionTest.php new file mode 100644 index 0000000..57cae41 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/DisabledMethodExceptionTest.php @@ -0,0 +1,41 @@ + + * @license MIT + */ +class DisabledMethodExceptionTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\Exception\DisabledMethodException::disabledMethod + */ + public function testProxyDirectoryNotFound() + { + $exception = DisabledMethodException::disabledMethod('foo::bar'); + + $this->assertSame('Method "foo::bar" is forcefully disabled', $exception->getMessage()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/InvalidProxiedClassExceptionTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/InvalidProxiedClassExceptionTest.php new file mode 100644 index 0000000..b7b63c9 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/InvalidProxiedClassExceptionTest.php @@ -0,0 +1,45 @@ + + * @license MIT + */ +class InvalidProxiedClassExceptionTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\Exception\InvalidProxiedClassException::interfaceNotSupported + */ + public function testInterfaceNotSupported() + { + $this->assertSame( + 'Provided interface "ProxyManagerTestAsset\BaseInterface" cannot be proxied', + InvalidProxiedClassException::interfaceNotSupported( + new ReflectionClass('ProxyManagerTestAsset\BaseInterface') + )->getMessage() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/InvalidProxyDirectoryExceptionTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/InvalidProxyDirectoryExceptionTest.php new file mode 100644 index 0000000..c80ff7e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/InvalidProxyDirectoryExceptionTest.php @@ -0,0 +1,41 @@ + + * @license MIT + */ +class InvalidProxyDirectoryExceptionTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\Exception\InvalidProxyDirectoryException::proxyDirectoryNotFound + */ + public function testProxyDirectoryNotFound() + { + $exception = InvalidProxyDirectoryException::proxyDirectoryNotFound('foo/bar'); + + $this->assertSame('Provided directory "foo/bar" does not exist', $exception->getMessage()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/UnsupportedProxiedClassExceptionTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/UnsupportedProxiedClassExceptionTest.php new file mode 100644 index 0000000..7370c7f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Exception/UnsupportedProxiedClassExceptionTest.php @@ -0,0 +1,46 @@ + + * @license MIT + */ +class UnsupportedProxiedClassExceptionTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\Exception\UnsupportedProxiedClassException::unsupportedLocalizedReflectionProperty + */ + public function testUnsupportedLocalizedReflectionProperty() + { + $this->assertSame( + 'Provided reflection property "property0" of class "ProxyManagerTestAsset\ClassWithPrivateProperties" ' + . 'is private and cannot be localized in PHP 5.3', + UnsupportedProxiedClassException::unsupportedLocalizedReflectionProperty( + new ReflectionProperty('ProxyManagerTestAsset\ClassWithPrivateProperties', 'property0') + )->getMessage() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/AbstractBaseFactoryTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/AbstractBaseFactoryTest.php new file mode 100644 index 0000000..e33f41b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/AbstractBaseFactoryTest.php @@ -0,0 +1,132 @@ + + * @license MIT + * + * @covers \ProxyManager\Factory\AbstractBaseFactory + */ +class AbstractBaseFactoryTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \ProxyManager\Factory\AbstractBaseFactory + */ + private $factory; + + /** + * @var \ProxyManager\ProxyGenerator\ProxyGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $generator; + + /** + * @var \ProxyManager\Inflector\ClassNameInflectorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $classNameInflector; + + /** + * @var \ProxyManager\GeneratorStrategy\GeneratorStrategyInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $generatorStrategy; + + /** + * @var \ProxyManager\Autoloader\AutoloaderInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $proxyAutoloader; + + /** + * {@inheritDoc} + */ + public function setUp() + { + $configuration = $this->getMock('ProxyManager\\Configuration'); + $this->generator = $this->getMock('ProxyManager\\ProxyGenerator\\ProxyGeneratorInterface'); + $this->classNameInflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface'); + $this->generatorStrategy = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface'); + $this->proxyAutoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface'); + + $configuration + ->expects($this->any()) + ->method('getClassNameInflector') + ->will($this->returnValue($this->classNameInflector)); + + $configuration + ->expects($this->any()) + ->method('getGeneratorStrategy') + ->will($this->returnValue($this->generatorStrategy)); + + $configuration + ->expects($this->any()) + ->method('getProxyAutoloader') + ->will($this->returnValue($this->proxyAutoloader)); + + $this + ->classNameInflector + ->expects($this->any()) + ->method('getUserClassName') + ->will($this->returnValue('stdClass')); + + $this->factory = $this->getMockForAbstractClass( + 'ProxyManager\\Factory\\AbstractBaseFactory', + array($configuration) + ); + + $this->factory->expects($this->any())->method('getGenerator')->will($this->returnValue($this->generator)); + } + + public function testGeneratesClass() + { + $generateProxy = new ReflectionMethod($this->factory, 'generateProxy'); + + $generateProxy->setAccessible(true); + $generatedClass = UniqueIdentifierGenerator::getIdentifier('fooBar'); + + $this + ->classNameInflector + ->expects($this->any()) + ->method('getProxyClassName') + ->with('stdClass') + ->will($this->returnValue($generatedClass)); + + $this + ->generatorStrategy + ->expects($this->once()) + ->method('generate') + ->with($this->isInstanceOf('Zend\\Code\\Generator\\ClassGenerator')); + $this + ->proxyAutoloader + ->expects($this->once()) + ->method('__invoke') + ->with($generatedClass) + ->will($this->returnCallback(function ($className) { + eval('class ' . $className . ' {}'); + })); + + $this->assertSame($generatedClass, $generateProxy->invoke($this->factory, 'stdClass')); + $this->assertTrue(class_exists($generatedClass, false)); + $this->assertSame($generatedClass, $generateProxy->invoke($this->factory, 'stdClass')); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/AccessInterceptorScopeLocalizerFactoryTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/AccessInterceptorScopeLocalizerFactoryTest.php new file mode 100644 index 0000000..61f83a4 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/AccessInterceptorScopeLocalizerFactoryTest.php @@ -0,0 +1,169 @@ + + * @license MIT + */ +class AccessInterceptorScopeLocalizerFactoryTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $inflector; + + /** + * @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject + */ + protected $config; + + /** + * {@inheritDoc} + */ + public function setUp() + { + $this->config = $this->getMock('ProxyManager\\Configuration'); + $this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface'); + $this + ->config + ->expects($this->any()) + ->method('getClassNameInflector') + ->will($this->returnValue($this->inflector)); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::__construct + */ + public function testWithOptionalFactory() + { + $factory = new AccessInterceptorValueHolderFactory(); + $this->assertAttributeNotEmpty('configuration', $factory); + $this->assertAttributeInstanceOf('ProxyManager\Configuration', 'configuration', $factory); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::__construct + * @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::createProxy + * @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::getGenerator + */ + public function testWillSkipAutoGeneration() + { + $instance = new stdClass(); + + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with('stdClass') + ->will($this->returnValue('ProxyManagerTestAsset\\AccessInterceptorValueHolderMock')); + + $factory = new AccessInterceptorScopeLocalizerFactory($this->config); + /* @var $proxy \ProxyManagerTestAsset\AccessInterceptorValueHolderMock */ + $proxy = $factory->createProxy($instance, array('foo'), array('bar')); + + $this->assertInstanceOf('ProxyManagerTestAsset\\AccessInterceptorValueHolderMock', $proxy); + $this->assertSame($instance, $proxy->instance); + $this->assertSame(array('foo'), $proxy->prefixInterceptors); + $this->assertSame(array('bar'), $proxy->suffixInterceptors); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::__construct + * @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::createProxy + * @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::getGenerator + * + * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful + */ + public function testWillTryAutoGeneration() + { + $instance = new stdClass(); + $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar'); + $generator = $this->getMock('ProxyManager\GeneratorStrategy\\GeneratorStrategyInterface'); + $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface'); + + $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator)); + $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader)); + + $generator + ->expects($this->once()) + ->method('generate') + ->with( + $this->callback( + function (ClassGenerator $targetClass) use ($proxyClassName) { + return $targetClass->getName() === $proxyClassName; + } + ) + ); + + // simulate autoloading + $autoloader + ->expects($this->once()) + ->method('__invoke') + ->with($proxyClassName) + ->will( + $this->returnCallback( + function () use ($proxyClassName) { + eval( + 'class ' . $proxyClassName + . ' extends \\ProxyManagerTestAsset\\AccessInterceptorValueHolderMock {}' + ); + } + ) + ); + + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with('stdClass') + ->will($this->returnValue($proxyClassName)); + + $this + ->inflector + ->expects($this->once()) + ->method('getUserClassName') + ->with('stdClass') + ->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock')); + + $factory = new AccessInterceptorScopeLocalizerFactory($this->config); + /* @var $proxy \ProxyManagerTestAsset\AccessInterceptorValueHolderMock */ + $proxy = $factory->createProxy($instance, array('foo'), array('bar')); + + $this->assertInstanceOf($proxyClassName, $proxy); + $this->assertSame($instance, $proxy->instance); + $this->assertSame(array('foo'), $proxy->prefixInterceptors); + $this->assertSame(array('bar'), $proxy->suffixInterceptors); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/AccessInterceptorValueHolderFactoryTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/AccessInterceptorValueHolderFactoryTest.php new file mode 100644 index 0000000..e3995a0 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/AccessInterceptorValueHolderFactoryTest.php @@ -0,0 +1,168 @@ + + * @license MIT + */ +class AccessInterceptorValueHolderFactoryTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $inflector; + + /** + * @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject + */ + protected $config; + + /** + * {@inheritDoc} + */ + public function setUp() + { + $this->config = $this->getMock('ProxyManager\\Configuration'); + $this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface'); + $this + ->config + ->expects($this->any()) + ->method('getClassNameInflector') + ->will($this->returnValue($this->inflector)); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::__construct + */ + public function testWithOptionalFactory() + { + $factory = new AccessInterceptorValueHolderFactory(); + $this->assertAttributeNotEmpty('configuration', $factory); + $this->assertAttributeInstanceOf('ProxyManager\Configuration', 'configuration', $factory); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::__construct + * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::createProxy + * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::getGenerator + */ + public function testWillSkipAutoGeneration() + { + $instance = new stdClass(); + + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with('stdClass') + ->will($this->returnValue('ProxyManagerTestAsset\\AccessInterceptorValueHolderMock')); + + $factory = new AccessInterceptorValueHolderFactory($this->config); + /* @var $proxy \ProxyManagerTestAsset\AccessInterceptorValueHolderMock */ + $proxy = $factory->createProxy($instance, array('foo'), array('bar')); + + $this->assertInstanceOf('ProxyManagerTestAsset\\AccessInterceptorValueHolderMock', $proxy); + $this->assertSame($instance, $proxy->instance); + $this->assertSame(array('foo'), $proxy->prefixInterceptors); + $this->assertSame(array('bar'), $proxy->suffixInterceptors); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::__construct + * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::createProxy + * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::getGenerator + * + * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful + */ + public function testWillTryAutoGeneration() + { + $instance = new stdClass(); + $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar'); + $generator = $this->getMock('ProxyManager\GeneratorStrategy\\GeneratorStrategyInterface'); + $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface'); + + $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator)); + $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader)); + + $generator + ->expects($this->once()) + ->method('generate') + ->with( + $this->callback( + function (ClassGenerator $targetClass) use ($proxyClassName) { + return $targetClass->getName() === $proxyClassName; + } + ) + ); + + // simulate autoloading + $autoloader + ->expects($this->once()) + ->method('__invoke') + ->with($proxyClassName) + ->will( + $this->returnCallback( + function () use ($proxyClassName) { + eval( + 'class ' . $proxyClassName + . ' extends \\ProxyManagerTestAsset\\AccessInterceptorValueHolderMock {}' + ); + } + ) + ); + + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with('stdClass') + ->will($this->returnValue($proxyClassName)); + + $this + ->inflector + ->expects($this->once()) + ->method('getUserClassName') + ->with('stdClass') + ->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock')); + + $factory = new AccessInterceptorValueHolderFactory($this->config); + /* @var $proxy \ProxyManagerTestAsset\AccessInterceptorValueHolderMock */ + $proxy = $factory->createProxy($instance, array('foo'), array('bar')); + + $this->assertInstanceOf($proxyClassName, $proxy); + $this->assertSame($instance, $proxy->instance); + $this->assertSame(array('foo'), $proxy->prefixInterceptors); + $this->assertSame(array('bar'), $proxy->suffixInterceptors); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/LazyLoadingGhostFactoryTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/LazyLoadingGhostFactoryTest.php new file mode 100644 index 0000000..9a7d376 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/LazyLoadingGhostFactoryTest.php @@ -0,0 +1,163 @@ + + * @license MIT + */ +class LazyLoadingGhostFactoryTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $inflector; + + /** + * @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject + */ + protected $config; + + /** + * {@inheritDoc} + */ + public function setUp() + { + $this->config = $this->getMock('ProxyManager\\Configuration'); + $this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface'); + $this + ->config + ->expects($this->any()) + ->method('getClassNameInflector') + ->will($this->returnValue($this->inflector)); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct + */ + public function testWithOptionalFactory() + { + $factory = new LazyLoadingGhostFactory(); + $this->assertAttributeNotEmpty('configuration', $factory); + $this->assertAttributeInstanceOf('ProxyManager\Configuration', 'configuration', $factory); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct + * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::createProxy + */ + public function testWillSkipAutoGeneration() + { + $className = UniqueIdentifierGenerator::getIdentifier('foo'); + + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with($className) + ->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock')); + + $factory = new LazyLoadingGhostFactory($this->config); + $initializer = function () { + }; + /* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */ + $proxy = $factory->createProxy($className, $initializer); + + $this->assertInstanceOf('ProxyManagerTestAsset\\LazyLoadingMock', $proxy); + $this->assertSame($initializer, $proxy->initializer); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct + * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::createProxy + * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::getGenerator + * + * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful + */ + public function testWillTryAutoGeneration() + { + $className = UniqueIdentifierGenerator::getIdentifier('foo'); + $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar'); + $generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface'); + $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface'); + + $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator)); + $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader)); + + $generator + ->expects($this->once()) + ->method('generate') + ->with( + $this->callback( + function (ClassGenerator $targetClass) use ($proxyClassName) { + return $targetClass->getName() === $proxyClassName; + } + ) + ); + + // simulate autoloading + $autoloader + ->expects($this->once()) + ->method('__invoke') + ->with($proxyClassName) + ->will( + $this->returnCallback( + function () use ($proxyClassName) { + eval('class ' . $proxyClassName . ' extends \\ProxyManagerTestAsset\\LazyLoadingMock {}'); + } + ) + ); + + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with($className) + ->will($this->returnValue($proxyClassName)); + + $this + ->inflector + ->expects($this->once()) + ->method('getUserClassName') + ->with($className) + ->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock')); + + $factory = new LazyLoadingGhostFactory($this->config); + $initializer = function () { + }; + /* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */ + $proxy = $factory->createProxy($className, $initializer); + + $this->assertInstanceOf($proxyClassName, $proxy); + $this->assertSame($initializer, $proxy->initializer); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/LazyLoadingValueHolderFactoryTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/LazyLoadingValueHolderFactoryTest.php new file mode 100644 index 0000000..c9da451 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/LazyLoadingValueHolderFactoryTest.php @@ -0,0 +1,163 @@ + + * @license MIT + */ +class LazyLoadingValueHolderFactoryTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $inflector; + + /** + * @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject + */ + protected $config; + + /** + * {@inheritDoc} + */ + public function setUp() + { + $this->config = $this->getMock('ProxyManager\\Configuration'); + $this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface'); + $this + ->config + ->expects($this->any()) + ->method('getClassNameInflector') + ->will($this->returnValue($this->inflector)); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::__construct + */ + public function testWithOptionalFactory() + { + $factory = new LazyLoadingValueHolderFactory(); + $this->assertAttributeNotEmpty('configuration', $factory); + $this->assertAttributeInstanceOf('ProxyManager\Configuration', 'configuration', $factory); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::__construct + * @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::createProxy + */ + public function testWillSkipAutoGeneration() + { + $className = UniqueIdentifierGenerator::getIdentifier('foo'); + + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with($className) + ->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock')); + + $factory = new LazyLoadingValueHolderFactory($this->config); + $initializer = function () { + }; + /* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */ + $proxy = $factory->createProxy($className, $initializer); + + $this->assertInstanceOf('ProxyManagerTestAsset\\LazyLoadingMock', $proxy); + $this->assertSame($initializer, $proxy->initializer); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::__construct + * @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::createProxy + * @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::getGenerator + * + * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful + */ + public function testWillTryAutoGeneration() + { + $className = UniqueIdentifierGenerator::getIdentifier('foo'); + $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar'); + $generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface'); + $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface'); + + $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator)); + $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader)); + + $generator + ->expects($this->once()) + ->method('generate') + ->with( + $this->callback( + function (ClassGenerator $targetClass) use ($proxyClassName) { + return $targetClass->getName() === $proxyClassName; + } + ) + ); + + // simulate autoloading + $autoloader + ->expects($this->once()) + ->method('__invoke') + ->with($proxyClassName) + ->will( + $this->returnCallback( + function () use ($proxyClassName) { + eval('class ' . $proxyClassName . ' extends \\ProxyManagerTestAsset\\LazyLoadingMock {}'); + } + ) + ); + + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with($className) + ->will($this->returnValue($proxyClassName)); + + $this + ->inflector + ->expects($this->once()) + ->method('getUserClassName') + ->with($className) + ->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock')); + + $factory = new LazyLoadingValueHolderFactory($this->config); + $initializer = function () { + }; + /* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */ + $proxy = $factory->createProxy($className, $initializer); + + $this->assertInstanceOf($proxyClassName, $proxy); + $this->assertSame($initializer, $proxy->initializer); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/NullObjectFactoryTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/NullObjectFactoryTest.php new file mode 100644 index 0000000..7fa6b2b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/NullObjectFactoryTest.php @@ -0,0 +1,150 @@ + + * @license MIT + */ +class NullObjectFactoryTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $inflector; + + /** + * @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject + */ + protected $config; + + /** + * {@inheritDoc} + */ + public function setUp() + { + $this->config = $this->getMock('ProxyManager\\Configuration'); + $this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface'); + $this + ->config + ->expects($this->any()) + ->method('getClassNameInflector') + ->will($this->returnValue($this->inflector)); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\NullObjectFactory::__construct + * @covers \ProxyManager\Factory\NullObjectFactory::createProxy + * @covers \ProxyManager\Factory\NullObjectFactory::getGenerator + */ + public function testWillSkipAutoGeneration() + { + $instance = new stdClass(); + + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with('stdClass') + ->will($this->returnValue('ProxyManagerTestAsset\\NullObjectMock')); + + $factory = new NullObjectFactory($this->config); + /* @var $proxy \ProxyManagerTestAsset\NullObjectMock */ + $proxy = $factory->createProxy($instance); + + $this->assertInstanceOf('ProxyManagerTestAsset\\NullObjectMock', $proxy); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\NullObjectFactory::__construct + * @covers \ProxyManager\Factory\NullObjectFactory::createProxy + * @covers \ProxyManager\Factory\NullObjectFactory::getGenerator + * + * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful + */ + public function testWillTryAutoGeneration() + { + $instance = new stdClass(); + $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar'); + $generator = $this->getMock('ProxyManager\GeneratorStrategy\\GeneratorStrategyInterface'); + $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface'); + + $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator)); + $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader)); + + $generator + ->expects($this->once()) + ->method('generate') + ->with( + $this->callback( + function (ClassGenerator $targetClass) use ($proxyClassName) { + return $targetClass->getName() === $proxyClassName; + } + ) + ); + + // simulate autoloading + $autoloader + ->expects($this->once()) + ->method('__invoke') + ->with($proxyClassName) + ->will( + $this->returnCallback( + function () use ($proxyClassName) { + eval( + 'class ' . $proxyClassName + . ' extends \\ProxyManagerTestAsset\\NullObjectMock {}' + ); + } + ) + ); + + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with('stdClass') + ->will($this->returnValue($proxyClassName)); + + $this + ->inflector + ->expects($this->once()) + ->method('getUserClassName') + ->with('stdClass') + ->will($this->returnValue('ProxyManagerTestAsset\\NullObjectMock')); + + $factory = new NullObjectFactory($this->config); + /* @var $proxy \ProxyManagerTestAsset\NullObjectMock */ + $proxy = $factory->createProxy($instance); + + $this->assertInstanceOf($proxyClassName, $proxy); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/BaseAdapterTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/BaseAdapterTest.php new file mode 100644 index 0000000..cb7f1e7 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/BaseAdapterTest.php @@ -0,0 +1,99 @@ + + * @license MIT + */ +class BaseAdapterTest extends PHPUnit_Framework_TestCase +{ + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\RemoteObject\Adapter\BaseAdapter::__construct + * @covers \ProxyManager\Factory\RemoteObject\Adapter\BaseAdapter::call + * @covers \ProxyManager\Factory\RemoteObject\Adapter\Soap::getServiceName + */ + public function testBaseAdapter() + { + $client = $this + ->getMockBuilder('Zend\Server\Client') + ->setMethods(array('call')) + ->getMock(); + + $adapter = $this->getMockForAbstractClass( + 'ProxyManager\\Factory\\RemoteObject\\Adapter\\BaseAdapter', + array($client) + ); + + $client + ->expects($this->once()) + ->method('call') + ->with('foobarbaz', array('tab' => 'taz')) + ->will($this->returnValue('baz')); + + $adapter + ->expects($this->once()) + ->method('getServiceName') + ->with('foo', 'bar') + ->will($this->returnValue('foobarbaz')); + + $this->assertSame('baz', $adapter->call('foo', 'bar', array('tab' => 'taz'))); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\RemoteObject\Adapter\BaseAdapter::__construct + * @covers \ProxyManager\Factory\RemoteObject\Adapter\BaseAdapter::call + * @covers \ProxyManager\Factory\RemoteObject\Adapter\Soap::getServiceName + */ + public function testBaseAdapterWithServiceMap() + { + $client = $this + ->getMockBuilder('Zend\Server\Client') + ->setMethods(array('call')) + ->getMock(); + + $adapter = $this->getMockForAbstractClass( + 'ProxyManager\\Factory\\RemoteObject\\Adapter\\BaseAdapter', + array($client, array('foobarbaz' => 'mapped')) + ); + + $client + ->expects($this->once()) + ->method('call') + ->with('mapped', array('tab' => 'taz')) + ->will($this->returnValue('baz')); + + $adapter + ->expects($this->once()) + ->method('getServiceName') + ->with('foo', 'bar') + ->will($this->returnValue('foobarbaz')); + + $this->assertSame('baz', $adapter->call('foo', 'bar', array('tab' => 'taz'))); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/JsonRpcTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/JsonRpcTest.php new file mode 100644 index 0000000..d2dd028 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/JsonRpcTest.php @@ -0,0 +1,55 @@ + + * @license MIT + */ +class JsonRpcTest extends PHPUnit_Framework_TestCase +{ + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\RemoteObject\Adapter\JsonRpc::__construct + * @covers \ProxyManager\Factory\RemoteObject\Adapter\JsonRpc::getServiceName + */ + public function testCanBuildAdapterWithJsonRpcClient() + { + $client = $this + ->getMockBuilder('Zend\Server\Client') + ->setMethods(array('call')) + ->getMock(); + + $adapter = new JsonRpc($client); + + $client + ->expects($this->once()) + ->method('call') + ->with('foo.bar', array('tab' => 'taz')) + ->will($this->returnValue('baz')); + + $this->assertSame('baz', $adapter->call('foo', 'bar', array('tab' => 'taz'))); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/SoapTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/SoapTest.php new file mode 100644 index 0000000..6dae8b7 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/SoapTest.php @@ -0,0 +1,55 @@ + + * @license MIT + */ +class SoapTest extends PHPUnit_Framework_TestCase +{ + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\RemoteObject\Adapter\Soap::__construct + * @covers \ProxyManager\Factory\RemoteObject\Adapter\Soap::getServiceName + */ + public function testCanBuildAdapterWithSoapRpcClient() + { + $client = $this + ->getMockBuilder('Zend\Server\Client') + ->setMethods(array('call')) + ->getMock(); + + $adapter = new Soap($client); + + $client + ->expects($this->once()) + ->method('call') + ->with('bar', array('tab' => 'taz')) + ->will($this->returnValue('baz')); + + $this->assertSame('baz', $adapter->call('foo', 'bar', array('tab' => 'taz'))); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/XmlRpcTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/XmlRpcTest.php new file mode 100644 index 0000000..fb6661c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObject/Adapter/XmlRpcTest.php @@ -0,0 +1,55 @@ + + * @license MIT + */ +class XmlRpcTest extends PHPUnit_Framework_TestCase +{ + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc::__construct + * @covers \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc::getServiceName + */ + public function testCanBuildAdapterWithXmlRpcClient() + { + $client = $this + ->getMockBuilder('Zend\Server\Client') + ->setMethods(array('call')) + ->getMock(); + + $adapter = new XmlRpc($client); + + $client + ->expects($this->once()) + ->method('call') + ->with('foo.bar', array('tab' => 'taz')) + ->will($this->returnValue('baz')); + + $this->assertSame('baz', $adapter->call('foo', 'bar', array('tab' => 'taz'))); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php new file mode 100644 index 0000000..ad073e6 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php @@ -0,0 +1,148 @@ + + * @license MIT + */ +class RemoteObjectFactoryTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $inflector; + + /** + * @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject + */ + protected $config; + + /** + * {@inheritDoc} + */ + public function setUp() + { + $this->config = $this->getMock('ProxyManager\\Configuration'); + $this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface'); + $this + ->config + ->expects($this->any()) + ->method('getClassNameInflector') + ->will($this->returnValue($this->inflector)); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\RemoteObjectFactory::__construct + * @covers \ProxyManager\Factory\RemoteObjectFactory::createProxy + * @covers \ProxyManager\Factory\RemoteObjectFactory::getGenerator + */ + public function testWillSkipAutoGeneration() + { + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with('ProxyManagerTestAsset\\BaseInterface') + ->will($this->returnValue('StdClass')); + + $adapter = $this->getMock('ProxyManager\Factory\RemoteObject\AdapterInterface'); + $factory = new RemoteObjectFactory($adapter, $this->config); + /* @var $proxy \stdClass */ + $proxy = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter); + + $this->assertInstanceOf('stdClass', $proxy); + } + + /** + * {@inheritDoc} + * + * @covers \ProxyManager\Factory\RemoteObjectFactory::__construct + * @covers \ProxyManager\Factory\RemoteObjectFactory::createProxy + * @covers \ProxyManager\Factory\RemoteObjectFactory::getGenerator + * + * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful + */ + public function testWillTryAutoGeneration() + { + $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar'); + $generator = $this->getMock('ProxyManager\GeneratorStrategy\\GeneratorStrategyInterface'); + $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface'); + + $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator)); + $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader)); + + $generator + ->expects($this->once()) + ->method('generate') + ->with( + $this->callback( + function (ClassGenerator $targetClass) use ($proxyClassName) { + return $targetClass->getName() === $proxyClassName; + } + ) + ); + + // simulate autoloading + $autoloader + ->expects($this->once()) + ->method('__invoke') + ->with($proxyClassName) + ->will( + $this->returnCallback( + function () use ($proxyClassName) { + eval( + 'class ' . $proxyClassName + . ' extends stdClass {}' + ); + } + ) + ); + + $this + ->inflector + ->expects($this->once()) + ->method('getProxyClassName') + ->with('ProxyManagerTestAsset\\BaseInterface') + ->will($this->returnValue($proxyClassName)); + + $this + ->inflector + ->expects($this->once()) + ->method('getUserClassName') + ->with('ProxyManagerTestAsset\\BaseInterface') + ->will($this->returnValue('stdClass')); + + $adapter = $this->getMock('ProxyManager\Factory\RemoteObject\AdapterInterface'); + $factory = new RemoteObjectFactory($adapter, $this->config); + /* @var $proxy \stdClass */ + $proxy = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter); + + $this->assertInstanceOf($proxyClassName, $proxy); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/FileLocator/FileLocatorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/FileLocator/FileLocatorTest.php new file mode 100644 index 0000000..1ea2fca --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/FileLocator/FileLocatorTest.php @@ -0,0 +1,52 @@ + + * @license MIT + */ +class FileLocatorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\FileLocator\FileLocator::__construct + * @covers \ProxyManager\FileLocator\FileLocator::getProxyFileName + */ + public function testGetProxyFileName() + { + $locator = new FileLocator(__DIR__); + + $this->assertSame(__DIR__ . DIRECTORY_SEPARATOR . 'FooBarBaz.php', $locator->getProxyFileName('Foo\\Bar\\Baz')); + $this->assertSame(__DIR__ . DIRECTORY_SEPARATOR . 'Foo_Bar_Baz.php', $locator->getProxyFileName('Foo_Bar_Baz')); + } + + /** + * @covers \ProxyManager\FileLocator\FileLocator::__construct + */ + public function testRejectsNonExistingDirectory() + { + $this->setExpectedException('ProxyManager\\Exception\\InvalidProxyDirectoryException'); + new FileLocator(__DIR__ . '/non-existing'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php new file mode 100644 index 0000000..fb4af7c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php @@ -0,0 +1,372 @@ + + * @license MIT + * + * @group Functional + * @coversNothing + */ +class AccessInterceptorScopeLocalizerFunctionalTest extends PHPUnit_Framework_TestCase +{ + /** + * {@inheritDoc} + */ + public static function setUpBeforeClass() + { + if (PHP_VERSION_ID < 50400) { + throw new PHPUnit_Framework_SkippedTestError( + 'PHP 5.3 doesn\'t support scope localization of private properties' + ); + } + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCalls($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ + $proxy = new $proxyName($instance); + + $this->assertProxySynchronized($instance, $proxy); + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + + $listener = $this->getMock('stdClass', array('__invoke')); + $listener + ->expects($this->once()) + ->method('__invoke') + ->with($proxy, $proxy, $method, $params, false); + + $proxy->setMethodPrefixInterceptor( + $method, + function ($proxy, $instance, $method, $params, & $returnEarly) use ($listener) { + $listener->__invoke($proxy, $instance, $method, $params, $returnEarly); + } + ); + + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + + $random = uniqid(); + + $proxy->setMethodPrefixInterceptor( + $method, + function ($proxy, $instance, $method, $params, & $returnEarly) use ($random) { + $returnEarly = true; + + return $random; + } + ); + + $this->assertSame($random, call_user_func_array(array($proxy, $method), $params)); + $this->assertProxySynchronized($instance, $proxy); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsWithSuffixListener($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ + $proxy = new $proxyName($instance); + $listener = $this->getMock('stdClass', array('__invoke')); + $listener + ->expects($this->once()) + ->method('__invoke') + ->with($proxy, $proxy, $method, $params, $expectedValue, false); + + $proxy->setMethodSuffixInterceptor( + $method, + function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) use ($listener) { + $listener->__invoke($proxy, $instance, $method, $params, $returnValue, $returnEarly); + } + ); + + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + + $random = uniqid(); + + $proxy->setMethodSuffixInterceptor( + $method, + function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) use ($random) { + $returnEarly = true; + + return $random; + } + ); + + $this->assertSame($random, call_user_func_array(array($proxy, $method), $params)); + $this->assertProxySynchronized($instance, $proxy); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsAfterUnSerialization($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ + $proxy = unserialize(serialize(new $proxyName($instance))); + + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + $this->assertProxySynchronized($instance, $proxy); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsAfterCloning($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ + $proxy = new $proxyName($instance); + $cloned = clone $proxy; + + $this->assertProxySynchronized($instance, $proxy); + $this->assertSame($expectedValue, call_user_func_array(array($cloned, $method), $params)); + $this->assertProxySynchronized($instance, $proxy); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyReadAccess($instance, $proxy, $publicProperty, $propertyValue) + { + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ + $this->assertSame($propertyValue, $proxy->$publicProperty); + $this->assertProxySynchronized($instance, $proxy); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyWriteAccess($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ + $newValue = uniqid(); + $proxy->$publicProperty = $newValue; + + $this->assertSame($newValue, $proxy->$publicProperty); + $this->assertProxySynchronized($instance, $proxy); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyExistence($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ + $this->assertSame(isset($instance->$publicProperty), isset($proxy->$publicProperty)); + $this->assertProxySynchronized($instance, $proxy); + + $instance->$publicProperty = null; + $this->assertFalse(isset($proxy->$publicProperty)); + $this->assertProxySynchronized($instance, $proxy); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyUnset($instance, $proxy, $publicProperty) + { + $this->markTestSkipped('It is currently not possible to synchronize properties un-setting'); + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */ + unset($proxy->$publicProperty); + + $this->assertFalse(isset($instance->$publicProperty)); + $this->assertFalse(isset($proxy->$publicProperty)); + $this->assertProxySynchronized($instance, $proxy); + } + + /** + * Verifies that accessing a public property containing an array behaves like in a normal context + */ + public function testCanWriteToArrayKeysInPublicProperty() + { + $instance = new ClassWithPublicArrayProperty(); + $className = get_class($instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicArrayProperty */ + $proxy = new $proxyName($instance); + + $proxy->arrayProperty['foo'] = 'bar'; + + $this->assertSame('bar', $proxy->arrayProperty['foo']); + + $proxy->arrayProperty = array('tab' => 'taz'); + + $this->assertSame(array('tab' => 'taz'), $proxy->arrayProperty); + $this->assertProxySynchronized($instance, $proxy); + } + + /** + * Verifies that public properties retrieved via `__get` don't get modified in the object state + */ + public function testWillNotModifyRetrievedPublicProperties() + { + $instance = new ClassWithPublicProperties(); + $className = get_class($instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicProperties */ + $proxy = new $proxyName($instance); + $variable = $proxy->property0; + + $this->assertSame('property0', $variable); + + $variable = 'foo'; + + $this->assertSame('property0', $proxy->property0); + $this->assertProxySynchronized($instance, $proxy); + } + + /** + * Verifies that public properties references retrieved via `__get` modify in the object state + */ + public function testWillModifyByRefRetrievedPublicProperties() + { + $instance = new ClassWithPublicProperties(); + $className = get_class($instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicProperties */ + $proxy = new $proxyName($instance); + $variable = & $proxy->property0; + + $this->assertSame('property0', $variable); + + $variable = 'foo'; + + $this->assertSame('foo', $proxy->property0); + $this->assertProxySynchronized($instance, $proxy); + } + + /** + * Generates a proxy for the given class name, and retrieves its class name + * + * @param string $parentClassName + * + * @return string + * + * @throws UnsupportedProxiedClassException + */ + private function generateProxy($parentClassName) + { + $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo'); + $generator = new AccessInterceptorScopeLocalizerGenerator(); + $generatedClass = new ClassGenerator($generatedClassName); + $strategy = new EvaluatingGeneratorStrategy(); + + $generator->generate(new ReflectionClass($parentClassName), $generatedClass); + $strategy->generate($generatedClass); + + return $generatedClassName; + } + + /** + * Generates a list of object | invoked method | parameters | expected result + * + * @return array + */ + public function getProxyMethods() + { + return array( + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicMethod', + array(), + 'publicMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicTypeHintedMethod', + array('param' => new \stdClass()), + 'publicTypeHintedMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicByReferenceMethod', + array(), + 'publicByReferenceMethodDefault' + ), + ); + } + + /** + * Generates proxies and instances with a public property to feed to the property accessor methods + * + * @return array + */ + public function getPropertyAccessProxies() + { + $instance1 = new BaseClass(); + $proxyName1 = $this->generateProxy(get_class($instance1)); + + return array( + array( + $instance1, + new $proxyName1($instance1), + 'publicProperty', + 'publicPropertyDefault', + ), + ); + } + + /** + * @param object $instance + * @param AccessInterceptorInterface $proxy + */ + private function assertProxySynchronized($instance, AccessInterceptorInterface $proxy) + { + $reflectionClass = new ReflectionClass($instance); + + foreach ($reflectionClass->getProperties() as $property) { + $property->setAccessible(true); + + $this->assertSame( + $property->getValue($instance), + $property->getValue($proxy), + 'Property "' . $property->getName() . '" is synchronized between instance and proxy' + ); + } + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php new file mode 100644 index 0000000..c71edb6 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php @@ -0,0 +1,344 @@ + + * @license MIT + * + * @group Functional + * @coversNothing + */ +class AccessInterceptorValueHolderFunctionalTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getProxyMethods + */ + public function testMethodCalls($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ + $proxy = new $proxyName($instance); + + $this->assertSame($instance, $proxy->getWrappedValueHolderValue()); + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + + $listener = $this->getMock('stdClass', array('__invoke')); + $listener + ->expects($this->once()) + ->method('__invoke') + ->with($proxy, $instance, $method, $params, false); + + $proxy->setMethodPrefixInterceptor( + $method, + function ($proxy, $instance, $method, $params, & $returnEarly) use ($listener) { + $listener->__invoke($proxy, $instance, $method, $params, $returnEarly); + } + ); + + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + + $random = uniqid(); + + $proxy->setMethodPrefixInterceptor( + $method, + function ($proxy, $instance, $method, $params, & $returnEarly) use ($random) { + $returnEarly = true; + + return $random; + } + ); + + $this->assertSame($random, call_user_func_array(array($proxy, $method), $params)); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsWithSuffixListener($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ + $proxy = new $proxyName($instance); + $listener = $this->getMock('stdClass', array('__invoke')); + $listener + ->expects($this->once()) + ->method('__invoke') + ->with($proxy, $instance, $method, $params, $expectedValue, false); + + $proxy->setMethodSuffixInterceptor( + $method, + function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) use ($listener) { + $listener->__invoke($proxy, $instance, $method, $params, $returnValue, $returnEarly); + } + ); + + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + + $random = uniqid(); + + $proxy->setMethodSuffixInterceptor( + $method, + function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) use ($random) { + $returnEarly = true; + + return $random; + } + ); + + $this->assertSame($random, call_user_func_array(array($proxy, $method), $params)); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsAfterUnSerialization($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ + $proxy = unserialize(serialize(new $proxyName($instance))); + + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + $this->assertEquals($instance, $proxy->getWrappedValueHolderValue()); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsAfterCloning($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ + $proxy = new $proxyName($instance); + $cloned = clone $proxy; + + $this->assertNotSame($proxy->getWrappedValueHolderValue(), $cloned->getWrappedValueHolderValue()); + $this->assertSame($expectedValue, call_user_func_array(array($cloned, $method), $params)); + $this->assertEquals($instance, $cloned->getWrappedValueHolderValue()); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyReadAccess($instance, $proxy, $publicProperty, $propertyValue) + { + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ + $this->assertSame($propertyValue, $proxy->$publicProperty); + $this->assertEquals($instance, $proxy->getWrappedValueHolderValue()); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyWriteAccess($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ + $newValue = uniqid(); + $proxy->$publicProperty = $newValue; + + $this->assertSame($newValue, $proxy->$publicProperty); + $this->assertSame($newValue, $proxy->getWrappedValueHolderValue()->$publicProperty); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyExistence($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ + $this->assertSame(isset($instance->$publicProperty), isset($proxy->$publicProperty)); + $this->assertEquals($instance, $proxy->getWrappedValueHolderValue()); + + $proxy->getWrappedValueHolderValue()->$publicProperty = null; + $this->assertFalse(isset($proxy->$publicProperty)); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyUnset($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */ + $instance = $proxy->getWrappedValueHolderValue() ? $proxy->getWrappedValueHolderValue() : $instance; + unset($proxy->$publicProperty); + + $this->assertFalse(isset($instance->$publicProperty)); + $this->assertFalse(isset($proxy->$publicProperty)); + } + + /** + * Verifies that accessing a public property containing an array behaves like in a normal context + */ + public function testCanWriteToArrayKeysInPublicProperty() + { + $instance = new ClassWithPublicArrayProperty(); + $className = get_class($instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicArrayProperty */ + $proxy = new $proxyName($instance); + + $proxy->arrayProperty['foo'] = 'bar'; + + $this->assertSame('bar', $proxy->arrayProperty['foo']); + + $proxy->arrayProperty = array('tab' => 'taz'); + + $this->assertSame(array('tab' => 'taz'), $proxy->arrayProperty); + } + + /** + * Verifies that public properties retrieved via `__get` don't get modified in the object state + */ + public function testWillNotModifyRetrievedPublicProperties() + { + $instance = new ClassWithPublicProperties(); + $className = get_class($instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicProperties */ + $proxy = new $proxyName($instance); + $variable = $proxy->property0; + + $this->assertSame('property0', $variable); + + $variable = 'foo'; + + $this->assertSame('property0', $proxy->property0); + } + + /** + * Verifies that public properties references retrieved via `__get` modify in the object state + */ + public function testWillModifyByRefRetrievedPublicProperties() + { + $instance = new ClassWithPublicProperties(); + $className = get_class($instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicProperties */ + $proxy = new $proxyName($instance); + $variable = & $proxy->property0; + + $this->assertSame('property0', $variable); + + $variable = 'foo'; + + $this->assertSame('foo', $proxy->property0); + } + + /** + * Generates a proxy for the given class name, and retrieves its class name + * + * @param string $parentClassName + * + * @return string + */ + private function generateProxy($parentClassName) + { + $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo'); + $generator = new AccessInterceptorValueHolderGenerator(); + $generatedClass = new ClassGenerator($generatedClassName); + $strategy = new EvaluatingGeneratorStrategy(); + + $generator->generate(new ReflectionClass($parentClassName), $generatedClass); + $strategy->generate($generatedClass); + + return $generatedClassName; + } + + /** + * Generates a list of object | invoked method | parameters | expected result + * + * @return array + */ + public function getProxyMethods() + { + return array( + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicMethod', + array(), + 'publicMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicTypeHintedMethod', + array('param' => new \stdClass()), + 'publicTypeHintedMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicByReferenceMethod', + array(), + 'publicByReferenceMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseInterface', + new BaseClass(), + 'publicMethod', + array(), + 'publicMethodDefault' + ), + ); + } + + /** + * Generates proxies and instances with a public property to feed to the property accessor methods + * + * @return array + */ + public function getPropertyAccessProxies() + { + $instance1 = new BaseClass(); + $proxyName1 = $this->generateProxy(get_class($instance1)); + $instance2 = new BaseClass(); + $proxyName2 = $this->generateProxy(get_class($instance2)); + + return array( + array( + $instance1, + new $proxyName1($instance1), + 'publicProperty', + 'publicPropertyDefault', + ), + array( + $instance2, + unserialize(serialize(new $proxyName2($instance2))), + 'publicProperty', + 'publicPropertyDefault', + ), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/BaseLazyLoadingPerformanceTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/BaseLazyLoadingPerformanceTest.php new file mode 100644 index 0000000..d00fa41 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/BaseLazyLoadingPerformanceTest.php @@ -0,0 +1,196 @@ + + * @license MIT + * + * @group Performance + * @coversNothing + */ +abstract class BaseLazyLoadingPerformanceTest extends BasePerformanceTest +{ + /** + * @param string $className + * @param object[] $instances + * @param \ProxyManager\Proxy\LazyLoadingInterface[] $proxies + * @param string $methodName + * @param array $parameters + */ + protected function profileMethodAccess($className, array $instances, array $proxies, $methodName, array $parameters) + { + $iterations = count($instances); + + $this->startCapturing(); + + foreach ($instances as $instance) { + call_user_func_array(array($instance, $methodName), $parameters); + } + + $baseProfile = $this->endCapturing( + $iterations . ' calls to ' . $className . '#' . $methodName . ': %fms / %fKb' + ); + $this->startCapturing(); + + foreach ($proxies as $proxy) { + call_user_func_array(array($proxy, $methodName), $parameters); + } + + $proxyProfile = $this->endCapturing( + $iterations . ' calls to proxied ' . $className . '#' . $methodName . ': %fms / %fKb' + ); + $this->compareProfile($baseProfile, $proxyProfile); + } + + /** + * @param string $className + * @param object[] $instances + * @param \ProxyManager\Proxy\LazyLoadingInterface[] $proxies + * @param string $property + */ + protected function profilePropertyWrites($className, array $instances, array $proxies, $property) + { + $iterations = count($instances); + + $this->startCapturing(); + + foreach ($instances as $instance) { + $instance->$property = 'foo'; + } + + $baseProfile = $this->endCapturing( + $iterations . ' writes of ' . $className . '::' . $property . ': %fms / %fKb' + ); + $this->startCapturing(); + + foreach ($proxies as $proxy) { + $proxy->$property = 'foo'; + } + + $proxyProfile = $this->endCapturing( + $iterations . ' writes of proxied ' . $className . '::' . $property . ': %fms / %fKb' + ); + $this->compareProfile($baseProfile, $proxyProfile); + } + + /** + * @param string $className + * @param object[] $instances + * @param \ProxyManager\Proxy\LazyLoadingInterface[] $proxies + * @param string $property + */ + protected function profilePropertyReads($className, array $instances, array $proxies, $property) + { + $iterations = count($instances); + + $this->startCapturing(); + + foreach ($instances as $instance) { + $instance->$property; + } + + $baseProfile = $this->endCapturing( + $iterations . ' reads of ' . $className . '::' . $property . ': %fms / %fKb' + ); + $this->startCapturing(); + + foreach ($proxies as $proxy) { + $proxy->$property; + } + + $proxyProfile = $this->endCapturing( + $iterations . ' reads of proxied ' . $className . '::' . $property . ': %fms / %fKb' + ); + $this->compareProfile($baseProfile, $proxyProfile); + } + + /** + * @param string $className + * @param object[] $instances + * @param \ProxyManager\Proxy\LazyLoadingInterface[] $proxies + * @param string $property + */ + protected function profilePropertyIsset($className, array $instances, array $proxies, $property) + { + $iterations = count($instances); + + $this->startCapturing(); + + foreach ($instances as $instance) { + isset($instance->$property); + } + + $baseProfile = $this->endCapturing( + $iterations . ' isset of ' . $className . '::' . $property . ': %fms / %fKb' + ); + $this->startCapturing(); + + foreach ($proxies as $proxy) { + isset($proxy->$property); + } + + $proxyProfile = $this->endCapturing( + $iterations . ' isset of proxied ' . $className . '::' . $property . ': %fms / %fKb' + ); + $this->compareProfile($baseProfile, $proxyProfile); + } + + /** + * @param string $className + * @param object[] $instances + * @param \ProxyManager\Proxy\LazyLoadingInterface[] $proxies + * @param string $property + */ + protected function profilePropertyUnset($className, array $instances, array $proxies, $property) + { + $iterations = count($instances); + + $this->startCapturing(); + + foreach ($instances as $instance) { + unset($instance->$property); + } + + $baseProfile = $this->endCapturing( + $iterations . ' unset of ' . $className . '::' . $property . ': %fms / %fKb' + ); + $this->startCapturing(); + + foreach ($proxies as $proxy) { + unset($proxy->$property); + } + + $proxyProfile = $this->endCapturing( + $iterations . ' unset of proxied ' . $className . '::' . $property . ': %fms / %fKb' + ); + $this->compareProfile($baseProfile, $proxyProfile); + } + + /** + * Generates a proxy for the given class name, and retrieves its class name + * + * @param string $parentClassName + * + * @return string + */ + abstract protected function generateProxy($parentClassName); +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/BasePerformanceTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/BasePerformanceTest.php new file mode 100644 index 0000000..4f9710b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/BasePerformanceTest.php @@ -0,0 +1,100 @@ + + * @license MIT + * + * @group Performance + * @coversNothing + */ +abstract class BasePerformanceTest extends PHPUnit_Framework_TestCase +{ + /** + * @var float time when last capture was started + */ + private $startTime = 0; + + /** + * @var int bytes when last capture was started + */ + private $startMemory = 0; + + /** + * {@inheritDoc} + */ + public static function setUpBeforeClass() + { + $header = "Performance test - " . get_called_class() . ":"; + + echo "\n\n" . str_repeat('=', strlen($header)) . "\n" . $header . "\n\n"; + } + + /** + * Start profiler snapshot + */ + protected function startCapturing() + { + $this->startMemory = memory_get_usage(); + $this->startTime = microtime(true); + } + + /** + * Echo current profiler output + * + * @param string $messageTemplate + * + * @return array + */ + protected function endCapturing($messageTemplate) + { + $time = microtime(true) - $this->startTime; + $memory = memory_get_usage() - $this->startMemory; + + if (gc_enable()) { + gc_collect_cycles(); + } + + echo sprintf($messageTemplate, $time, $memory / 1024) . "\n"; + + return array( + 'time' => $time, + 'memory' => $memory + ); + } + + /** + * Display comparison between two profiles + * + * @param array $baseProfile + * @param array $proxyProfile + */ + protected function compareProfile(array $baseProfile, array $proxyProfile) + { + $timeOverhead = (($proxyProfile['time'] / $baseProfile['time']) - 1) * 100; + $memoryOverhead = (($proxyProfile['memory'] / $baseProfile['memory']) - 1) * 100; + + echo sprintf('Comparison time / memory: %.2f%% / %.2f%%', $timeOverhead, $memoryOverhead) . "\n\n"; + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php new file mode 100644 index 0000000..30b8ceb --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingGhostFunctionalTest.php @@ -0,0 +1,425 @@ + + * @license MIT + * + * @group Functional + * @coversNothing + */ +class LazyLoadingGhostFunctionalTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getProxyMethods + */ + public function testMethodCalls($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */ + $proxy = new $proxyName($this->createInitializer($className, $instance)); + + $this->assertFalse($proxy->isProxyInitialized()); + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + $this->assertTrue($proxy->isProxyInitialized()); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsAfterUnSerialization($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */ + $proxy = unserialize(serialize(new $proxyName($this->createInitializer($className, $instance)))); + + $this->assertTrue($proxy->isProxyInitialized()); + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsAfterCloning($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */ + $proxy = new $proxyName($this->createInitializer($className, $instance)); + $cloned = clone $proxy; + + $this->assertTrue($cloned->isProxyInitialized()); + $this->assertSame($expectedValue, call_user_func_array(array($cloned, $method), $params)); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyReadAccess($instance, $proxy, $publicProperty, $propertyValue) + { + /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */ + $this->assertSame($propertyValue, $proxy->$publicProperty); + $this->assertTrue($proxy->isProxyInitialized()); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyWriteAccess($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */ + $newValue = uniqid(); + $proxy->$publicProperty = $newValue; + + $this->assertTrue($proxy->isProxyInitialized()); + $this->assertSame($newValue, $proxy->$publicProperty); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyExistence($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */ + $this->assertSame(isset($instance->$publicProperty), isset($proxy->$publicProperty)); + $this->assertTrue($proxy->isProxyInitialized()); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyAbsence($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */ + $proxy->$publicProperty = null; + $this->assertFalse(isset($proxy->$publicProperty)); + $this->assertTrue($proxy->isProxyInitialized()); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyUnset($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */ + + unset($proxy->$publicProperty); + + $this->assertTrue($proxy->isProxyInitialized()); + $this->assertTrue(isset($instance->$publicProperty)); + $this->assertFalse(isset($proxy->$publicProperty)); + } + + /** + * Verifies that accessing a public property containing an array behaves like in a normal context + */ + public function testCanWriteToArrayKeysInPublicProperty() + { + $instance = new ClassWithPublicArrayProperty(); + $className = get_class($instance); + $initializer = $this->createInitializer($className, $instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicArrayProperty */ + $proxy = new $proxyName($initializer); + + $proxy->arrayProperty['foo'] = 'bar'; + + $this->assertSame('bar', $proxy->arrayProperty['foo']); + + $proxy->arrayProperty = array('tab' => 'taz'); + + $this->assertSame(array('tab' => 'taz'), $proxy->arrayProperty); + } + + /** + * Verifies that public properties retrieved via `__get` don't get modified in the object itself + */ + public function testWillNotModifyRetrievedPublicProperties() + { + $instance = new ClassWithPublicProperties(); + $className = get_class($instance); + $initializer = $this->createInitializer($className, $instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicProperties */ + $proxy = new $proxyName($initializer); + $variable = $proxy->property0; + + $this->assertSame('property0', $variable); + + $variable = 'foo'; + + $this->assertSame('property0', $proxy->property0); + } + + /** + * Verifies that public properties references retrieved via `__get` modify in the object state + */ + public function testWillModifyByRefRetrievedPublicProperties() + { + $instance = new ClassWithPublicProperties(); + $className = get_class($instance); + $initializer = $this->createInitializer($className, $instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicProperties */ + $proxy = new $proxyName($initializer); + $variable = & $proxy->property0; + + $this->assertSame('property0', $variable); + + $variable = 'foo'; + + $this->assertSame('foo', $proxy->property0); + } + + public function testKeepsInitializerWhenNotOverwitten() + { + $instance = new BaseClass(); + $proxyName = $this->generateProxy(get_class($instance)); + $initializer = function () { + }; + /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */ + $proxy = new $proxyName($initializer); + + $proxy->initializeProxy(); + + $this->assertSame($initializer, $proxy->getProxyInitializer()); + } + + /** + * Verifies that public properties are not being initialized multiple times + */ + public function testKeepsInitializedPublicProperties() + { + $instance = new BaseClass(); + $proxyName = $this->generateProxy(get_class($instance)); + $initializer = function (BaseClass $proxy, $method, $parameters, & $initializer) { + $initializer = null; + $proxy->publicProperty = 'newValue'; + }; + /* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */ + $proxy = new $proxyName($initializer); + + $proxy->initializeProxy(); + $this->assertSame('newValue', $proxy->publicProperty); + + $proxy->publicProperty = 'otherValue'; + + $proxy->initializeProxy(); + + $this->assertSame('otherValue', $proxy->publicProperty); + } + + /** + * Verifies that properties' default values are preserved + */ + public function testPublicPropertyDefaultWillBePreserved() + { + $instance = new ClassWithPublicProperties(); + $proxyName = $this->generateProxy(get_class($instance)); + /* @var $proxy ClassWithPublicProperties */ + $proxy = new $proxyName(function () { + }); + + $this->assertSame('property0', $proxy->property0); + } + + /** + * Verifies that protected properties' default values are preserved + */ + public function testProtectedPropertyDefaultWillBePreserved() + { + $instance = new ClassWithProtectedProperties(); + $proxyName = $this->generateProxy(get_class($instance)); + /* @var $proxy ClassWithProtectedProperties */ + $proxy = new $proxyName(function () { + }); + + // Check protected property via reflection + $reflectionProperty = new ReflectionProperty($instance, 'property0'); + $reflectionProperty->setAccessible(true); + + $this->assertSame('property0', $reflectionProperty->getValue($proxy)); + } + + /** + * Verifies that private properties' default values are preserved + */ + public function testPrivatePropertyDefaultWillBePreserved() + { + $instance = new ClassWithPrivateProperties(); + $proxyName = $this->generateProxy(get_class($instance)); + /* @var $proxy ClassWithPrivateProperties */ + $proxy = new $proxyName(function () { + }); + + // Check protected property via reflection + $reflectionProperty = new ReflectionProperty($instance, 'property0'); + $reflectionProperty->setAccessible(true); + + $this->assertSame('property0', $reflectionProperty->getValue($proxy)); + } + + /** + * Generates a proxy for the given class name, and retrieves its class name + * + * @param string $parentClassName + * + * @return string + */ + private function generateProxy($parentClassName) + { + $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo'); + $generator = new LazyLoadingGhostGenerator(); + $generatedClass = new ClassGenerator($generatedClassName); + $strategy = new EvaluatingGeneratorStrategy(); + + $generator->generate(new ReflectionClass($parentClassName), $generatedClass); + $strategy->generate($generatedClass); + + return $generatedClassName; + } + + /** + * @param string $className + * @param object $realInstance + * @param Mock $initializerMatcher + * + * @return \Closure + */ + private function createInitializer($className, $realInstance, Mock $initializerMatcher = null) + { + if (null === $initializerMatcher) { + $initializerMatcher = $this->getMock('stdClass', array('__invoke')); + + $initializerMatcher + ->expects($this->once()) + ->method('__invoke') + ->with( + $this->logicalAnd( + $this->isInstanceOf('ProxyManager\\Proxy\\GhostObjectInterface'), + $this->isInstanceOf($className) + ) + ); + } + + $initializerMatcher = $initializerMatcher ?: $this->getMock('stdClass', array('__invoke')); + + return function ( + GhostObjectInterface $proxy, + $method, + $params, + & $initializer + ) use ( + $initializerMatcher, + $realInstance + ) { + $initializer = null; + $reflectionClass = new ReflectionClass($realInstance); + + foreach ($reflectionClass->getProperties() as $property) { + $property->setAccessible(true); + $property->setValue($proxy, $property->getValue($realInstance)); + } + + $initializerMatcher->__invoke($proxy, $method, $params); + }; + } + + /** + * Generates a list of object | invoked method | parameters | expected result + * + * @return array + */ + public function getProxyMethods() + { + return array( + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicMethod', + array(), + 'publicMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicTypeHintedMethod', + array(new \stdClass()), + 'publicTypeHintedMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicByReferenceMethod', + array(), + 'publicByReferenceMethodDefault' + ), + ); + } + + /** + * Generates proxies and instances with a public property to feed to the property accessor methods + * + * @return array + */ + public function getPropertyAccessProxies() + { + $instance1 = new BaseClass(); + $proxyName1 = $this->generateProxy(get_class($instance1)); + $instance2 = new BaseClass(); + $proxyName2 = $this->generateProxy(get_class($instance2)); + + return array( + array( + $instance1, + new $proxyName1($this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance1)), + 'publicProperty', + 'publicPropertyDefault', + ), + array( + $instance2, + unserialize( + serialize(new $proxyName2($this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance2))) + ), + 'publicProperty', + 'publicPropertyDefault', + ), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingGhostPerformanceTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingGhostPerformanceTest.php new file mode 100644 index 0000000..21b9f49 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingGhostPerformanceTest.php @@ -0,0 +1,160 @@ + + * @license MIT + * + * @group Performance + * @coversNothing + */ +class LazyLoadingGhostPerformanceTest extends BaseLazyLoadingPerformanceTest +{ + /** + * @outputBuffering + * @dataProvider getTestedClasses + * + * @param string $className + * @param array $methods + * @param array $properties + * @param \ReflectionProperty[] $reflectionProperties + * + * @return void + */ + public function testProxyInstantiationPerformance( + $className, + array $methods, + array $properties, + array $reflectionProperties + ) { + $proxyName = $this->generateProxy($className); + $iterations = 20000; + $instances = array(); + /* @var $proxies \ProxyManager\Proxy\GhostObjectInterface[] */ + $proxies = array(); + $realInstance = new $className(); + $initializer = function ( + GhostObjectInterface $proxy, + $method, + $params, + & $initializer + ) use ( + $reflectionProperties, + $realInstance + ) { + $initializer = null; + + foreach ($reflectionProperties as $reflectionProperty) { + $reflectionProperty->setValue($proxy, $reflectionProperty->getValue($realInstance)); + } + + return true; + }; + + $this->startCapturing(); + + for ($i = 0; $i < $iterations; $i += 1) { + $instances[] = new $className(); + } + + $baseProfile = $this->endCapturing( + 'Instantiation for ' . $iterations . ' objects of type ' . $className . ': %fms / %fKb' + ); + $this->startCapturing(); + + for ($i = 0; $i < $iterations; $i += 1) { + $proxies[] = new $proxyName($initializer); + } + + $proxyProfile = $this->endCapturing( + 'Instantiation for ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb' + ); + $this->compareProfile($baseProfile, $proxyProfile); + $this->startCapturing(); + + foreach ($proxies as $proxy) { + $proxy->initializeProxy(); + } + + $this->endCapturing('Initialization of ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb'); + + foreach ($methods as $methodName => $parameters) { + $this->profileMethodAccess($className, $instances, $proxies, $methodName, $parameters); + } + + foreach ($properties as $property) { + $this->profilePropertyWrites($className, $instances, $proxies, $property); + $this->profilePropertyReads($className, $instances, $proxies, $property); + $this->profilePropertyIsset($className, $instances, $proxies, $property); + $this->profilePropertyUnset($className, $instances, $proxies, $property); + } + } + + /** + * @return array + */ + public function getTestedClasses() + { + $testedClasses = array( + array('stdClass', array(), array()), + array('ProxyManagerTestAsset\\BaseClass', array('publicMethod' => array()), array('publicProperty')), + ); + + foreach ($testedClasses as $key => $testedClass) { + $reflectionProperties = array(); + $reflectionClass = new ReflectionClass($testedClass[0]); + + foreach ($reflectionClass->getProperties() as $property) { + $property->setAccessible(true); + + $reflectionProperties[$property->getName()] = $property; + } + + $testedClasses[$key][] = $reflectionProperties; + } + + return $testedClasses; + } + + /** + * {@inheritDoc} + */ + protected function generateProxy($parentClassName) + { + $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo'); + $generator = new LazyLoadingGhostGenerator(); + $generatedClass = new ClassGenerator($generatedClassName); + $strategy = new EvaluatingGeneratorStrategy(); + + $generator->generate(new ReflectionClass($parentClassName), $generatedClass); + $strategy->generate($generatedClass); + + return $generatedClassName; + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php new file mode 100644 index 0000000..6dc1d3b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderFunctionalTest.php @@ -0,0 +1,347 @@ + + * @license MIT + * + * @group Functional + * @coversNothing + */ +class LazyLoadingValueHolderFunctionalTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getProxyMethods + */ + public function testMethodCalls($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ + $proxy = new $proxyName($this->createInitializer($className, $instance)); + + $this->assertFalse($proxy->isProxyInitialized()); + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + $this->assertTrue($proxy->isProxyInitialized()); + $this->assertSame($instance, $proxy->getWrappedValueHolderValue()); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsAfterUnSerialization($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ + $proxy = unserialize(serialize(new $proxyName($this->createInitializer($className, $instance)))); + + $this->assertTrue($proxy->isProxyInitialized()); + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + $this->assertEquals($instance, $proxy->getWrappedValueHolderValue()); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsAfterCloning($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ + $proxy = new $proxyName($this->createInitializer($className, $instance)); + $cloned = clone $proxy; + + $this->assertTrue($cloned->isProxyInitialized()); + $this->assertNotSame($proxy->getWrappedValueHolderValue(), $cloned->getWrappedValueHolderValue()); + $this->assertSame($expectedValue, call_user_func_array(array($cloned, $method), $params)); + $this->assertEquals($instance, $cloned->getWrappedValueHolderValue()); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyReadAccess($instance, $proxy, $publicProperty, $propertyValue) + { + /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ + $this->assertSame($propertyValue, $proxy->$publicProperty); + $this->assertTrue($proxy->isProxyInitialized()); + $this->assertEquals($instance, $proxy->getWrappedValueHolderValue()); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyWriteAccess($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ + $newValue = uniqid(); + $proxy->$publicProperty = $newValue; + + $this->assertTrue($proxy->isProxyInitialized()); + $this->assertSame($newValue, $proxy->$publicProperty); + $this->assertSame($newValue, $proxy->getWrappedValueHolderValue()->$publicProperty); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyExistence($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ + $this->assertSame(isset($instance->$publicProperty), isset($proxy->$publicProperty)); + $this->assertTrue($proxy->isProxyInitialized()); + $this->assertEquals($instance, $proxy->getWrappedValueHolderValue()); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyAbsence($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ + $instance = $proxy->getWrappedValueHolderValue() ? $proxy->getWrappedValueHolderValue() : $instance; + $instance->$publicProperty = null; + $this->assertFalse(isset($proxy->$publicProperty)); + $this->assertTrue($proxy->isProxyInitialized()); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyUnset($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */ + $instance = $proxy->getWrappedValueHolderValue() ? $proxy->getWrappedValueHolderValue() : $instance; + unset($proxy->$publicProperty); + + $this->assertTrue($proxy->isProxyInitialized()); + + $this->assertFalse(isset($instance->$publicProperty)); + $this->assertFalse(isset($proxy->$publicProperty)); + } + + /** + * Verifies that accessing a public property containing an array behaves like in a normal context + */ + public function testCanWriteToArrayKeysInPublicProperty() + { + $instance = new ClassWithPublicArrayProperty(); + $className = get_class($instance); + $initializer = $this->createInitializer($className, $instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicArrayProperty */ + $proxy = new $proxyName($initializer); + + $proxy->arrayProperty['foo'] = 'bar'; + + $this->assertSame('bar', $proxy->arrayProperty['foo']); + + $proxy->arrayProperty = array('tab' => 'taz'); + + $this->assertSame(array('tab' => 'taz'), $proxy->arrayProperty); + } + + /** + * Verifies that public properties retrieved via `__get` don't get modified in the object itself + */ + public function testWillNotModifyRetrievedPublicProperties() + { + $instance = new ClassWithPublicProperties(); + $className = get_class($instance); + $initializer = $this->createInitializer($className, $instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicProperties */ + $proxy = new $proxyName($initializer); + $variable = $proxy->property0; + + $this->assertSame('property0', $variable); + + $variable = 'foo'; + + $this->assertSame('property0', $proxy->property0); + } + + /** + * Verifies that public properties references retrieved via `__get` modify in the object state + */ + public function testWillModifyByRefRetrievedPublicProperties() + { + $instance = new ClassWithPublicProperties(); + $className = get_class($instance); + $initializer = $this->createInitializer($className, $instance); + $proxyName = $this->generateProxy($className); + /* @var $proxy ClassWithPublicProperties */ + $proxy = new $proxyName($initializer); + $variable = & $proxy->property0; + + $this->assertSame('property0', $variable); + + $variable = 'foo'; + + $this->assertSame('foo', $proxy->property0); + } + + /** + * Generates a proxy for the given class name, and retrieves its class name + * + * @param string $parentClassName + * + * @return string + */ + private function generateProxy($parentClassName) + { + $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo'); + $generator = new LazyLoadingValueHolderGenerator(); + $generatedClass = new ClassGenerator($generatedClassName); + $strategy = new EvaluatingGeneratorStrategy(); + + $generator->generate(new ReflectionClass($parentClassName), $generatedClass); + $strategy->generate($generatedClass); + + return $generatedClassName; + } + + /** + * @param string $className + * @param object $realInstance + * @param Mock $initializerMatcher + * + * @return \Closure + */ + private function createInitializer($className, $realInstance, Mock $initializerMatcher = null) + { + if (null === $initializerMatcher) { + $initializerMatcher = $this->getMock('stdClass', array('__invoke')); + + $initializerMatcher + ->expects($this->once()) + ->method('__invoke') + ->with( + $this->logicalAnd( + $this->isInstanceOf('ProxyManager\\Proxy\\VirtualProxyInterface'), + $this->isInstanceOf($className) + ), + $realInstance + ); + } + + $initializerMatcher = $initializerMatcher ?: $this->getMock('stdClass', array('__invoke')); + + return function ( + & $wrappedObject, + VirtualProxyInterface $proxy, + $method, + $params, + & $initializer + ) use ( + $initializerMatcher, + $realInstance + ) { + $initializer = null; + $wrappedObject = $realInstance; + + $initializerMatcher->__invoke($proxy, $wrappedObject, $method, $params); + }; + } + + /** + * Generates a list of object | invoked method | parameters | expected result + * + * @return array + */ + public function getProxyMethods() + { + return array( + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicMethod', + array(), + 'publicMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicTypeHintedMethod', + array(new \stdClass()), + 'publicTypeHintedMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicByReferenceMethod', + array(), + 'publicByReferenceMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseInterface', + new BaseClass(), + 'publicMethod', + array(), + 'publicMethodDefault' + ), + ); + } + + /** + * Generates proxies and instances with a public property to feed to the property accessor methods + * + * @return array + */ + public function getPropertyAccessProxies() + { + $instance1 = new BaseClass(); + $proxyName1 = $this->generateProxy(get_class($instance1)); + $instance2 = new BaseClass(); + $proxyName2 = $this->generateProxy(get_class($instance2)); + + return array( + array( + $instance1, + new $proxyName1($this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance1)), + 'publicProperty', + 'publicPropertyDefault', + ), + array( + $instance2, + unserialize( + serialize(new $proxyName2($this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance2))) + ), + 'publicProperty', + 'publicPropertyDefault', + ), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderPerformanceTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderPerformanceTest.php new file mode 100644 index 0000000..1279526 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/LazyLoadingValueHolderPerformanceTest.php @@ -0,0 +1,134 @@ + + * @license MIT + * + * @group Performance + * @coversNothing + */ +class LazyLoadingValueHolderPerformanceTest extends BaseLazyLoadingPerformanceTest +{ + /** + * @outputBuffering + * @dataProvider getTestedClasses + * + * @param string $className + * @param array $methods + * @param array $properties + * + * @return void + */ + public function testProxyInstantiationPerformance($className, array $methods, array $properties) + { + $proxyName = $this->generateProxy($className); + $iterations = 20000; + $instances = array(); + /* @var $proxies \ProxyManager\Proxy\VirtualProxyInterface[] */ + $proxies = array(); + $initializer = function ( + & $valueHolder, + VirtualProxyInterface $proxy, + $method, + $params, + & $initializer + ) use ($className) { + $initializer = null; + $valueHolder = new $className(); + + return true; + }; + + $this->startCapturing(); + + for ($i = 0; $i < $iterations; $i += 1) { + $instances[] = new $className(); + } + + $baseProfile = $this->endCapturing( + 'Instantiation for ' . $iterations . ' objects of type ' . $className . ': %fms / %fKb' + ); + $this->startCapturing(); + + for ($i = 0; $i < $iterations; $i += 1) { + $proxies[] = new $proxyName($initializer); + } + + $proxyProfile = $this->endCapturing( + 'Instantiation for ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb' + ); + $this->compareProfile($baseProfile, $proxyProfile); + $this->startCapturing(); + + foreach ($proxies as $proxy) { + $proxy->initializeProxy(); + } + + $this->endCapturing('Initialization of ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb'); + + foreach ($methods as $methodName => $parameters) { + $this->profileMethodAccess($className, $instances, $proxies, $methodName, $parameters); + } + + foreach ($properties as $property) { + $this->profilePropertyWrites($className, $instances, $proxies, $property); + $this->profilePropertyReads($className, $instances, $proxies, $property); + $this->profilePropertyIsset($className, $instances, $proxies, $property); + $this->profilePropertyUnset($className, $instances, $proxies, $property); + } + } + + /** + * @return array + */ + public function getTestedClasses() + { + return array( + array('stdClass', array(), array()), + array('ProxyManagerTestAsset\\BaseClass', array('publicMethod' => array()), array('publicProperty')), + ); + } + + /** + * {@inheritDoc} + */ + protected function generateProxy($parentClassName) + { + $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo'); + $generator = new LazyLoadingValueHolderGenerator(); + $generatedClass = new ClassGenerator($generatedClassName); + $strategy = new EvaluatingGeneratorStrategy(); + + $generator->generate(new ReflectionClass($parentClassName), $generatedClass); + $strategy->generate($generatedClass); + + return $generatedClassName; + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/MultipleProxyGenerationTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/MultipleProxyGenerationTest.php new file mode 100644 index 0000000..564d56c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/MultipleProxyGenerationTest.php @@ -0,0 +1,114 @@ + + * @license MIT + * + * @link https://github.com/Ocramius/ProxyManager/issues/10 + * + * @group Functional + * @group issue-10 + * @coversNothing + */ +class MultipleProxyGenerationTest extends PHPUnit_Framework_TestCase +{ + /** + * Verifies that proxies generated from different factories will retain their specific implementation + * and won't conflict + * + * @dataProvider getTestedClasses + */ + public function testCanGenerateMultipleDifferentProxiesForSameClass($className) + { + $skipScopeLocalizerTests = false; + $ghostProxyFactory = new LazyLoadingGhostFactory(); + $virtualProxyFactory = new LazyLoadingValueHolderFactory(); + $accessInterceptorFactory = new AccessInterceptorValueHolderFactory(); + $accessInterceptorScopeLocalizerFactory = new AccessInterceptorScopeLocalizerFactory(); + $initializer = function () { + }; + + $reflectionClass = new ReflectionClass($className); + + if (PHP_VERSION_ID < 50400 && $reflectionClass->getProperties(ReflectionProperty::IS_PRIVATE)) { + $skipScopeLocalizerTests = true; + } + + $generated = array( + $ghostProxyFactory->createProxy($className, $initializer), + $virtualProxyFactory->createProxy($className, $initializer), + $accessInterceptorFactory->createProxy(new $className()), + ); + + if (! $skipScopeLocalizerTests) { + $generated[] = $accessInterceptorScopeLocalizerFactory->createProxy(new $className()); + } + + foreach ($generated as $key => $proxy) { + $this->assertInstanceOf($className, $proxy); + + foreach ($generated as $comparedKey => $comparedProxy) { + if ($comparedKey === $key) { + continue; + } + + $this->assertNotSame(get_class($comparedProxy), get_class($proxy)); + } + } + + $this->assertInstanceOf('ProxyManager\Proxy\GhostObjectInterface', $generated[0]); + $this->assertInstanceOf('ProxyManager\Proxy\VirtualProxyInterface', $generated[1]); + $this->assertInstanceOf('ProxyManager\Proxy\AccessInterceptorInterface', $generated[2]); + $this->assertInstanceOf('ProxyManager\Proxy\ValueHolderInterface', $generated[2]); + + if (! $skipScopeLocalizerTests) { + $this->assertInstanceOf('ProxyManager\Proxy\AccessInterceptorInterface', $generated[3]); + } + } + + /** + * @return string[][] + */ + public function getTestedClasses() + { + return array( + array('ProxyManagerTestAsset\\BaseClass'), + array('ProxyManagerTestAsset\\ClassWithMagicMethods'), + array('ProxyManagerTestAsset\\ClassWithByRefMagicMethods'), + array('ProxyManagerTestAsset\\ClassWithMixedProperties'), + array('ProxyManagerTestAsset\\ClassWithPrivateProperties'), + array('ProxyManagerTestAsset\\ClassWithProtectedProperties'), + array('ProxyManagerTestAsset\\ClassWithPublicProperties'), + array('ProxyManagerTestAsset\\EmptyClass'), + array('ProxyManagerTestAsset\\HydratedObject'), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php new file mode 100644 index 0000000..a848424 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php @@ -0,0 +1,207 @@ + + * @license MIT + * + * @group Functional + * @coversNothing + */ +class NullObjectFunctionalTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getProxyMethods + */ + public function testMethodCalls($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ + $proxy = new $proxyName(); + + $this->assertSame(null, call_user_func_array(array($proxy, $method), $params)); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsAfterUnSerialization($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ + $proxy = unserialize(serialize(new $proxyName())); + + $this->assertSame(null, call_user_func_array(array($proxy, $method), $params)); + } + + /** + * @dataProvider getProxyMethods + */ + public function testMethodCallsAfterCloning($className, $instance, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($className); + + /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ + $proxy = new $proxyName(); + $cloned = clone $proxy; + + $this->assertSame(null, call_user_func_array(array($cloned, $method), $params)); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyReadAccess($instance, $proxy, $publicProperty, $propertyValue) + { + /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ + $this->assertSame(null, $proxy->$publicProperty); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyWriteAccess($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ + $newValue = uniqid(); + $proxy->$publicProperty = $newValue; + + $this->assertSame($newValue, $proxy->$publicProperty); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyExistence($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ + $this->assertSame(null, $proxy->$publicProperty); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testPropertyUnset($instance, $proxy, $publicProperty) + { + /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ + unset($proxy->$publicProperty); + + $this->assertTrue(isset($instance->$publicProperty)); + $this->assertFalse(isset($proxy->$publicProperty)); + } + + /** + * Generates a proxy for the given class name, and retrieves its class name + * + * @param string $parentClassName + * + * @return string + */ + private function generateProxy($parentClassName) + { + $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo'); + $generator = new NullObjectGenerator(); + $generatedClass = new ClassGenerator($generatedClassName); + $strategy = new EvaluatingGeneratorStrategy(); + + $generator->generate(new ReflectionClass($parentClassName), $generatedClass); + $strategy->generate($generatedClass); + + return $generatedClassName; + } + + /** + * Generates a list of object | invoked method | parameters | expected result + * + * @return array + */ + public function getProxyMethods() + { + return array( + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicMethod', + array(), + 'publicMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicTypeHintedMethod', + array('param' => new \stdClass()), + 'publicTypeHintedMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseClass', + new BaseClass(), + 'publicByReferenceMethod', + array(), + 'publicByReferenceMethodDefault' + ), + array( + 'ProxyManagerTestAsset\\BaseInterface', + new BaseClass(), + 'publicMethod', + array(), + 'publicMethodDefault' + ), + ); + } + + /** + * Generates proxies and instances with a public property to feed to the property accessor methods + * + * @return array + */ + public function getPropertyAccessProxies() + { + $instance1 = new BaseClass(); + $proxyName1 = $this->generateProxy(get_class($instance1)); + $instance2 = new BaseClass(); + $proxyName2 = $this->generateProxy(get_class($instance2)); + + return array( + array( + $instance1, + new $proxyName1($instance1), + 'publicProperty', + 'publicPropertyDefault', + ), + array( + $instance2, + unserialize(serialize(new $proxyName2($instance2))), + 'publicProperty', + 'publicPropertyDefault', + ), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/RemoteObjectFunctionalTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/RemoteObjectFunctionalTest.php new file mode 100644 index 0000000..9356e87 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/RemoteObjectFunctionalTest.php @@ -0,0 +1,216 @@ + + * @license MIT + * + * @group Functional + * @coversNothing + */ +class RemoteObjectFunctionalTest extends PHPUnit_Framework_TestCase +{ + /** + * @param mixed $expectedValue + * @param string $method + * @param array $params + * + * @return XmlRpcAdapter + */ + protected function getXmlRpcAdapter($expectedValue, $method, array $params) + { + $client = $this + ->getMockBuilder('Zend\Server\Client') + ->setMethods(array('call')) + ->getMock(); + + $client + ->expects($this->any()) + ->method('call') + ->with($this->stringEndsWith($method), $params) + ->will($this->returnValue($expectedValue)); + + $adapter = new XmlRpcAdapter( + $client, + array( + 'ProxyManagerTestAsset\RemoteProxy\Foo.foo' + => 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface.foo' + ) + ); + + return $adapter; + } + + /** + * @param mixed $expectedValue + * @param string $method + * @param array $params + * + * @return JsonRpcAdapter + */ + protected function getJsonRpcAdapter($expectedValue, $method, array $params) + { + $client = $this + ->getMockBuilder('Zend\Server\Client') + ->setMethods(array('call')) + ->getMock(); + + $client + ->expects($this->any()) + ->method('call') + ->with($this->stringEndsWith($method), $params) + ->will($this->returnValue($expectedValue)); + + $adapter = new JsonRpcAdapter( + $client, + array( + 'ProxyManagerTestAsset\RemoteProxy\Foo.foo' + => 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface.foo' + ) + ); + + return $adapter; + } + + /** + * @dataProvider getProxyMethods + */ + public function testXmlRpcMethodCalls($instanceOrClassname, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($instanceOrClassname); + + /* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */ + $proxy = new $proxyName($this->getXmlRpcAdapter($expectedValue, $method, $params)); + + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + } + + /** + * @dataProvider getProxyMethods + */ + public function testJsonRpcMethodCalls($instanceOrClassname, $method, $params, $expectedValue) + { + $proxyName = $this->generateProxy($instanceOrClassname); + + /* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */ + $proxy = new $proxyName($this->getJsonRpcAdapter($expectedValue, $method, $params)); + + $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params)); + } + + /** + * @dataProvider getPropertyAccessProxies + */ + public function testJsonRpcPropertyReadAccess($instanceOrClassname, $publicProperty, $propertyValue) + { + $proxyName = $this->generateProxy($instanceOrClassname); + + /* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */ + $proxy = new $proxyName( + $this->getJsonRpcAdapter($propertyValue, '__get', array($publicProperty)) + ); + + /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ + $this->assertSame($propertyValue, $proxy->$publicProperty); + } + + /** + * Generates a proxy for the given class name, and retrieves its class name + * + * @param string $parentClassName + * + * @return string + */ + private function generateProxy($parentClassName) + { + $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo'); + $generator = new RemoteObjectGenerator(); + $generatedClass = new ClassGenerator($generatedClassName); + $strategy = new EvaluatingGeneratorStrategy(); + + $generator->generate(new ReflectionClass($parentClassName), $generatedClass); + $strategy->generate($generatedClass); + + return $generatedClassName; + } + + /** + * Generates a list of object | invoked method | parameters | expected result + * + * @return array + */ + public function getProxyMethods() + { + return array( + array( + 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface', + 'foo', + array(), + 'bar remote' + ), + array( + 'ProxyManagerTestAsset\RemoteProxy\Foo', + 'foo', + array(), + 'bar remote' + ), + array( + new Foo(), + 'foo', + array(), + 'bar remote' + ), + array( + 'ProxyManagerTestAsset\RemoteProxy\BazServiceInterface', + 'baz', + array('baz'), + 'baz remote' + ), + ); + } + + /** + * Generates proxies and instances with a public property to feed to the property accessor methods + * + * @return array + */ + public function getPropertyAccessProxies() + { + return array( + array( + 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface', + 'publicProperty', + 'publicProperty remote', + ), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/ClassGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/ClassGeneratorTest.php new file mode 100644 index 0000000..8bab3ac --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/ClassGeneratorTest.php @@ -0,0 +1,63 @@ + + * @license MIT + */ +class ClassGeneratorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\Generator\ClassGenerator::setExtendedClass + */ + public function testExtendedClassesAreFQCNs() + { + $desiredFqcn = '\\stdClass'; + $classNameInputs = array('stdClass', '\\stdClass\\'); + + foreach ($classNameInputs as $className) { + $classGenerator = new ClassGenerator(); + $classGenerator->setExtendedClass($className); + + $this->assertEquals($desiredFqcn, $classGenerator->getExtendedClass()); + } + } + + /** + * @covers \ProxyManager\Generator\ClassGenerator::setImplementedInterfaces + */ + public function testImplementedInterfacesAreFQCNs() + { + $desiredFqcns = array('\\Countable'); + $interfaceNameInputs = array(array('Countable'), array('\\Countable\\')); + + foreach ($interfaceNameInputs as $interfaceNames) { + $classGenerator = new ClassGenerator(); + $classGenerator->setImplementedInterfaces($interfaceNames); + + $this->assertEquals($desiredFqcns, $classGenerator->getImplementedInterfaces()); + } + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/MagicMethodGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/MagicMethodGeneratorTest.php new file mode 100644 index 0000000..f9cd033 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/MagicMethodGeneratorTest.php @@ -0,0 +1,54 @@ + + * @license MIT + */ +class MagicMethodGeneratorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\Generator\MagicMethodGenerator::__construct + */ + public function testGeneratesCorrectByRefReturnValue() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithByRefMagicMethods'); + $magicMethod = new MagicMethodGenerator($reflection, '__get', array('name')); + + $this->assertTrue($magicMethod->returnsReference()); + } + + /** + * @covers \ProxyManager\Generator\MagicMethodGenerator::__construct + */ + public function testGeneratesCorrectByValReturnValue() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); + $magicMethod = new MagicMethodGenerator($reflection, '__get', array('name')); + + $this->assertFalse($magicMethod->returnsReference()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/MethodGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/MethodGeneratorTest.php new file mode 100644 index 0000000..6a6c830 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/MethodGeneratorTest.php @@ -0,0 +1,78 @@ + + * @license MIT + * + * @covers \ProxyManager\Generator\MethodGenerator + */ +class MethodGeneratorTest extends PHPUnit_Framework_TestCase +{ + public function testGenerateSimpleMethod() + { + $methodGenerator = new MethodGenerator(); + + $methodGenerator->setReturnsReference(true); + $methodGenerator->setName('methodName'); + $methodGenerator->setVisibility('protected'); + $methodGenerator->setBody('/* body */'); + $methodGenerator->setDocBlock('docBlock'); + $methodGenerator->setParameter(new ParameterGenerator('foo')); + + $this->assertSame(true, $methodGenerator->returnsReference()); + $this->assertStringMatchesFormat( + '%a/**%adocBlock%a*/%aprotected function & methodName($foo)%a{%a/* body */%a}', + $methodGenerator->generate() + ); + } + + /** + * Verify that building from reflection works + */ + public function testGenerateFromReflection() + { + $method = MethodGenerator::fromReflection(new MethodReflection(__CLASS__, __FUNCTION__)); + + $this->assertSame(__FUNCTION__, $method->getName()); + $this->assertSame(MethodGenerator::VISIBILITY_PUBLIC, $method->getVisibility()); + $this->assertFalse($method->isStatic()); + $this->assertSame('Verify that building from reflection works', $method->getDocBlock()->getShortDescription()); + + $method = MethodGenerator::fromReflection( + new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'protectedMethod') + ); + + $this->assertSame(MethodGenerator::VISIBILITY_PROTECTED, $method->getVisibility()); + + $method = MethodGenerator::fromReflection( + new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'privateMethod') + ); + + $this->assertSame(MethodGenerator::VISIBILITY_PRIVATE, $method->getVisibility()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/ParameterGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/ParameterGeneratorTest.php new file mode 100644 index 0000000..f3602f7 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/ParameterGeneratorTest.php @@ -0,0 +1,116 @@ + + * @license MIT + * + * @covers \ProxyManager\Generator\ParameterGenerator + */ +class ParameterGeneratorTest extends PHPUnit_Framework_TestCase +{ + public function testGeneratesProperTypeHint() + { + $generator = new ParameterGenerator('foo'); + + $generator->setType('array'); + $this->assertSame('array $foo', $generator->generate()); + + $generator->setType('stdClass'); + $this->assertSame('\\stdClass $foo', $generator->generate()); + + $generator->setType('\\fooClass'); + $this->assertSame('\\fooClass $foo', $generator->generate()); + } + + public function testGeneratesMethodWithCallableType() + { + if (PHP_VERSION_ID < 50400) { + $this->markTestSkipped('`callable` is only supported in PHP >=5.4.0'); + } + + $generator = new ParameterGenerator(); + + $generator->setType('callable'); + $generator->setName('foo'); + + $this->assertSame('callable $foo', $generator->generate()); + } + + public function testVisitMethodWithCallable() + { + if (PHP_VERSION_ID < 50400) { + $this->markTestSkipped('`callable` is only supported in PHP >=5.4.0'); + } + + $parameter = new ParameterReflection( + array('ProxyManagerTestAsset\\CallableTypeHintClass', 'callableTypeHintMethod'), + 'parameter' + ); + + $generator = ParameterGenerator::fromReflection($parameter); + + $this->assertSame('callable', $generator->getType()); + } + + public function testReadsParameterDefaults() + { + $parameter = ParameterGenerator::fromReflection(new ParameterReflection( + array( + 'ProxyManagerTestAsset\\ClassWithMethodWithDefaultParameters', + 'publicMethodWithDefaults' + ), + 'parameter' + )); + + /* @var $defaultValue \Zend\Code\Generator\ValueGenerator */ + $defaultValue = $parameter->getDefaultValue(); + + $this->assertInstanceOf('Zend\\Code\\Generator\\ValueGenerator', $defaultValue); + $this->assertSame(array('foo'), $defaultValue->getValue()); + + $this->assertStringMatchesFormat('array%a$parameter%a=%aarray(\'foo\')', $parameter->generate()); + } + + public function testReadsParameterTypeHint() + { + $parameter = ParameterGenerator::fromReflection(new ParameterReflection( + array('ProxyManagerTestAsset\\BaseClass', 'publicTypeHintedMethod'), + 'param' + )); + + $this->assertSame('stdClass', $parameter->getType()); + } + + public function testGeneratesParameterPassedByReference() + { + $parameter = new ParameterGenerator('foo'); + + $parameter->setPassedByReference(true); + + $this->assertStringMatchesFormat('&%A$foo', $parameter->generate()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/Util/UniqueIdentifierGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/Util/UniqueIdentifierGeneratorTest.php new file mode 100644 index 0000000..b513978 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/Util/UniqueIdentifierGeneratorTest.php @@ -0,0 +1,75 @@ + + * @license MIT + */ +class UniqueIdentifierGeneratorTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getBaseIdentifierNames + * + * @covers \ProxyManager\Generator\Util\UniqueIdentifierGenerator::getIdentifier + */ + public function testGeneratesUniqueIdentifiers($name) + { + $this->assertNotSame( + UniqueIdentifierGenerator::getIdentifier($name), + UniqueIdentifierGenerator::getIdentifier($name) + ); + } + + /** + * @dataProvider getBaseIdentifierNames + * + * @covers \ProxyManager\Generator\Util\UniqueIdentifierGenerator::getIdentifier + */ + public function testGeneratesValidIdentifiers($name) + { + $this->assertRegExp( + '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/', + UniqueIdentifierGenerator::getIdentifier($name) + ); + } + + /** + * Data provider generating identifier names to be checked + * + * @return string[][] + */ + public function getBaseIdentifierNames() + { + return array( + array(''), + array('1'), + array('foo'), + array('Foo'), + array('bar'), + array('Bar'), + array('foo_bar'), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/GeneratorStrategy/BaseGeneratorStrategyTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/GeneratorStrategy/BaseGeneratorStrategyTest.php new file mode 100644 index 0000000..3d5f2fc --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/GeneratorStrategy/BaseGeneratorStrategyTest.php @@ -0,0 +1,46 @@ + + * @license MIT + */ +class BaseGeneratorStrategyTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\GeneratorStrategy\BaseGeneratorStrategy::generate + */ + public function testGenerate() + { + $strategy = new BaseGeneratorStrategy(); + $className = UniqueIdentifierGenerator::getIdentifier('Foo'); + $classGenerator = new ClassGenerator($className); + $generated = $strategy->generate($classGenerator); + + $this->assertGreaterThan(0, strpos($generated, $className)); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/GeneratorStrategy/EvaluatingGeneratorStrategyTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/GeneratorStrategy/EvaluatingGeneratorStrategyTest.php new file mode 100644 index 0000000..79c9307 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/GeneratorStrategy/EvaluatingGeneratorStrategyTest.php @@ -0,0 +1,67 @@ + + * @license MIT + */ +class EvaluatingGeneratorStrategyTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::generate + * @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::__construct + */ + public function testGenerate() + { + $strategy = new EvaluatingGeneratorStrategy(); + $className = UniqueIdentifierGenerator::getIdentifier('Foo'); + $classGenerator = new ClassGenerator($className); + $generated = $strategy->generate($classGenerator); + + $this->assertGreaterThan(0, strpos($generated, $className)); + $this->assertTrue(class_exists($className, false)); + } + + /** + * @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::generate + * @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::__construct + */ + public function testGenerateWithDisabledEval() + { + if (! ini_get('suhosin.executor.disable_eval')) { + $this->markTestSkipped('Ini setting "suhosin.executor.disable_eval" is needed to run this test'); + } + + $strategy = new EvaluatingGeneratorStrategy(); + $className = 'Foo' . uniqid(); + $classGenerator = new ClassGenerator($className); + $generated = $strategy->generate($classGenerator); + + $this->assertGreaterThan(0, strpos($generated, $className)); + $this->assertTrue(class_exists($className, false)); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/GeneratorStrategy/FileWriterGeneratorStrategyTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/GeneratorStrategy/FileWriterGeneratorStrategyTest.php new file mode 100644 index 0000000..eeb5abe --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/GeneratorStrategy/FileWriterGeneratorStrategyTest.php @@ -0,0 +1,63 @@ + + * @license MIT + */ +class FileWriterGeneratorStrategyTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy::__construct + * @covers \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy::generate + */ + public function testGenerate() + { + $locator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface'); + $generator = new FileWriterGeneratorStrategy($locator); + $tmpFile = sys_get_temp_dir() . '/FileWriterGeneratorStrategyTest' . uniqid() . '.php'; + $namespace = 'Foo'; + $className = UniqueIdentifierGenerator::getIdentifier('Bar'); + $fqcn = $namespace . '\\' . $className; + + $locator + ->expects($this->any()) + ->method('getProxyFileName') + ->with($fqcn) + ->will($this->returnValue($tmpFile)); + + $body = $generator->generate(new ClassGenerator($fqcn)); + + $this->assertGreaterThan(0, strpos($body, $className)); + $this->assertFalse(class_exists($fqcn, false)); + $this->assertTrue(file_exists($tmpFile)); + + require $tmpFile; + + $this->assertTrue(class_exists($fqcn, false)); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Inflector/ClassNameInflectorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Inflector/ClassNameInflectorTest.php new file mode 100644 index 0000000..2c172bd --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Inflector/ClassNameInflectorTest.php @@ -0,0 +1,119 @@ + + * @license MIT + */ +class ClassNameInflectorTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getClassNames + * + * @covers \ProxyManager\Inflector\ClassNameInflector::__construct + * @covers \ProxyManager\Inflector\ClassNameInflector::getUserClassName + * @covers \ProxyManager\Inflector\ClassNameInflector::getProxyClassName + * @covers \ProxyManager\Inflector\ClassNameInflector::isProxyClassName + */ + public function testInflector($realClassName, $proxyClassName) + { + $inflector = new ClassNameInflector('ProxyNS'); + + $this->assertFalse($inflector->isProxyClassName($realClassName)); + $this->assertTrue($inflector->isProxyClassName($proxyClassName)); + $this->assertStringMatchesFormat($realClassName, $inflector->getUserClassName($realClassName)); + $this->assertStringMatchesFormat($proxyClassName, $inflector->getProxyClassName($proxyClassName)); + $this->assertStringMatchesFormat($proxyClassName, $inflector->getProxyClassName($realClassName)); + $this->assertStringMatchesFormat($realClassName, $inflector->getUserClassName($proxyClassName)); + } + + /** + * @covers \ProxyManager\Inflector\ClassNameInflector::getProxyClassName + */ + public function testGeneratesSameClassNameWithSameParameters() + { + $inflector = new ClassNameInflector('ProxyNS'); + + $this->assertSame($inflector->getProxyClassName('Foo\\Bar'), $inflector->getProxyClassName('Foo\\Bar')); + $this->assertSame( + $inflector->getProxyClassName('Foo\\Bar', array('baz' => 'tab')), + $inflector->getProxyClassName('Foo\\Bar', array('baz' => 'tab')) + ); + $this->assertSame( + $inflector->getProxyClassName('Foo\\Bar', array('tab' => 'baz')), + $inflector->getProxyClassName('Foo\\Bar', array('tab' => 'baz')) + ); + } + + /** + * @covers \ProxyManager\Inflector\ClassNameInflector::getProxyClassName + */ + public function testGeneratesDifferentClassNameWithDifferentParameters() + { + $inflector = new ClassNameInflector('ProxyNS'); + + $this->assertNotSame( + $inflector->getProxyClassName('Foo\\Bar'), + $inflector->getProxyClassName('Foo\\Bar', array('foo' => 'bar')) + ); + $this->assertNotSame( + $inflector->getProxyClassName('Foo\\Bar', array('baz' => 'tab')), + $inflector->getProxyClassName('Foo\\Bar', array('tab' => 'baz')) + ); + $this->assertNotSame( + $inflector->getProxyClassName('Foo\\Bar', array('foo' => 'bar', 'tab' => 'baz')), + $inflector->getProxyClassName('Foo\\Bar', array('foo' => 'bar')) + ); + $this->assertNotSame( + $inflector->getProxyClassName('Foo\\Bar', array('foo' => 'bar', 'tab' => 'baz')), + $inflector->getProxyClassName('Foo\\Bar', array('tab' => 'baz', 'foo' => 'bar')) + ); + } + + /** + * @covers \ProxyManager\Inflector\ClassNameInflector::getProxyClassName + */ + public function testGeneratesCorrectClassNameWhenGivenLeadingBackslash() + { + $inflector = new ClassNameInflector('ProxyNS'); + + $this->assertSame( + $inflector->getProxyClassName('\\Foo\\Bar', array('tab' => 'baz')), + $inflector->getProxyClassName('Foo\\Bar', array('tab' => 'baz')) + ); + } + + /** + * @return array + */ + public function getClassNames() + { + return array( + array('Foo', 'ProxyNS\\' . ClassNameInflectorInterface::PROXY_MARKER . '\\Foo\\%s'), + array('Foo\\Bar', 'ProxyNS\\' . ClassNameInflectorInterface::PROXY_MARKER . '\\Foo\\Bar\\%s'), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Inflector/Util/ParameterEncoderTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Inflector/Util/ParameterEncoderTest.php new file mode 100644 index 0000000..5098a5e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Inflector/Util/ParameterEncoderTest.php @@ -0,0 +1,64 @@ + + * @license MIT + */ +class ParameterEncoderTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getParameters + * + * @covers \ProxyManager\Inflector\Util\ParameterEncoder::encodeParameters + */ + public function testGeneratesValidClassName(array $parameters) + { + $encoder = new ParameterEncoder(); + + $this->assertRegExp( + '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+/', + $encoder->encodeParameters($parameters), + 'Encoded string is a valid class identifier' + ); + } + + /** + * @return array + */ + public function getParameters() + { + return array( + array(array()), + array(array('foo' => 'bar')), + array(array('bar' => 'baz')), + array(array(null)), + array(array(null, null)), + array(array('bar' => null)), + array(array('bar' => 12345)), + array(array('foo' => 'bar', 'bar' => 'baz')), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AbstractProxyGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AbstractProxyGeneratorTest.php new file mode 100644 index 0000000..ff6e467 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AbstractProxyGeneratorTest.php @@ -0,0 +1,93 @@ + + * @license MIT + */ +abstract class AbstractProxyGeneratorTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getTestedImplementations + * + * Verifies that generated code is valid and implements expected interfaces + */ + public function testGeneratesValidCode($className) + { + $generator = $this->getProxyGenerator(); + $generatedClassName = UniqueIdentifierGenerator::getIdentifier('AbstractProxyGeneratorTest'); + $generatedClass = new ClassGenerator($generatedClassName); + $originalClass = new ReflectionClass($className); + $generatorStrategy = new EvaluatingGeneratorStrategy(); + + $generator->generate($originalClass, $generatedClass); + $generatorStrategy->generate($generatedClass); + + $generatedReflection = new ReflectionClass($generatedClassName); + + if ($originalClass->isInterface()) { + $this->assertTrue($generatedReflection->implementsInterface($className)); + } else { + $this->assertSame($originalClass->getName(), $generatedReflection->getParentClass()->getName()); + } + + $this->assertSame($generatedClassName, $generatedReflection->getName()); + + foreach ($this->getExpectedImplementedInterfaces() as $interface) { + $this->assertTrue($generatedReflection->implementsInterface($interface)); + } + } + + /** + * Retrieve a new generator instance + * + * @return \ProxyManager\ProxyGenerator\ProxyGeneratorInterface + */ + abstract protected function getProxyGenerator(); + + /** + * Retrieve interfaces that should be implemented by the generated code + * + * @return string[] + */ + abstract protected function getExpectedImplementedInterfaces(); + + /** + * @return array + */ + public function getTestedImplementations() + { + return array( + array('ProxyManagerTestAsset\\BaseClass'), + array('ProxyManagerTestAsset\\ClassWithMagicMethods'), + array('ProxyManagerTestAsset\\ClassWithByRefMagicMethods'), + array('ProxyManagerTestAsset\\ClassWithMixedProperties'), + array('ProxyManagerTestAsset\\BaseInterface'), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/MethodGenerator/MagicWakeupTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/MethodGenerator/MagicWakeupTest.php new file mode 100644 index 0000000..c7cb0e1 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/MethodGenerator/MagicWakeupTest.php @@ -0,0 +1,60 @@ + + * @license MIT + */ +class MagicWakeupTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass( + 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' + ); + + $magicWakeup = new MagicWakeup($reflection); + + $this->assertSame('__wakeup', $magicWakeup->getName()); + $this->assertCount(0, $magicWakeup->getParameters()); + $this->assertSame("unset(\$this->bar, \$this->baz);", $magicWakeup->getBody()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup::__construct + */ + public function testBodyStructureWithoutPublicProperties() + { + $magicWakeup = new MagicWakeup(new ReflectionClass('ProxyManagerTestAsset\\EmptyClass')); + + $this->assertSame('__wakeup', $magicWakeup->getName()); + $this->assertCount(0, $magicWakeup->getParameters()); + $this->assertEmpty($magicWakeup->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptorTest.php new file mode 100644 index 0000000..277e476 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptorTest.php @@ -0,0 +1,47 @@ + + * @license MIT + */ +class SetMethodPrefixInterceptorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodPrefixInterceptor::__construct + */ + public function testBodyStructure() + { + $suffix = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $suffix->expects($this->once())->method('getName')->will($this->returnValue('foo')); + + $setter = new SetMethodPrefixInterceptor($suffix); + + $this->assertSame('setMethodPrefixInterceptor', $setter->getName()); + $this->assertCount(2, $setter->getParameters()); + $this->assertSame('$this->foo[$methodName] = $prefixInterceptor;', $setter->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptorTest.php new file mode 100644 index 0000000..c718325 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptorTest.php @@ -0,0 +1,47 @@ + + * @license MIT + */ +class SetMethodSuffixInterceptorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodSuffixInterceptor::__construct + */ + public function testBodyStructure() + { + $suffix = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $suffix->expects($this->once())->method('getName')->will($this->returnValue('foo')); + + $setter = new SetMethodSuffixInterceptor($suffix); + + $this->assertSame('setMethodSuffixInterceptor', $setter->getName()); + $this->assertCount(2, $setter->getParameters()); + $this->assertSame('$this->foo[$methodName] = $suffixInterceptor;', $setter->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodPrefixInterceptorsTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodPrefixInterceptorsTest.php new file mode 100644 index 0000000..002761f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodPrefixInterceptorsTest.php @@ -0,0 +1,41 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodPrefixInterceptors + */ +class MethodPrefixInterceptorsTest extends AbstractUniquePropertyNameTest +{ + /** + * {@inheritDoc} + */ + protected function createProperty() + { + return new MethodPrefixInterceptors(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodSuffixInterceptorsTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodSuffixInterceptorsTest.php new file mode 100644 index 0000000..8e5b4b3 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptor/PropertyGenerator/MethodSuffixInterceptorsTest.php @@ -0,0 +1,41 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodSuffixInterceptors + */ +class MethodSuffixInterceptorsTest extends AbstractUniquePropertyNameTest +{ + /** + * {@inheritDoc} + */ + protected function createProperty() + { + return new MethodSuffixInterceptors(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/ConstructorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/ConstructorTest.php new file mode 100644 index 0000000..b53a716 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/ConstructorTest.php @@ -0,0 +1,205 @@ + + * @license MIT + */ +class ConstructorTest extends PHPUnit_Framework_TestCase +{ + private $prefixInterceptors; + private $suffixInterceptors; + public function setUp() + { + $this->prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $this->suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $this->prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $this->suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor::__construct + */ + public function testSignature() + { + $constructor = new Constructor( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithProtectedProperties'), + $this->prefixInterceptors, + $this->suffixInterceptors + ); + $this->assertSame('__construct', $constructor->getName()); + + $parameters = $constructor->getParameters(); + + $this->assertCount(3, $parameters); + + $this->assertSame( + 'ProxyManagerTestAsset\\ClassWithProtectedProperties', + $parameters['localizedObject']->getType() + ); + $this->assertSame('array', $parameters['prefixInterceptors']->getType()); + $this->assertSame('array', $parameters['suffixInterceptors']->getType()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor::__construct + */ + public function testBodyStructure() + { + $constructor = new Constructor( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithPublicProperties'), + $this->prefixInterceptors, + $this->suffixInterceptors + ); + + $this->assertSame( + '$this->property0 = & $localizedObject->property0; + +$this->property1 = & $localizedObject->property1; + +$this->property2 = & $localizedObject->property2; + +$this->property3 = & $localizedObject->property3; + +$this->property4 = & $localizedObject->property4; + +$this->property5 = & $localizedObject->property5; + +$this->property6 = & $localizedObject->property6; + +$this->property7 = & $localizedObject->property7; + +$this->property8 = & $localizedObject->property8; + +$this->property9 = & $localizedObject->property9; + +$this->pre = $prefixInterceptors; +$this->post = $suffixInterceptors;', + $constructor->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor::__construct + */ + public function testBodyStructureWithProtectedProperties() + { + $constructor = new Constructor( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithProtectedProperties'), + $this->prefixInterceptors, + $this->suffixInterceptors + ); + + $this->assertSame( + '$this->property0 = & $localizedObject->property0; + +$this->property1 = & $localizedObject->property1; + +$this->property2 = & $localizedObject->property2; + +$this->property3 = & $localizedObject->property3; + +$this->property4 = & $localizedObject->property4; + +$this->property5 = & $localizedObject->property5; + +$this->property6 = & $localizedObject->property6; + +$this->property7 = & $localizedObject->property7; + +$this->property8 = & $localizedObject->property8; + +$this->property9 = & $localizedObject->property9; + +$this->pre = $prefixInterceptors; +$this->post = $suffixInterceptors;', + $constructor->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor::__construct + */ + public function testBodyStructureWithPrivateProperties() + { + if (PHP_VERSION_ID < 50400) { + $this->setExpectedException('ProxyManager\Exception\UnsupportedProxiedClassException'); + } + + $constructor = new Constructor( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithPrivateProperties'), + $this->prefixInterceptors, + $this->suffixInterceptors + ); + + $this->assertSame( + '\Closure::bind(function () use ($localizedObject) { + $this->property0 = & $localizedObject->property0; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property1 = & $localizedObject->property1; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property2 = & $localizedObject->property2; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property3 = & $localizedObject->property3; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property4 = & $localizedObject->property4; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property5 = & $localizedObject->property5; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property6 = & $localizedObject->property6; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property7 = & $localizedObject->property7; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property8 = & $localizedObject->property8; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +\Closure::bind(function () use ($localizedObject) { + $this->property9 = & $localizedObject->property9; +}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); + +$this->pre = $prefixInterceptors; +$this->post = $suffixInterceptors;', + $constructor->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/InterceptedMethodTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/InterceptedMethodTest.php new file mode 100644 index 0000000..9fb8a26 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/InterceptedMethodTest.php @@ -0,0 +1,61 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\InterceptedMethod + */ +class InterceptedMethodTest extends PHPUnit_Framework_TestCase +{ + public function testBodyStructure() + { + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $method = InterceptedMethod::generateMethod( + new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceParameterMethod'), + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertInstanceOf('ProxyManager\\Generator\\MethodGenerator', $method); + + $this->assertSame('publicByReferenceParameterMethod', $method->getName()); + $this->assertCount(2, $method->getParameters()); + $this->assertGreaterThan( + 0, + strpos( + $method->getBody(), + '$returnValue = parent::publicByReferenceParameterMethod($param, $byRefParam);' + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicCloneTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicCloneTest.php new file mode 100644 index 0000000..3327f0d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicCloneTest.php @@ -0,0 +1,70 @@ + + * @license MIT + */ +class MagicCloneTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicClone::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicClone = new MagicClone($reflection, $prefixInterceptors, $suffixInterceptors); + + $this->assertSame('__clone', $magicClone->getName()); + $this->assertCount(0, $magicClone->getParameters()); + $this->assertStringMatchesFormat("%a\n\n\$returnValue = null;\n\n%a", $magicClone->getBody()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicClone::__construct + */ + public function testBodyStructureWithInheritedMethod() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicClone = new MagicClone($reflection, $prefixInterceptors, $suffixInterceptors); + + $this->assertSame('__clone', $magicClone->getName()); + $this->assertCount(0, $magicClone->getParameters()); + $this->assertStringMatchesFormat("%a\n\n\$returnValue = parent::__clone();\n\n%a", $magicClone->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicGetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicGetTest.php new file mode 100644 index 0000000..3d188bb --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicGetTest.php @@ -0,0 +1,78 @@ + + * @license MIT + */ +class MagicGetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicGet::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicGet = new MagicGet( + $reflection, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('__get', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat('%a$returnValue = & $accessor();%a', $magicGet->getBody()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicGet::__construct + */ + public function testBodyStructureWithInheritedMethod() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicGet = new MagicGet( + $reflection, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('__get', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat('%a$returnValue = & parent::__get($name);%a', $magicGet->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicIssetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicIssetTest.php new file mode 100644 index 0000000..13dfd00 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicIssetTest.php @@ -0,0 +1,78 @@ + + * @license MIT + */ +class MagicIssetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicIsset::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicGet = new MagicIsset( + $reflection, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('__isset', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat('%a$returnValue = $accessor();%a', $magicGet->getBody()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicIsset::__construct + */ + public function testBodyStructureWithInheritedMethod() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicGet = new MagicIsset( + $reflection, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('__isset', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat('%a$returnValue = & parent::__isset($name);%a', $magicGet->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSetTest.php new file mode 100644 index 0000000..14f6ccf --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSetTest.php @@ -0,0 +1,78 @@ + + * @license MIT + */ +class MagicSetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSet::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicGet = new MagicSet( + $reflection, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('__set', $magicGet->getName()); + $this->assertCount(2, $magicGet->getParameters()); + $this->assertStringMatchesFormat('%a$returnValue = & $accessor();%a', $magicGet->getBody()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSet::__construct + */ + public function testBodyStructureWithInheritedMethod() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicGet = new MagicSet( + $reflection, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('__set', $magicGet->getName()); + $this->assertCount(2, $magicGet->getParameters()); + $this->assertStringMatchesFormat('%a$returnValue = & parent::__set($name, $value);%a', $magicGet->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSleepTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSleepTest.php new file mode 100644 index 0000000..3f3d926 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicSleepTest.php @@ -0,0 +1,78 @@ + + * @license MIT + */ +class MagicSleepTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSleep::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicGet = new MagicSleep( + $reflection, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('__sleep', $magicGet->getName()); + $this->assertEmpty($magicGet->getParameters()); + $this->assertStringMatchesFormat('%a$returnValue = array_keys((array) $this);%a', $magicGet->getBody()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSleep::__construct + */ + public function testBodyStructureWithInheritedMethod() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicGet = new MagicSleep( + $reflection, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('__sleep', $magicGet->getName()); + $this->assertEmpty($magicGet->getParameters()); + $this->assertStringMatchesFormat('%a$returnValue = & parent::__sleep();%a', $magicGet->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicUnsetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicUnsetTest.php new file mode 100644 index 0000000..f22bc98 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/MagicUnsetTest.php @@ -0,0 +1,78 @@ + + * @license MIT + */ +class MagicUnsetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicUnset::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicGet = new MagicUnset( + $reflection, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('__unset', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat('%a$returnValue = $accessor();%a', $magicGet->getBody()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicUnset::__construct + */ + public function testBodyStructureWithInheritedMethod() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicGet = new MagicUnset( + $reflection, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame('__unset', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat('%a$returnValue = & parent::__unset($name);%a', $magicGet->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Util/InterceptorGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Util/InterceptorGeneratorTest.php new file mode 100644 index 0000000..d328898 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Util/InterceptorGeneratorTest.php @@ -0,0 +1,79 @@ + + * @license MIT + */ +class InterceptorGeneratorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator + */ + public function testInterceptorGenerator() + { + $method = $this->getMock('ProxyManager\\Generator\\MethodGenerator'); + $bar = $this->getMock('ProxyManager\\Generator\\ParameterGenerator'); + $baz = $this->getMock('ProxyManager\\Generator\\ParameterGenerator'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $bar->expects($this->any())->method('getName')->will($this->returnValue('bar')); + $baz->expects($this->any())->method('getName')->will($this->returnValue('baz')); + $method->expects($this->any())->method('getName')->will($this->returnValue('fooMethod')); + $method->expects($this->any())->method('getParameters')->will($this->returnValue(array($bar, $baz))); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $body = InterceptorGenerator::createInterceptedMethodBody( + '$returnValue = "foo";', + $method, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame( + 'if (isset($this->pre[\'fooMethod\'])) {' . "\n" + . ' $returnEarly = false;' . "\n" + . ' $prefixReturnValue = $this->pre[\'fooMethod\']->__invoke($this, $this, \'fooMethod\', ' + . 'array(\'bar\' => $bar, \'baz\' => $baz), $returnEarly);' . "\n\n" + . ' if ($returnEarly) {' . "\n" + . ' return $prefixReturnValue;' . "\n" + . ' }' . "\n" + . '}' . "\n\n" + . '$returnValue = "foo";' . "\n\n" + . 'if (isset($this->post[\'fooMethod\'])) {' . "\n" + . ' $returnEarly = false;' . "\n" + . ' $suffixReturnValue = $this->post[\'fooMethod\']->__invoke($this, $this, \'fooMethod\', ' + . 'array(\'bar\' => $bar, \'baz\' => $baz), $returnValue, $returnEarly);' . "\n\n" + . ' if ($returnEarly) {' . "\n" + . ' return $suffixReturnValue;' . "\n" + . ' }' . "\n" + . '}' . "\n\n" + . 'return $returnValue;', + $body + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizerTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizerTest.php new file mode 100644 index 0000000..44f15a2 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorScopeLocalizerTest.php @@ -0,0 +1,73 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator + */ +class AccessInterceptorScopeLocalizerTest extends AbstractProxyGeneratorTest +{ + /** + * @dataProvider getTestedImplementations + * + * {@inheritDoc} + */ + public function testGeneratesValidCode($className) + { + $reflectionClass = new ReflectionClass($className); + + if ($reflectionClass->isInterface()) { + // @todo interfaces *may* be proxied by deferring property localization to the constructor (no hardcoding) + $this->setExpectedException('ProxyManager\Exception\InvalidProxiedClassException'); + + return parent::testGeneratesValidCode($className); + } + + if (PHP_VERSION_ID < 50400 && $reflectionClass->getProperties(ReflectionProperty::IS_PRIVATE)) { + $this->setExpectedException('ProxyManager\Exception\UnsupportedProxiedClassException'); + } + + return parent::testGeneratesValidCode($className); + } + + /** + * {@inheritDoc} + */ + protected function getProxyGenerator() + { + return new AccessInterceptorScopeLocalizerGenerator(); + } + + /** + * {@inheritDoc} + */ + protected function getExpectedImplementedInterfaces() + { + return array('ProxyManager\\Proxy\\AccessInterceptorInterface'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php new file mode 100644 index 0000000..931a5bf --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ConstructorTest.php @@ -0,0 +1,84 @@ + + * @license MIT + */ +class ConstructorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor::__construct + */ + public function testBodyStructure() + { + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $reflection = new ReflectionClass( + 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' + ); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $constructor = new Constructor($reflection, $valueHolder, $prefixInterceptors, $suffixInterceptors); + + $this->assertSame('__construct', $constructor->getName()); + $this->assertCount(3, $constructor->getParameters()); + $this->assertSame( + "unset(\$this->bar, \$this->baz);\n\n\$this->foo = \$wrappedObject;\n\$this->pre = \$prefixInterceptors;" + . "\n\$this->post = \$suffixInterceptors;", + $constructor->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor::__construct + */ + public function testBodyStructureWithoutPublicProperties() + { + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $constructor = new Constructor($reflection, $valueHolder, $prefixInterceptors, $suffixInterceptors); + + $this->assertSame('__construct', $constructor->getName()); + $this->assertCount(3, $constructor->getParameters()); + $this->assertSame( + "\$this->foo = \$wrappedObject;\n\$this->pre = \$prefixInterceptors;" + . "\n\$this->post = \$suffixInterceptors;", + $constructor->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/InterceptedMethodTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/InterceptedMethodTest.php new file mode 100644 index 0000000..069eedc --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/InterceptedMethodTest.php @@ -0,0 +1,67 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\InterceptedMethod::generateMethod + */ +class InterceptedMethodTest extends PHPUnit_Framework_TestCase +{ + /** + * + */ + public function testBodyStructure() + { + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $method = InterceptedMethod::generateMethod( + new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceParameterMethod'), + $valueHolder, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertInstanceOf('ProxyManager\\Generator\\MethodGenerator', $method); + + $this->assertSame('publicByReferenceParameterMethod', $method->getName()); + $this->assertCount(2, $method->getParameters()); + $this->assertGreaterThan( + 0, + strpos( + $method->getBody(), + '$returnValue = $this->foo->publicByReferenceParameterMethod($param, $byRefParam);' + ) + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicCloneTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicCloneTest.php new file mode 100644 index 0000000..1e88b74 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicCloneTest.php @@ -0,0 +1,62 @@ + + * @license MIT + */ +class MagicCloneTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicClone::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $magicClone = new MagicClone($reflection, $valueHolder, $prefixInterceptors, $suffixInterceptors); + + $this->assertSame('__clone', $magicClone->getName()); + $this->assertCount(0, $magicClone->getParameters()); + $this->assertSame( + '$this->bar = clone $this->bar;' . "\n\n" + . 'foreach ($this->pre as $key => $value) {' . "\n" + . ' $this->pre[$key] = clone $value;' . "\n" + . '}' . "\n\n" + . 'foreach ($this->post as $key => $value) {' . "\n" + . ' $this->post[$key] = clone $value;' . "\n" + . '}', + $magicClone->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicGetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicGetTest.php new file mode 100644 index 0000000..d450b09 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicGetTest.php @@ -0,0 +1,64 @@ + + * @license MIT + */ +class MagicGetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicGet::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + $publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + + $magicGet = new MagicGet( + $reflection, + $valueHolder, + $prefixInterceptors, + $suffixInterceptors, + $publicProperties + ); + + $this->assertSame('__get', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat('%A$returnValue = & $this->bar->$name;%A', $magicGet->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicIssetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicIssetTest.php new file mode 100644 index 0000000..f5a13ff --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicIssetTest.php @@ -0,0 +1,64 @@ + + * @license MIT + */ +class MagicIssetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicIsset::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + $publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + + $magicIsset = new MagicIsset( + $reflection, + $valueHolder, + $prefixInterceptors, + $suffixInterceptors, + $publicProperties + ); + + $this->assertSame('__isset', $magicIsset->getName()); + $this->assertCount(1, $magicIsset->getParameters()); + $this->assertGreaterThan(0, strpos($magicIsset->getBody(), '$returnValue = isset($this->bar->$name);')); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicSetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicSetTest.php new file mode 100644 index 0000000..d5e5357 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicSetTest.php @@ -0,0 +1,64 @@ + + * @license MIT + */ +class MagicSetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicSet::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + $publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + + $magicSet = new MagicSet( + $reflection, + $valueHolder, + $prefixInterceptors, + $suffixInterceptors, + $publicProperties + ); + + $this->assertSame('__set', $magicSet->getName()); + $this->assertCount(2, $magicSet->getParameters()); + $this->assertGreaterThan(0, strpos($magicSet->getBody(), '$returnValue = ($this->bar->$name = $value);')); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnsetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnsetTest.php new file mode 100644 index 0000000..e785287 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/MagicUnsetTest.php @@ -0,0 +1,67 @@ + + * @license MIT + */ +class MagicUnsetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicUnset::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + $publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + + $magicUnset = new MagicUnset( + $reflection, + $valueHolder, + $prefixInterceptors, + $suffixInterceptors, + $publicProperties + ); + + $this->assertSame('__unset', $magicUnset->getName()); + $this->assertCount(1, $magicUnset->getParameters()); + $this->assertGreaterThan( + 0, + strpos($magicUnset->getBody(), 'unset($this->bar->$name);') + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Util/InterceptorGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Util/InterceptorGeneratorTest.php new file mode 100644 index 0000000..f4950b3 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/Util/InterceptorGeneratorTest.php @@ -0,0 +1,82 @@ + + * @license MIT + */ +class InterceptorGeneratorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Util\InterceptorGenerator + */ + public function testInterceptorGenerator() + { + $method = $this->getMock('ProxyManager\\Generator\\MethodGenerator'); + $bar = $this->getMock('ProxyManager\\Generator\\ParameterGenerator'); + $baz = $this->getMock('ProxyManager\\Generator\\ParameterGenerator'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $bar->expects($this->any())->method('getName')->will($this->returnValue('bar')); + $baz->expects($this->any())->method('getName')->will($this->returnValue('baz')); + $method->expects($this->any())->method('getName')->will($this->returnValue('fooMethod')); + $method->expects($this->any())->method('getParameters')->will($this->returnValue(array($bar, $baz))); + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre')); + $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post')); + + $body = InterceptorGenerator::createInterceptedMethodBody( + '$returnValue = "foo";', + $method, + $valueHolder, + $prefixInterceptors, + $suffixInterceptors + ); + + $this->assertSame( + 'if (isset($this->pre[\'fooMethod\'])) {' . "\n" + . ' $returnEarly = false;' . "\n" + . ' $prefixReturnValue = $this->pre[\'fooMethod\']->__invoke($this, $this->foo, \'fooMethod\', ' + . 'array(\'bar\' => $bar, \'baz\' => $baz), $returnEarly);' . "\n\n" + . ' if ($returnEarly) {' . "\n" + . ' return $prefixReturnValue;' . "\n" + . ' }' . "\n" + . '}' . "\n\n" + . '$returnValue = "foo";' . "\n\n" + . 'if (isset($this->post[\'fooMethod\'])) {' . "\n" + . ' $returnEarly = false;' . "\n" + . ' $suffixReturnValue = $this->post[\'fooMethod\']->__invoke($this, $this->foo, \'fooMethod\', ' + . 'array(\'bar\' => $bar, \'baz\' => $baz), $returnValue, $returnEarly);' . "\n\n" + . ' if ($returnEarly) {' . "\n" + . ' return $suffixReturnValue;' . "\n" + . ' }' . "\n" + . '}' . "\n\n" + . 'return $returnValue;', + $body + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolderTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolderTest.php new file mode 100644 index 0000000..58410b4 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/AccessInterceptorValueHolderTest.php @@ -0,0 +1,51 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator + */ +class AccessInterceptorValueHolderTest extends AbstractProxyGeneratorTest +{ + /** + * {@inheritDoc} + */ + protected function getProxyGenerator() + { + return new AccessInterceptorValueHolderGenerator(); + } + + /** + * {@inheritDoc} + */ + protected function getExpectedImplementedInterfaces() + { + return array( + 'ProxyManager\\Proxy\\AccessInterceptorInterface', + 'ProxyManager\\Proxy\\ValueHolderInterface', + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/CallInitializerTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/CallInitializerTest.php new file mode 100644 index 0000000..32c0a97 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/CallInitializerTest.php @@ -0,0 +1,57 @@ + + * @license MIT + */ +class CallInitializerTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\CallInitializer::__construct + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $propertiesDefaults = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $initializationTracker = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('init')); + $propertiesDefaults->expects($this->any())->method('getName')->will($this->returnValue('props')); + $initializationTracker->expects($this->any())->method('getName')->will($this->returnValue('track')); + + $callInitializer = new CallInitializer($initializer, $propertiesDefaults, $initializationTracker); + + $this->assertStringMatchesFormat( + '%Aif ($this->track || ! $this->init) {%areturn;%a}%a' + . '$this->track = true;%a' + . 'foreach (self::$props as $key => $default) {%a' + . '$this->$key = $default;%a' + . '$this->init->__invoke(%a);%a' + . '$this->track = false;', + $callInitializer->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/ConstructorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/ConstructorTest.php new file mode 100644 index 0000000..8324155 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/ConstructorTest.php @@ -0,0 +1,67 @@ + + * @license MIT + */ +class ConstructorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\Constructor::__construct + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $reflection = new ReflectionClass( + 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' + ); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $constructor = new Constructor($reflection, $initializer); + + $this->assertSame('__construct', $constructor->getName()); + $this->assertCount(1, $constructor->getParameters()); + $this->assertSame("unset(\$this->bar, \$this->baz);\n\n\$this->foo = \$initializer;", $constructor->getBody()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\Constructor::__construct + */ + public function testBodyStructureWithoutPublicProperties() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $constructor = new Constructor(new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'), $initializer); + + $this->assertSame('__construct', $constructor->getName()); + $this->assertCount(1, $constructor->getParameters()); + $this->assertSame("\$this->foo = \$initializer;", $constructor->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/GetProxyInitializerTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/GetProxyInitializerTest.php new file mode 100644 index 0000000..5b7be9a --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/GetProxyInitializerTest.php @@ -0,0 +1,47 @@ + + * @license MIT + */ +class GetProxyInitializerTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\GetProxyInitializer::__construct + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $getter = new GetProxyInitializer($initializer); + + $this->assertSame('getProxyInitializer', $getter->getName()); + $this->assertCount(0, $getter->getParameters()); + $this->assertSame('return $this->foo;', $getter->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/InitializeProxyTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/InitializeProxyTest.php new file mode 100644 index 0000000..842b348 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/InitializeProxyTest.php @@ -0,0 +1,52 @@ + + * @license MIT + */ +class InitializeProxyTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\InitializeProxy::__construct + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $initCall = $this->getMock('Zend\\Code\\Generator\\MethodGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $initCall->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $initializeProxy = new InitializeProxy($initializer, $initCall); + + $this->assertSame('initializeProxy', $initializeProxy->getName()); + $this->assertCount(0, $initializeProxy->getParameters()); + $this->assertSame( + 'return $this->foo && $this->bar(\'initializeProxy\', array());', + $initializeProxy->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/IsProxyInitializedTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/IsProxyInitializedTest.php new file mode 100644 index 0000000..26d5a34 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/IsProxyInitializedTest.php @@ -0,0 +1,47 @@ + + * @license MIT + */ +class IsProxyInitializedTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\IsProxyInitialized::__construct + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $isProxyInitialized = new IsProxyInitialized($initializer); + + $this->assertSame('isProxyInitialized', $isProxyInitialized->getName()); + $this->assertCount(0, $isProxyInitialized->getParameters()); + $this->assertSame('return ! $this->foo;', $isProxyInitialized->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/LazyLoadingMethodInterceptorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/LazyLoadingMethodInterceptorTest.php new file mode 100644 index 0000000..e202458 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/LazyLoadingMethodInterceptorTest.php @@ -0,0 +1,79 @@ + + * @license MIT + */ +class LazyLoadingMethodInterceptorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\LazyLoadingMethodInterceptor + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $initCall = $this->getMock('Zend\\Code\\Generator\\MethodGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $initCall->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $reflection = new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceParameterMethod'); + $method = LazyLoadingMethodInterceptor::generateMethod($reflection, $initializer, $initCall); + + $this->assertSame('publicByReferenceParameterMethod', $method->getName()); + $this->assertCount(2, $method->getParameters()); + $this->assertSame( + "\$this->foo && \$this->bar('publicByReferenceParameterMethod', " + . "array('param' => \$param, 'byRefParam' => \$byRefParam));\n\n" + . "return parent::publicByReferenceParameterMethod(\$param, \$byRefParam);", + $method->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\LazyLoadingMethodInterceptor + */ + public function testBodyStructureWithoutParameters() + { + $reflectionMethod = new MethodReflection(__CLASS__, 'testBodyStructureWithoutParameters'); + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $initCall = $this->getMock('Zend\\Code\\Generator\\MethodGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $initCall->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $method = LazyLoadingMethodInterceptor::generateMethod($reflectionMethod, $initializer, $initCall); + + $this->assertSame('testBodyStructureWithoutParameters', $method->getName()); + $this->assertCount(0, $method->getParameters()); + $this->assertSame( + "\$this->foo && \$this->bar('testBodyStructureWithoutParameters', array());\n\n" + . "return parent::testBodyStructureWithoutParameters();", + $method->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicCloneTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicCloneTest.php new file mode 100644 index 0000000..d352402 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicCloneTest.php @@ -0,0 +1,54 @@ + + * @license MIT + */ +class MagicCloneTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicClone::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $initCall = $this->getMock('Zend\\Code\\Generator\\MethodGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $initCall->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $magicClone = new MagicClone($reflection, $initializer, $initCall); + + $this->assertSame('__clone', $magicClone->getName()); + $this->assertCount(0, $magicClone->getParameters()); + $this->assertSame( + "\$this->foo && \$this->bar('__clone', array());", + $magicClone->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGetTest.php new file mode 100644 index 0000000..33a73e8 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGetTest.php @@ -0,0 +1,122 @@ + + * @license MIT + */ +class MagicGetTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + protected $initializer; + + /** + * @var \Zend\Code\Generator\MethodGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + protected $initMethod; + + /** + * @var \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap|\PHPUnit_Framework_MockObject_MockObject + */ + protected $publicProperties; + + /** + * {@inheritDoc} + */ + protected function setUp() + { + $this->initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $this->initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator'); + $this->publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $this->initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $this->initMethod->expects($this->any())->method('getName')->will($this->returnValue('baz')); + $this->publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + $this->publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar')); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $magicGet = new MagicGet($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__get', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->baz('__get', array('name' => \$name));\n\n" + . "if (isset(self::\$bar[\$name])) {\n return \$this->\$name;\n}\n\n" + . "%a", + $magicGet->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet::__construct + */ + public function testBodyStructureWithPublicProperties() + { + $reflection = new ReflectionClass( + 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' + ); + + $magicGet = new MagicGet($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__get', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->baz('__get', array('name' => \$name));\n\n" + . "if (isset(self::\$bar[\$name])) {\n return \$this->\$name;\n}\n\n" + . "%a", + $magicGet->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet::__construct + */ + public function testBodyStructureWithOverriddenMagicGet() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); + $magicGet = new MagicGet($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__get', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertSame( + "\$this->foo && \$this->baz('__get', array('name' => \$name));\n\n" + . "if (isset(self::\$bar[\$name])) {\n return \$this->\$name;\n}\n\n" + . "return parent::__get(\$name);", + $magicGet->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicIssetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicIssetTest.php new file mode 100644 index 0000000..ea6f61d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicIssetTest.php @@ -0,0 +1,121 @@ + + * @license MIT + */ +class MagicIssetTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + protected $initializer; + + /** + * @var \Zend\Code\Generator\MethodGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + protected $initMethod; + + /** + * @var \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap|\PHPUnit_Framework_MockObject_MockObject + */ + protected $publicProperties; + + /** + * {@inheritDoc} + */ + protected function setUp() + { + $this->initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $this->initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator'); + $this->publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $this->initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $this->initMethod->expects($this->any())->method('getName')->will($this->returnValue('baz')); + $this->publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + $this->publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar')); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $magicIsset = new MagicIsset($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__isset', $magicIsset->getName()); + $this->assertCount(1, $magicIsset->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->baz('__isset', array('name' => \$name));\n\n" + . "if (isset(self::\$bar[\$name])) {\n return isset(\$this->\$name);\n}\n\n" + . "%areturn %s;", + $magicIsset->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset::__construct + */ + public function testBodyStructureWithPublicProperties() + { + $reflection = new ReflectionClass( + 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' + ); + $magicIsset = new MagicIsset($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__isset', $magicIsset->getName()); + $this->assertCount(1, $magicIsset->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->baz('__isset', array('name' => \$name));\n\n" + . "if (isset(self::\$bar[\$name])) {\n return isset(\$this->\$name);\n}\n\n" + . "%areturn %s;", + $magicIsset->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset::__construct + */ + public function testBodyStructureWithOverriddenMagicGet() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); + $magicIsset = new MagicIsset($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__isset', $magicIsset->getName()); + $this->assertCount(1, $magicIsset->getParameters()); + $this->assertSame( + "\$this->foo && \$this->baz('__isset', array('name' => \$name));\n\n" + . "if (isset(self::\$bar[\$name])) {\n return isset(\$this->\$name);\n}\n\n" + . "return parent::__isset(\$name);", + $magicIsset->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSetTest.php new file mode 100644 index 0000000..60f6a10 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSetTest.php @@ -0,0 +1,122 @@ + + * @license MIT + */ +class MagicSetTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + protected $initializer; + + /** + * @var \Zend\Code\Generator\MethodGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + protected $initMethod; + + /** + * @var \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap|\PHPUnit_Framework_MockObject_MockObject + */ + protected $publicProperties; + + /** + * {@inheritDoc} + */ + protected function setUp() + { + $this->initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $this->initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator'); + $this->publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $this->initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $this->initMethod->expects($this->any())->method('getName')->will($this->returnValue('baz')); + $this->publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + $this->publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar')); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSet::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $magicSet = new MagicSet($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__set', $magicSet->getName()); + $this->assertCount(2, $magicSet->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->baz('__set', array('name' => \$name, 'value' => \$value));\n\n" + . "if (isset(self::\$bar[\$name])) {\n return (\$this->\$name = \$value);\n}\n\n" + . "%areturn %s;", + $magicSet->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSet::__construct + */ + public function testBodyStructureWithPublicProperties() + { + $reflection = new ReflectionClass( + 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' + ); + + $magicSet = new MagicSet($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__set', $magicSet->getName()); + $this->assertCount(2, $magicSet->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->baz('__set', array('name' => \$name, 'value' => \$value));\n\n" + . "if (isset(self::\$bar[\$name])) {\n return (\$this->\$name = \$value);\n}\n\n" + . "%areturn %s;", + $magicSet->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSet::__construct + */ + public function testBodyStructureWithOverriddenMagicGet() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); + $magicSet = new MagicSet($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__set', $magicSet->getName()); + $this->assertCount(2, $magicSet->getParameters()); + $this->assertSame( + "\$this->foo && \$this->baz('__set', array('name' => \$name, 'value' => \$value));\n\n" + . "if (isset(self::\$bar[\$name])) {\n return (\$this->\$name = \$value);\n}\n\n" + . "return parent::__set(\$name, \$value);", + $magicSet->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSleepTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSleepTest.php new file mode 100644 index 0000000..43be100 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicSleepTest.php @@ -0,0 +1,55 @@ + + * @license MIT + */ +class MagicSleepTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSleep::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $initMethod->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $magicSleep = new MagicSleep($reflection, $initializer, $initMethod); + + $this->assertSame('__sleep', $magicSleep->getName()); + $this->assertCount(0, $magicSleep->getParameters()); + $this->assertSame( + "\$this->foo && \$this->bar('__sleep', array());" + . "\n\nreturn array_keys((array) \$this);", + $magicSleep->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicUnsetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicUnsetTest.php new file mode 100644 index 0000000..3c202f6 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicUnsetTest.php @@ -0,0 +1,122 @@ + + * @license MIT + */ +class MagicUnsetTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + protected $initializer; + + /** + * @var \Zend\Code\Generator\MethodGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + protected $initMethod; + + /** + * @var \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap|\PHPUnit_Framework_MockObject_MockObject + */ + protected $publicProperties; + + /** + * {@inheritDoc} + */ + protected function setUp() + { + $this->initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $this->initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator'); + $this->publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $this->initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $this->initMethod->expects($this->any())->method('getName')->will($this->returnValue('baz')); + $this->publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + $this->publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar')); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $magicIsset = new MagicUnset($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__unset', $magicIsset->getName()); + $this->assertCount(1, $magicIsset->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->baz('__unset', array('name' => \$name));\n\n" + . "if (isset(self::\$bar[\$name])) {\n unset(\$this->\$name);\n\n return;\n}" + . "%areturn %s;", + $magicIsset->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset::__construct + */ + public function testBodyStructureWithPublicProperties() + { + $reflection = new ReflectionClass( + 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' + ); + + $magicIsset = new MagicUnset($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__unset', $magicIsset->getName()); + $this->assertCount(1, $magicIsset->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->baz('__unset', array('name' => \$name));\n\n" + . "if (isset(self::\$bar[\$name])) {\n unset(\$this->\$name);\n\n return;\n}" + . "%areturn %s;", + $magicIsset->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset::__construct + */ + public function testBodyStructureWithOverriddenMagicGet() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); + $magicIsset = new MagicUnset($reflection, $this->initializer, $this->initMethod, $this->publicProperties); + + $this->assertSame('__unset', $magicIsset->getName()); + $this->assertCount(1, $magicIsset->getParameters()); + $this->assertSame( + "\$this->foo && \$this->baz('__unset', array('name' => \$name));\n\n" + . "if (isset(self::\$bar[\$name])) {\n unset(\$this->\$name);\n\n return;\n}\n\n" + . "return parent::__unset(\$name);", + $magicIsset->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializerTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializerTest.php new file mode 100644 index 0000000..c5bdb19 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializerTest.php @@ -0,0 +1,54 @@ + + * @license MIT + */ +class SetProxyInitializerTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\SetProxyInitializer::__construct + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $setter = new SetProxyInitializer($initializer); + $parameters = $setter->getParameters(); + + $this->assertSame('setProxyInitializer', $setter->getName()); + $this->assertCount(1, $parameters); + + /* @var $initializer \ProxyManager\Generator\ParameterGenerator */ + $initializer = array_shift($parameters); + + $this->assertInstanceOf('ProxyManager\\Generator\\ParameterGenerator', $initializer); + $this->assertSame('initializer', $initializer->getName()); + $this->assertSame('$this->foo = $initializer;', $setter->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializationTrackerTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializationTrackerTest.php new file mode 100644 index 0000000..83eacbc --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializationTrackerTest.php @@ -0,0 +1,41 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializationTracker + */ +class InitializationTrackerTest extends AbstractUniquePropertyNameTest +{ + /** + * {@inheritDoc} + */ + protected function createProperty() + { + return new InitializationTracker(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializerPropertyTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializerPropertyTest.php new file mode 100644 index 0000000..c7ef258 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializerPropertyTest.php @@ -0,0 +1,41 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializerProperty + */ +class InitializerPropertyTest extends AbstractUniquePropertyNameTest +{ + /** + * {@inheritDoc} + */ + protected function createProperty() + { + return new InitializerProperty(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhostGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhostGeneratorTest.php new file mode 100644 index 0000000..ca1b349 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhostGeneratorTest.php @@ -0,0 +1,48 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator + */ +class LazyLoadingGhostGeneratorTest extends AbstractProxyGeneratorTest +{ + /** + * {@inheritDoc} + */ + protected function getProxyGenerator() + { + return new LazyLoadingGhostGenerator(); + } + + /** + * {@inheritDoc} + */ + protected function getExpectedImplementedInterfaces() + { + return array('ProxyManager\\Proxy\\GhostObjectInterface'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/ConstructorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/ConstructorTest.php new file mode 100644 index 0000000..e914305 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/ConstructorTest.php @@ -0,0 +1,67 @@ + + * @license MIT + */ +class ConstructorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\Constructor::__construct + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $reflection = new ReflectionClass( + 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' + ); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $constructor = new Constructor($reflection, $initializer); + + $this->assertSame('__construct', $constructor->getName()); + $this->assertCount(1, $constructor->getParameters()); + $this->assertSame("unset(\$this->bar, \$this->baz);\n\n\$this->foo = \$initializer;", $constructor->getBody()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\Constructor::__construct + */ + public function testBodyStructureWithoutPublicProperties() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $constructor = new Constructor(new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'), $initializer); + + $this->assertSame('__construct', $constructor->getName()); + $this->assertCount(1, $constructor->getParameters()); + $this->assertSame("\$this->foo = \$initializer;", $constructor->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/GetProxyInitializerTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/GetProxyInitializerTest.php new file mode 100644 index 0000000..4059640 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/GetProxyInitializerTest.php @@ -0,0 +1,47 @@ + + * @license MIT + */ +class GetProxyInitializerTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\GetProxyInitializer::__construct + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $getter = new GetProxyInitializer($initializer); + + $this->assertSame('getProxyInitializer', $getter->getName()); + $this->assertCount(0, $getter->getParameters()); + $this->assertSame('return $this->foo;', $getter->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/InitializeProxyTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/InitializeProxyTest.php new file mode 100644 index 0000000..cd39fdb --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/InitializeProxyTest.php @@ -0,0 +1,52 @@ + + * @license MIT + */ +class InitializeProxyTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\InitializeProxy::__construct + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $initializeProxy = new InitializeProxy($initializer, $valueHolder); + + $this->assertSame('initializeProxy', $initializeProxy->getName()); + $this->assertCount(0, $initializeProxy->getParameters()); + $this->assertSame( + 'return $this->foo && $this->foo->__invoke($this->bar, $this, \'initializeProxy\', array(), $this->foo);', + $initializeProxy->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/IsProxyInitializedTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/IsProxyInitializedTest.php new file mode 100644 index 0000000..e6823b6 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/IsProxyInitializedTest.php @@ -0,0 +1,47 @@ + + * @license MIT + */ +class IsProxyInitializedTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\IsProxyInitialized::__construct + */ + public function testBodyStructure() + { + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $isProxyInitialized = new IsProxyInitialized($valueHolder); + + $this->assertSame('isProxyInitialized', $isProxyInitialized->getName()); + $this->assertCount(0, $isProxyInitialized->getParameters()); + $this->assertSame('return null !== $this->bar;', $isProxyInitialized->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/LazyLoadingMethodInterceptorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/LazyLoadingMethodInterceptorTest.php new file mode 100644 index 0000000..be2ff40 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/LazyLoadingMethodInterceptorTest.php @@ -0,0 +1,82 @@ + + * @license MIT + */ +class LazyLoadingMethodInterceptorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $reflection = new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceParameterMethod'); + $method = LazyLoadingMethodInterceptor::generateMethod($reflection, $initializer, $valueHolder); + + $this->assertSame('publicByReferenceParameterMethod', $method->getName()); + $this->assertCount(2, $method->getParameters()); + $this->assertSame( + "\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, 'publicByReferenceParameterMethod', " + . "array('param' => \$param, 'byRefParam' => \$byRefParam), \$this->foo);\n\n" + . "return \$this->bar->publicByReferenceParameterMethod(\$param, \$byRefParam);", + $method->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor + */ + public function testBodyStructureWithoutParameters() + { + $reflectionMethod = new MethodReflection(__CLASS__, 'testBodyStructureWithoutParameters'); + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $method = LazyLoadingMethodInterceptor::generateMethod($reflectionMethod, $initializer, $valueHolder); + + $this->assertSame('testBodyStructureWithoutParameters', $method->getName()); + $this->assertCount(0, $method->getParameters()); + $this->assertSame( + "\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, " + . "'testBodyStructureWithoutParameters', array(), \$this->foo);\n\n" + . "return \$this->bar->testBodyStructureWithoutParameters();", + $method->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicCloneTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicCloneTest.php new file mode 100644 index 0000000..44b9cb9 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicCloneTest.php @@ -0,0 +1,55 @@ + + * @license MIT + */ +class MagicCloneTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicClone::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $magicClone = new MagicClone($reflection, $initializer, $valueHolder); + + $this->assertSame('__clone', $magicClone->getName()); + $this->assertCount(0, $magicClone->getParameters()); + $this->assertSame( + "\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, " + . "'__clone', array(), \$this->foo);\n\n\$this->bar = clone \$this->bar;", + $magicClone->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGetTest.php new file mode 100644 index 0000000..442c95e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicGetTest.php @@ -0,0 +1,63 @@ + + * @license MIT + */ +class MagicGetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicGet::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + $publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + $publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $magicGet = new MagicGet($reflection, $initializer, $valueHolder, $publicProperties); + + $this->assertSame('__get', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, '__get', array('name' => \$name)" + . ", \$this->foo);\n\n" + . "if (isset(self::\$bar[\$name])) {\n return \$this->bar->\$name;\n}" + . "%areturn %s;", + $magicGet->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicIssetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicIssetTest.php new file mode 100644 index 0000000..a3ed157 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicIssetTest.php @@ -0,0 +1,63 @@ + + * @license MIT + */ +class MagicIssetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicIsset::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + $publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + $publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $magicIsset = new MagicIsset($reflection, $initializer, $valueHolder, $publicProperties); + + $this->assertSame('__isset', $magicIsset->getName()); + $this->assertCount(1, $magicIsset->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, '__isset', array('name' => \$name)" + . ", \$this->foo);\n\n" + . "if (isset(self::\$bar[\$name])) {\n return isset(\$this->bar->\$name);\n}" + . "%areturn %s;", + $magicIsset->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSetTest.php new file mode 100644 index 0000000..f8edc38 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSetTest.php @@ -0,0 +1,63 @@ + + * @license MIT + */ +class MagicSetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSet::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + $publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + $publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $magicSet = new MagicSet($reflection, $initializer, $valueHolder, $publicProperties); + + $this->assertSame('__set', $magicSet->getName()); + $this->assertCount(2, $magicSet->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, " + . "'__set', array('name' => \$name, 'value' => \$value), \$this->foo);\n\n" + . "if (isset(self::\$bar[\$name])) {\n return (\$this->bar->\$name = \$value);\n}" + . "%areturn %s;", + $magicSet->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleepTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleepTest.php new file mode 100644 index 0000000..d156041 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicSleepTest.php @@ -0,0 +1,55 @@ + + * @license MIT + */ +class MagicSleepTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSleep::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $magicSleep = new MagicSleep($reflection, $initializer, $valueHolder); + + $this->assertSame('__sleep', $magicSleep->getName()); + $this->assertCount(0, $magicSleep->getParameters()); + $this->assertSame( + "\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, '__sleep', array(), \$this->foo);" + . "\n\nreturn array('bar');", + $magicSleep->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicUnsetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicUnsetTest.php new file mode 100644 index 0000000..5d8e843 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/MagicUnsetTest.php @@ -0,0 +1,63 @@ + + * @license MIT + */ +class MagicUnsetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicUnset::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $publicProperties = $this + ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap') + ->disableOriginalConstructor() + ->getMock(); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + $publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false)); + $publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $magicIsset = new MagicUnset($reflection, $initializer, $valueHolder, $publicProperties); + + $this->assertSame('__unset', $magicIsset->getName()); + $this->assertCount(1, $magicIsset->getParameters()); + $this->assertStringMatchesFormat( + "\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, '__unset', array('name' => \$name)" + . ", \$this->foo);\n\n" + . "if (isset(self::\$bar[\$name])) {\n unset(\$this->bar->\$name);\n\n return;\n}" + . "%areturn %s;", + $magicIsset->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializerTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializerTest.php new file mode 100644 index 0000000..0bd1735 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializerTest.php @@ -0,0 +1,54 @@ + + * @license MIT + */ +class SetProxyInitializerTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\SetProxyInitializer::__construct + */ + public function testBodyStructure() + { + $initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $initializer->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $setter = new SetProxyInitializer($initializer); + $parameters = $setter->getParameters(); + + $this->assertSame('setProxyInitializer', $setter->getName()); + $this->assertCount(1, $parameters); + + /* @var $initializer \ProxyManager\Generator\ParameterGenerator */ + $initializer = array_shift($parameters); + + $this->assertInstanceOf('ProxyManager\\Generator\\ParameterGenerator', $initializer); + $this->assertSame('initializer', $initializer->getName()); + $this->assertSame('$this->foo = $initializer;', $setter->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/InitializerPropertyTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/InitializerPropertyTest.php new file mode 100644 index 0000000..4878504 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/InitializerPropertyTest.php @@ -0,0 +1,41 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\InitializerProperty + */ +class InitializerPropertyTest extends AbstractUniquePropertyNameTest +{ + /** + * {@inheritDoc} + */ + protected function createProperty() + { + return new InitializerProperty(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/ValueHolderPropertyTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/ValueHolderPropertyTest.php new file mode 100644 index 0000000..9033d0e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolder/PropertyGenerator/ValueHolderPropertyTest.php @@ -0,0 +1,41 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\ValueHolderProperty + */ +class ValueHolderPropertyTest extends AbstractUniquePropertyNameTest +{ + /** + * {@inheritDoc} + */ + protected function createProperty() + { + return new ValueHolderProperty(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolderGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolderGeneratorTest.php new file mode 100644 index 0000000..a9a3e6c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingValueHolderGeneratorTest.php @@ -0,0 +1,48 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator + */ +class LazyLoadingValueHolderGeneratorTest extends AbstractProxyGeneratorTest +{ + /** + * {@inheritDoc} + */ + protected function getProxyGenerator() + { + return new LazyLoadingValueHolderGenerator(); + } + + /** + * {@inheritDoc} + */ + protected function getExpectedImplementedInterfaces() + { + return array('ProxyManager\\Proxy\\VirtualProxyInterface'); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/ConstructorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/ConstructorTest.php new file mode 100644 index 0000000..8044a0b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/ConstructorTest.php @@ -0,0 +1,62 @@ + + * @license MIT + */ +class ConstructorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\Constructor::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMixedProperties'); + $constructor = new Constructor($reflection); + + $this->assertSame('__construct', $constructor->getName()); + $this->assertCount(0, $constructor->getParameters()); + $this->assertSame( + "\$this->publicProperty0 = null;\n\$this->publicProperty1 = null;\n\$this->publicProperty2 = null;", + $constructor->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\Constructor::__construct + */ + public function testBodyStructureWithoutPublicProperties() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithPrivateProperties'); + $constructor = new Constructor($reflection); + + $this->assertSame('__construct', $constructor->getName()); + $this->assertCount(0, $constructor->getParameters()); + $body = $constructor->getBody(); + $this->assertTrue(empty($body)); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptorTest.php new file mode 100644 index 0000000..b84b0e8 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptorTest.php @@ -0,0 +1,73 @@ + + * @license MIT + */ +class NullObjectMethodInterceptorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor + */ + public function testBodyStructure() + { + $reflection = new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceParameterMethod'); + $method = NullObjectMethodInterceptor::generateMethod($reflection); + + $this->assertSame('publicByReferenceParameterMethod', $method->getName()); + $this->assertCount(2, $method->getParameters()); + $this->assertSame("", $method->getBody()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor + */ + public function testBodyStructureWithoutParameters() + { + $reflectionMethod = new MethodReflection(__CLASS__, 'testBodyStructureWithoutParameters'); + + $method = NullObjectMethodInterceptor::generateMethod($reflectionMethod); + + $this->assertSame('testBodyStructureWithoutParameters', $method->getName()); + $this->assertCount(0, $method->getParameters()); + $this->assertSame("", $method->getBody()); + } + + /** + * @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor + */ + public function testBodyStructureWithoutByRefReturn() + { + $reflectionMethod = new MethodReflection('ProxyManagerTestAsset\BaseClass', 'publicByReferenceMethod'); + + $method = NullObjectMethodInterceptor::generateMethod($reflectionMethod); + + $this->assertSame('publicByReferenceMethod', $method->getName()); + $this->assertCount(0, $method->getParameters()); + $this->assertStringMatchesFormat("\$ref%s = null;\nreturn \$ref%s;", $method->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php new file mode 100644 index 0000000..6eb0d26 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php @@ -0,0 +1,116 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\NullObjectGenerator + */ +class NullObjectGeneratorTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getTestedImplementations + * + * Verifies that generated code is valid and implements expected interfaces + */ + public function testGeneratesValidCode($className) + { + $generator = $this->getProxyGenerator(); + $generatedClassName = UniqueIdentifierGenerator::getIdentifier('AbstractProxyGeneratorTest'); + $generatedClass = new ClassGenerator($generatedClassName); + $originalClass = new ReflectionClass($className); + $generatorStrategy = new EvaluatingGeneratorStrategy(); + + $generator->generate($originalClass, $generatedClass); + $generatorStrategy->generate($generatedClass); + + $generatedReflection = new ReflectionClass($generatedClassName); + + if ($originalClass->isInterface()) { + $this->assertTrue($generatedReflection->implementsInterface($className)); + } else { + $this->assertEmpty( + array_diff($originalClass->getInterfaceNames(), $generatedReflection->getInterfaceNames()) + ); + } + + $this->assertSame($generatedClassName, $generatedReflection->getName()); + + foreach ($this->getExpectedImplementedInterfaces() as $interface) { + $this->assertTrue($generatedReflection->implementsInterface($interface)); + } + + $proxyGenerated = new $generatedClassName(); + + foreach ($generatedReflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { + $this->assertNull($proxyGenerated->$property); + } + + /** @var \ReflectionMethod $method */ + foreach ($generatedReflection->getMethods(ReflectionProperty::IS_PUBLIC) as $method) { + if ($method->getNumberOfParameters() == 0) { + $this->assertNull(call_user_func(array($proxyGenerated, $method->getName()))); + } + } + } + + /** + * {@inheritDoc} + */ + protected function getProxyGenerator() + { + return new NullObjectGenerator(); + } + + /** + * {@inheritDoc} + */ + protected function getExpectedImplementedInterfaces() + { + return array( + 'ProxyManager\\Proxy\\NullObjectInterface', + ); + } + + /** + * @return array + */ + public function getTestedImplementations() + { + return array( + array('ProxyManagerTestAsset\\BaseClass'), + array('ProxyManagerTestAsset\\ClassWithMagicMethods'), + array('ProxyManagerTestAsset\\ClassWithByRefMagicMethods'), + array('ProxyManagerTestAsset\\ClassWithMixedProperties'), + array('ProxyManagerTestAsset\\BaseInterface'), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/AbstractUniquePropertyNameTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/AbstractUniquePropertyNameTest.php new file mode 100644 index 0000000..4f63271 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/AbstractUniquePropertyNameTest.php @@ -0,0 +1,47 @@ + + * @license MIT + */ +abstract class AbstractUniquePropertyNameTest extends PHPUnit_Framework_TestCase +{ + /** + * Verifies that a given property name is unique across two different instantiations of the property + */ + public function testUniqueProperty() + { + $property1 = $this->createProperty(); + $property2 = $this->createProperty(); + + $this->assertSame($property1->getName(), $property1->getName()); + $this->assertNotEquals($property1->getName(), $property2->getName()); + } + + /** + * @return \Zend\Code\Generator\PropertyGenerator + */ + abstract protected function createProperty(); +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/PublicPropertiesDefaultsTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/PublicPropertiesDefaultsTest.php new file mode 100644 index 0000000..0dfd930 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/PublicPropertiesDefaultsTest.php @@ -0,0 +1,71 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesDefaults + */ +class PublicPropertiesDefaultsTest extends PHPUnit_Framework_TestCase +{ + public function testEmptyClass() + { + $publicProperties = new PublicPropertiesDefaults(new ReflectionClass('ProxyManagerTestAsset\\EmptyClass')); + + $this->assertInternalType('array', $publicProperties->getDefaultValue()->getValue()); + $this->assertEmpty($publicProperties->getDefaultValue()->getValue()); + $this->assertTrue($publicProperties->isStatic()); + $this->assertSame(PublicPropertiesDefaults::VISIBILITY_PRIVATE, $publicProperties->getVisibility()); + } + + public function testClassWithPublicProperties() + { + $publicProperties = new PublicPropertiesDefaults( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithPublicProperties') + ); + + $this->assertInternalType('array', $publicProperties->getDefaultValue()->getValue()); + $this->assertCount(10, $publicProperties->getDefaultValue()->getValue()); + $this->assertTrue($publicProperties->isStatic()); + $this->assertSame(PublicPropertiesDefaults::VISIBILITY_PRIVATE, $publicProperties->getVisibility()); + } + + public function testBaseClass() + { + $publicProperties = new PublicPropertiesDefaults( + new ReflectionClass('ProxyManagerTestAsset\\BaseClass') + ); + + $this->assertInternalType('array', $publicProperties->getDefaultValue()->getValue()); + $this->assertSame( + array('publicProperty' => 'publicPropertyDefault'), + $publicProperties->getDefaultValue()->getValue() + ); + $this->assertTrue($publicProperties->isStatic()); + $this->assertSame(PublicPropertiesDefaults::VISIBILITY_PRIVATE, $publicProperties->getVisibility()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/PublicPropertiesMapTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/PublicPropertiesMapTest.php new file mode 100644 index 0000000..38b3ac0 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/PublicPropertiesMapTest.php @@ -0,0 +1,58 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap + */ +class PublicPropertiesMapTest extends PHPUnit_Framework_TestCase +{ + public function testEmptyClass() + { + $publicProperties = new PublicPropertiesMap(new ReflectionClass('ProxyManagerTestAsset\\EmptyClass')); + + $this->assertInternalType('array', $publicProperties->getDefaultValue()->getValue()); + $this->assertEmpty($publicProperties->getDefaultValue()->getValue()); + $this->assertTrue($publicProperties->isStatic()); + $this->assertSame('private', $publicProperties->getVisibility()); + $this->assertTrue($publicProperties->isEmpty()); + } + + public function testClassWithPublicProperties() + { + $publicProperties = new PublicPropertiesMap( + new ReflectionClass('ProxyManagerTestAsset\\ClassWithPublicProperties') + ); + + $this->assertInternalType('array', $publicProperties->getDefaultValue()->getValue()); + $this->assertCount(10, $publicProperties->getDefaultValue()->getValue()); + $this->assertTrue($publicProperties->isStatic()); + $this->assertSame('private', $publicProperties->getVisibility()); + $this->assertFalse($publicProperties->isEmpty()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/ConstructorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/ConstructorTest.php new file mode 100644 index 0000000..ede0aa7 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/ConstructorTest.php @@ -0,0 +1,52 @@ + + * @license MIT + */ +class ConstructorTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\Constructor::__construct + */ + public function testBodyStructure() + { + $adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $adapter->expects($this->any())->method('getName')->will($this->returnValue('adapter')); + + $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMixedProperties'); + $constructor = new Constructor($reflection, $adapter); + + $this->assertSame('__construct', $constructor->getName()); + $this->assertCount(1, $constructor->getParameters()); + $this->assertSame( + "\$this->adapter = \$adapter;\nunset(\$this->publicProperty0);" + . "\nunset(\$this->publicProperty1);\nunset(\$this->publicProperty2);", + $constructor->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicGetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicGetTest.php new file mode 100644 index 0000000..e7dcac8 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicGetTest.php @@ -0,0 +1,52 @@ + + * @license MIT + */ +class MagicGetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicGet::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $adapter->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $magicGet = new MagicGet($reflection, $adapter); + + $this->assertSame('__get', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat( + '$return = $this->foo->call(\'ProxyManagerTestAsset\\\EmptyClass\', \'__get\', array($name));' + . "\n\nreturn \$return;", + $magicGet->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicIssetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicIssetTest.php new file mode 100644 index 0000000..0253b8c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicIssetTest.php @@ -0,0 +1,52 @@ + + * @license MIT + */ +class MagicIssetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicIsset::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $adapter->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $magicGet = new MagicIsset($reflection, $adapter); + + $this->assertSame('__isset', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat( + '$return = $this->foo->call(\'ProxyManagerTestAsset\\\EmptyClass\', \'__isset\', array($name));' + . "\n\nreturn \$return;", + $magicGet->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicSetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicSetTest.php new file mode 100644 index 0000000..14b53c8 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicSetTest.php @@ -0,0 +1,52 @@ + + * @license MIT + */ +class MagicSetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicSet::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $adapter->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $magicGet = new MagicSet($reflection, $adapter); + + $this->assertSame('__set', $magicGet->getName()); + $this->assertCount(2, $magicGet->getParameters()); + $this->assertStringMatchesFormat( + '$return = $this->foo->call(\'ProxyManagerTestAsset\\\EmptyClass\', \'__set\', array($name, $value));' + . "\n\nreturn \$return;", + $magicGet->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicUnsetTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicUnsetTest.php new file mode 100644 index 0000000..c4ffb21 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/MagicUnsetTest.php @@ -0,0 +1,52 @@ + + * @license MIT + */ +class MagicUnsetTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicUnset::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $adapter->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $magicGet = new MagicUnset($reflection, $adapter); + + $this->assertSame('__unset', $magicGet->getName()); + $this->assertCount(1, $magicGet->getParameters()); + $this->assertStringMatchesFormat( + '$return = $this->foo->call(\'ProxyManagerTestAsset\\\EmptyClass\', \'__unset\', array($name));' + . "\n\nreturn \$return;", + $magicGet->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/RemoteObjectMethodTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/RemoteObjectMethodTest.php new file mode 100644 index 0000000..6e72166 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/MethodGenerator/RemoteObjectMethodTest.php @@ -0,0 +1,114 @@ + + * @license MIT + */ +class RemoteObjectMethodTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod + */ + public function testBodyStructureWithParameters() + { + $adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $adapter->expects($this->any())->method('getName')->will($this->returnValue('adapter')); + + $reflectionMethod = new MethodReflection( + 'ProxyManagerTestAsset\\BaseClass', + 'publicByReferenceParameterMethod' + ); + + $method = RemoteObjectMethod::generateMethod( + $reflectionMethod, + $adapter, + new ReflectionClass('Zend\\Code\\Generator\\PropertyGenerator') + ); + + $this->assertSame('publicByReferenceParameterMethod', $method->getName()); + $this->assertCount(2, $method->getParameters()); + $this->assertSame( + '$return = $this->adapter->call(\'Zend\\\Code\\\Generator\\\PropertyGenerator\', ' + . '\'publicByReferenceParameterMethod\', array($param, $byRefParam));' + . "\n\nreturn \$return;", + $method->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod + */ + public function testBodyStructureWithArrayParameter() + { + $adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $adapter->expects($this->any())->method('getName')->will($this->returnValue('adapter')); + + $reflectionMethod = new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicArrayHintedMethod'); + + $method = RemoteObjectMethod::generateMethod( + $reflectionMethod, + $adapter, + new ReflectionClass('Zend\\Code\\Generator\\PropertyGenerator') + ); + + $this->assertSame('publicArrayHintedMethod', $method->getName()); + $this->assertCount(1, $method->getParameters()); + $this->assertSame( + '$return = $this->adapter->call(\'Zend\\\Code\\\Generator\\\PropertyGenerator\', ' + . '\'publicArrayHintedMethod\', array($param));' + . "\n\nreturn \$return;", + $method->getBody() + ); + } + + /** + * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod + */ + public function testBodyStructureWithoutParameters() + { + $adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + $adapter->expects($this->any())->method('getName')->will($this->returnValue('adapter')); + + $reflectionMethod = new MethodReflection(__CLASS__, 'testBodyStructureWithoutParameters'); + + $method = RemoteObjectMethod::generateMethod( + $reflectionMethod, + $adapter, + new ReflectionClass('Zend\\Code\\Generator\\PropertyGenerator') + ); + + $this->assertSame('testBodyStructureWithoutParameters', $method->getName()); + $this->assertCount(0, $method->getParameters()); + $this->assertSame( + '$return = $this->adapter->call(\'Zend\\\Code\\\Generator\\\PropertyGenerator\', ' + . '\'testBodyStructureWithoutParameters\', array());' + . "\n\nreturn \$return;", + $method->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/PropertyGenerator/AdapterPropertyTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/PropertyGenerator/AdapterPropertyTest.php new file mode 100644 index 0000000..b19a8ae --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObject/PropertyGenerator/AdapterPropertyTest.php @@ -0,0 +1,41 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty + */ +class AdapterPropertyTest extends AbstractUniquePropertyNameTest +{ + /** + * {@inheritDoc} + */ + protected function createProperty() + { + return new AdapterProperty(); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObjectGeneratorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObjectGeneratorTest.php new file mode 100644 index 0000000..958a9da --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObjectGeneratorTest.php @@ -0,0 +1,102 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\RemoteObjectGenerator + */ +class RemoteObjectGeneratorTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getTestedImplementations + * + * Verifies that generated code is valid and implements expected interfaces + */ + public function testGeneratesValidCode($className) + { + $generator = $this->getProxyGenerator(); + $generatedClassName = UniqueIdentifierGenerator::getIdentifier('AbstractProxyGeneratorTest'); + $generatedClass = new ClassGenerator($generatedClassName); + $originalClass = new ReflectionClass($className); + $generatorStrategy = new EvaluatingGeneratorStrategy(); + + $generator->generate($originalClass, $generatedClass); + $generatorStrategy->generate($generatedClass); + + $generatedReflection = new ReflectionClass($generatedClassName); + + if ($originalClass->isInterface()) { + $this->assertTrue($generatedReflection->implementsInterface($className)); + } else { + $this->assertEmpty( + array_diff($originalClass->getInterfaceNames(), $generatedReflection->getInterfaceNames()) + ); + } + + $this->assertSame($generatedClassName, $generatedReflection->getName()); + + foreach ($this->getExpectedImplementedInterfaces() as $interface) { + $this->assertTrue($generatedReflection->implementsInterface($interface)); + } + } + + /** + * {@inheritDoc} + */ + protected function getProxyGenerator() + { + return new RemoteObjectGenerator(); + } + + /** + * {@inheritDoc} + */ + protected function getExpectedImplementedInterfaces() + { + return array( + 'ProxyManager\\Proxy\\RemoteObjectInterface', + ); + } + + /** + * @return array + */ + public function getTestedImplementations() + { + return array( + array('ProxyManagerTestAsset\\BaseClass'), + array('ProxyManagerTestAsset\\ClassWithMagicMethods'), + array('ProxyManagerTestAsset\\ClassWithByRefMagicMethods'), + array('ProxyManagerTestAsset\\ClassWithMixedProperties'), + array('ProxyManagerTestAsset\\BaseInterface'), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/Util/ProxiedMethodsFilterTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/Util/ProxiedMethodsFilterTest.php new file mode 100644 index 0000000..3f2d91b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/Util/ProxiedMethodsFilterTest.php @@ -0,0 +1,113 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter + */ +class ProxiedMethodsFilterTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider expectedMethods + */ + public function testFiltering(ReflectionClass $reflectionClass, $excludes, array $expectedMethods) + { + if (is_array($excludes)) { + $filtered = ProxiedMethodsFilter::getProxiedMethods($reflectionClass, $excludes); + } else { + $filtered = ProxiedMethodsFilter::getProxiedMethods($reflectionClass); + } + + foreach ($filtered as $method) { + $this->assertInstanceOf('ReflectionMethod', $method); + } + + $keys = array_map( + function (ReflectionMethod $method) { + return $method->getName(); + }, + $filtered + ); + + sort($keys); + sort($expectedMethods); + + $this->assertSame($keys, $expectedMethods); + } + + /** + * @return array[][] + */ + public function expectedMethods() + { + return array( + array( + new ReflectionClass('ProxyManagerTestAsset\\BaseClass'), + null, + array( + 'publicArrayHintedMethod', + 'publicByReferenceMethod', + 'publicByReferenceParameterMethod', + 'publicMethod', + 'publicTypeHintedMethod', + ), + ), + array( + new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'), + null, + array(), + ), + array( + new ReflectionClass('ProxyManagerTestAsset\\LazyLoadingMock'), + null, + array(), + ), + array( + new ReflectionClass('ProxyManagerTestAsset\\LazyLoadingMock'), + array(), + array(), + ), + array( + new ReflectionClass('ProxyManagerTestAsset\\HydratedObject'), + array('doFoo'), + array('__get'), + ), + array( + new ReflectionClass('ProxyManagerTestAsset\\HydratedObject'), + array('Dofoo'), + array('__get'), + ), + array( + new ReflectionClass('ProxyManagerTestAsset\\HydratedObject'), + array(), + array('doFoo', '__get'), + ), + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/Util/PublicScopeSimulatorTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/Util/PublicScopeSimulatorTest.php new file mode 100644 index 0000000..2a75405 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/Util/PublicScopeSimulatorTest.php @@ -0,0 +1,132 @@ + + * @license MIT + * + * @covers \ProxyManager\ProxyGenerator\Util\PublicScopeSimulator + */ +class PublicScopeSimulatorTest extends PHPUnit_Framework_TestCase +{ + public function testSimpleGet() + { + $code = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_GET, + 'foo', + null, + null, + 'bar' + ); + + $this->assertStringMatchesFormat('%a{%areturn $%s->$foo;%a}%a$bar = %s;', $code); + } + + public function testSimpleSet() + { + $code = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_SET, + 'foo', + 'baz', + null, + 'bar' + ); + + $this->assertStringMatchesFormat('%a{%areturn $%s->$foo = $baz;%a}%a$bar = %s;', $code); + } + + public function testSimpleIsset() + { + $code = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_ISSET, + 'foo', + null, + null, + 'bar' + ); + + $this->assertStringMatchesFormat('%a{%areturn isset($%s->$foo);%a}%a$bar = %s;', $code); + } + + public function testSimpleUnset() + { + $code = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_UNSET, + 'foo', + null, + null, + 'bar' + ); + + $this->assertStringMatchesFormat('%a{%aunset($%s->$foo);%a}%a$bar = %s;', $code); + } + + public function testSetRequiresValueParameterName() + { + $this->setExpectedException('InvalidArgumentException'); + + PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_SET, + 'foo', + null, + null, + 'bar' + ); + } + + public function testDelegatesToValueHolderWhenAvailable() + { + $code = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_SET, + 'foo', + 'baz', + new PropertyGenerator('valueHolder'), + 'bar' + ); + + $this->assertStringMatchesFormat( + '%A$targetObject = $this->valueHolder;%a{%areturn $%s->$foo = $baz;%a}%a$bar = %s;', + $code + ); + } + + public function testSetRequiresValidOperation() + { + $this->setExpectedException('InvalidArgumentException'); + + PublicScopeSimulator::getPublicAccessSimulationCode('invalid', 'foo'); + } + + public function testWillReturnDirectlyWithNoReturnParam() + { + $code = PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_GET, + 'foo' + ); + + $this->assertStringMatchesFormat('%a{%areturn $%s->$foo;%a}%areturn %s;', $code); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/ValueHolder/MethodGenerator/GetWrappedValueHolderValueTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/ValueHolder/MethodGenerator/GetWrappedValueHolderValueTest.php new file mode 100644 index 0000000..e4a1108 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/ValueHolder/MethodGenerator/GetWrappedValueHolderValueTest.php @@ -0,0 +1,47 @@ + + * @license MIT + */ +class GetWrappedValueHolderValueTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue::__construct + */ + public function testBodyStructure() + { + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo')); + + $getter = new GetWrappedValueHolderValue($valueHolder); + + $this->assertSame('getWrappedValueHolderValue', $getter->getName()); + $this->assertCount(0, $getter->getParameters()); + $this->assertSame('return $this->foo;', $getter->getBody()); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/ValueHolder/MethodGenerator/MagicSleepTest.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/ValueHolder/MethodGenerator/MagicSleepTest.php new file mode 100644 index 0000000..d5038c6 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/ValueHolder/MethodGenerator/MagicSleepTest.php @@ -0,0 +1,52 @@ + + * @license MIT + */ +class MagicSleepTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers \ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\MagicSleep::__construct + */ + public function testBodyStructure() + { + $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); + $valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator'); + + $valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar')); + + $magicSleep = new MagicSleep($reflection, $valueHolder); + + $this->assertSame('__sleep', $magicSleep->getName()); + $this->assertCount(0, $magicSleep->getParameters()); + $this->assertSame( + "return array('bar');", + $magicSleep->getBody() + ); + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php new file mode 100644 index 0000000..8324d97 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php @@ -0,0 +1,55 @@ + + * @license MIT + */ +class AccessInterceptorValueHolderMock +{ + /** + * @var mixed + */ + public $instance; + + /** + * @var mixed + */ + public $prefixInterceptors; + + /** + * @var mixed + */ + public $suffixInterceptors; + + /** + * @param mixed $instance + * @param mixed $prefixInterceptors + * @param mixed $suffixInterceptors + */ + public function __construct($instance, $prefixInterceptors, $suffixInterceptors) + { + $this->instance = $instance; + $this->prefixInterceptors = $prefixInterceptors; + $this->suffixInterceptors = $suffixInterceptors; + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/BaseClass.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/BaseClass.php new file mode 100644 index 0000000..4d58a11 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/BaseClass.php @@ -0,0 +1,108 @@ + + * @license MIT + */ +class BaseClass implements BaseInterface +{ + /** + * @var string + */ + public $publicProperty = 'publicPropertyDefault'; + + /** + * @var string + */ + protected $protectedProperty = 'protectedPropertyDefault'; + + /** + * @var string + */ + private $privateProperty = 'privatePropertyDefault'; + + /** + * @return string + */ + public function publicMethod() + { + return 'publicMethodDefault'; + } + + /** + * @return string + */ + protected function protectedMethod() + { + return 'protectedMethodDefault'; + } + + /** + * @return string + */ + private function privateMethod() + { + return 'privateMethodDefault'; + } + + /** + * @param \stdClass $param + * + * @return string + */ + public function publicTypeHintedMethod(\stdClass $param) + { + return 'publicTypeHintedMethodDefault'; + } + + /** + * @param array $param + * + * @return string + */ + public function publicArrayHintedMethod(array $param) + { + return 'publicArrayHintedMethodDefault'; + } + + /** + * @return string + */ + public function & publicByReferenceMethod() + { + $returnValue = 'publicByReferenceMethodDefault'; + + return $returnValue; + } + + /** + * @param mixed $param + * @param mixed $byRefParam + * + * @return string + */ + public function publicByReferenceParameterMethod($param, & $byRefParam) + { + return 'publicByReferenceParameterMethodDefault'; + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/BaseInterface.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/BaseInterface.php new file mode 100644 index 0000000..8749a8d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/BaseInterface.php @@ -0,0 +1,33 @@ + + * @license MIT + */ +interface BaseInterface +{ + /** + * @return mixed + */ + public function publicMethod(); +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/CallableTypeHintClass.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/CallableTypeHintClass.php new file mode 100644 index 0000000..4a65595 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/CallableTypeHintClass.php @@ -0,0 +1,39 @@ + + * @license MIT + */ +class CallableTypeHintClass +{ + /** + * @param callable $parameter + * + * @return callable + */ + public function callableTypeHintMethod(callable $parameter) + { + return $parameter; + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithByRefMagicMethods.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithByRefMagicMethods.php new file mode 100644 index 0000000..6f0ab5d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithByRefMagicMethods.php @@ -0,0 +1,74 @@ + + * @license MIT + */ +class ClassWithByRefMagicMethods +{ + /** + * {@inheritDoc} + */ + public function & __set($name, $value) + { + return array($name => $value); + } + + /** + * {@inheritDoc} + */ + public function & __get($name) + { + return $name; + } + + /** + * {@inheritDoc} + */ + public function & __isset($name) + { + return (bool) $name; + } + + /** + * {@inheritDoc} + */ + public function & __unset($name) + { + return (bool) $name; + } + + /** + * {@inheritDoc} + */ + public function & __sleep() + { + } + + /** + * {@inheritDoc} + */ + public function & __wakeup() + { + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithMagicMethods.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithMagicMethods.php new file mode 100644 index 0000000..2bd26e5 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithMagicMethods.php @@ -0,0 +1,81 @@ + + * @license MIT + */ +class ClassWithMagicMethods +{ + /** + * {@inheritDoc} + */ + public function __set($name, $value) + { + return array($name => $value); + } + + /** + * {@inheritDoc} + */ + public function __get($name) + { + return $name; + } + + /** + * {@inheritDoc} + */ + public function __isset($name) + { + return (bool) $name; + } + + /** + * {@inheritDoc} + */ + public function __unset($name) + { + return (bool) $name; + } + + /** + * {@inheritDoc} + */ + public function __sleep() + { + } + + /** + * {@inheritDoc} + */ + public function __wakeup() + { + } + + /** + * {@inheritDoc} + */ + public function __clone() + { + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithMethodWithDefaultParameters.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithMethodWithDefaultParameters.php new file mode 100644 index 0000000..fa6134a --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithMethodWithDefaultParameters.php @@ -0,0 +1,38 @@ + + * @license MIT + */ +class ClassWithMethodWithDefaultParameters +{ + /** + * @param array $parameter + * + * @return string + */ + public function publicMethodWithDefaults(array $parameter = array('foo')) + { + return 'defaultValue'; + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithMixedProperties.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithMixedProperties.php new file mode 100644 index 0000000..3ebf27c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithMixedProperties.php @@ -0,0 +1,46 @@ + + * @license MIT + */ +class ClassWithMixedProperties +{ + public $publicProperty0 = 'publicProperty0'; + + public $publicProperty1 = 'publicProperty1'; + + public $publicProperty2 = 'publicProperty2'; + + protected $protectedProperty0 = 'protectedProperty0'; + + protected $protectedProperty1 = 'protectedProperty1'; + + protected $protectedProperty2 = 'protectedProperty2'; + + private $privateProperty0 = 'privateProperty0'; + + private $privateProperty1 = 'privateProperty1'; + + private $privateProperty2 = 'privateProperty2'; +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithPrivateProperties.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithPrivateProperties.php new file mode 100644 index 0000000..96a7a93 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithPrivateProperties.php @@ -0,0 +1,48 @@ + + * @license MIT + */ +class ClassWithPrivateProperties +{ + private $property0 = 'property0'; + + private $property1 = 'property1'; + + private $property2 = 'property2'; + + private $property3 = 'property3'; + + private $property4 = 'property4'; + + private $property5 = 'property5'; + + private $property6 = 'property6'; + + private $property7 = 'property7'; + + private $property8 = 'property8'; + + private $property9 = 'property9'; +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithProtectedProperties.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithProtectedProperties.php new file mode 100644 index 0000000..ad600d1 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithProtectedProperties.php @@ -0,0 +1,48 @@ + + * @license MIT + */ +class ClassWithProtectedProperties +{ + protected $property0 = 'property0'; + + protected $property1 = 'property1'; + + protected $property2 = 'property2'; + + protected $property3 = 'property3'; + + protected $property4 = 'property4'; + + protected $property5 = 'property5'; + + protected $property6 = 'property6'; + + protected $property7 = 'property7'; + + protected $property8 = 'property8'; + + protected $property9 = 'property9'; +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithPublicArrayProperty.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithPublicArrayProperty.php new file mode 100644 index 0000000..af68ceb --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithPublicArrayProperty.php @@ -0,0 +1,31 @@ + + * @license MIT + */ +class ClassWithPublicArrayProperty +{ + public $arrayProperty = array(); +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithPublicProperties.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithPublicProperties.php new file mode 100644 index 0000000..d36ea8c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ClassWithPublicProperties.php @@ -0,0 +1,48 @@ + + * @license MIT + */ +class ClassWithPublicProperties +{ + public $property0 = 'property0'; + + public $property1 = 'property1'; + + public $property2 = 'property2'; + + public $property3 = 'property3'; + + public $property4 = 'property4'; + + public $property5 = 'property5'; + + public $property6 = 'property6'; + + public $property7 = 'property7'; + + public $property8 = 'property8'; + + public $property9 = 'property9'; +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/EmptyClass.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/EmptyClass.php new file mode 100644 index 0000000..e74a0f7 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/EmptyClass.php @@ -0,0 +1,29 @@ + + * @license MIT + */ +class EmptyClass +{ +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/HydratedObject.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/HydratedObject.php new file mode 100644 index 0000000..198bf6c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/HydratedObject.php @@ -0,0 +1,60 @@ + + * @license MIT + */ +class HydratedObject +{ + /** + * @var mixed + */ + public $foo = 1; + + /** + * @var mixed + */ + protected $bar = 2; + + /** + * @var mixed + */ + private $baz = 3; + + /** + * Method to be disabled + */ + public function doFoo() + { + } + + /** + * @param string $name + * + * @return mixed + */ + public function __get($name) + { + return $this->$name; + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/LazyLoadingMock.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/LazyLoadingMock.php new file mode 100644 index 0000000..b199f8f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/LazyLoadingMock.php @@ -0,0 +1,41 @@ + + * @license MIT + */ +class LazyLoadingMock +{ + /** + * @var mixed + */ + public $initializer; + + /** + * @param mixed $initializer + */ + public function __construct($initializer) + { + $this->initializer = $initializer; + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/NullObjectMock.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/NullObjectMock.php new file mode 100644 index 0000000..b747f3b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/NullObjectMock.php @@ -0,0 +1,29 @@ + + * @license MIT + */ +class NullObjectMock +{ +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ProxyGenerator/LazyLoading/MethodGenerator/ClassWithTwoPublicProperties.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ProxyGenerator/LazyLoading/MethodGenerator/ClassWithTwoPublicProperties.php new file mode 100644 index 0000000..bb34b58 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/ProxyGenerator/LazyLoading/MethodGenerator/ClassWithTwoPublicProperties.php @@ -0,0 +1,38 @@ + + * @license MIT + */ +class ClassWithTwoPublicProperties +{ + /** + * @var mixed + */ + public $bar; + + /** + * @var mixed + */ + public $baz; +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/RemoteProxy/BazServiceInterface.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/RemoteProxy/BazServiceInterface.php new file mode 100644 index 0000000..08df058 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/RemoteProxy/BazServiceInterface.php @@ -0,0 +1,35 @@ + + * @license MIT + */ +interface BazServiceInterface +{ + /** + * @param string $param + * + * @return string + */ + public function baz($param); +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/RemoteProxy/Foo.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/RemoteProxy/Foo.php new file mode 100644 index 0000000..9304f70 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/RemoteProxy/Foo.php @@ -0,0 +1,56 @@ + + * @license MIT + */ +class Foo implements FooServiceInterface, BazServiceInterface +{ + /** + * @return string + */ + public function foo() + { + return 'bar remote'; + } + + /** + * @param string $param + * + * @return string + */ + public function baz($param) + { + return $param . ' remote'; + } + + /** + * @param string $name + * + * @return string + */ + public function __get($name) + { + return $name . ' remote'; + } +} diff --git a/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/RemoteProxy/FooServiceInterface.php b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/RemoteProxy/FooServiceInterface.php new file mode 100644 index 0000000..4894b21 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/ProxyManagerTestAsset/RemoteProxy/FooServiceInterface.php @@ -0,0 +1,33 @@ + + * @license MIT + */ +interface FooServiceInterface +{ + /** + * @return mixed + */ + public function foo(); +} diff --git a/core/vendor/ocramius/proxy-manager/tests/TestConfiguration.php.dist b/core/vendor/ocramius/proxy-manager/tests/TestConfiguration.php.dist new file mode 100644 index 0000000..3d0507e --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/TestConfiguration.php.dist @@ -0,0 +1,19 @@ +createProxy(new Kitchen()); + +var_dump(isset($proxy->sweets)); +?> +--EXPECT-- +bool(false) \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-private-property-read.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-private-property-read.phpt new file mode 100644 index 0000000..313312a --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-private-property-read.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated access interceptors disallow private property direct read +--FILE-- +createProxy(new Kitchen()); + +$proxy->sweets; +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-private-property-unset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-private-property-unset.phpt new file mode 100644 index 0000000..3f32a24 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-private-property-unset.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated access interceptors disallow private property direct unset +--FILE-- +createProxy(new Kitchen()); + +unset($proxy->sweets); +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-private-property-write.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-private-property-write.phpt new file mode 100644 index 0000000..b108ac2 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-private-property-write.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated access interceptors disallow private property direct write +--FILE-- +createProxy(new Kitchen()); + +$proxy->sweets = 'stolen'; +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-isset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-isset.phpt new file mode 100644 index 0000000..e277887 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-isset.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated access interceptors disallow protected property direct isset check +--FILE-- +createProxy(new Kitchen()); + +var_dump(isset($proxy->sweets)); +?> +--EXPECT-- +bool(false) \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-read.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-read.phpt new file mode 100644 index 0000000..8d47a63 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-read.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated access interceptors disallow protected property direct read +--FILE-- +createProxy(new Kitchen()); + +$proxy->sweets; +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-unset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-unset.phpt new file mode 100644 index 0000000..21ed252 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-unset.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated access interceptors disallow protected property direct unset +--FILE-- +createProxy(new Kitchen()); + +unset($proxy->sweets); +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-write.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-write.phpt new file mode 100644 index 0000000..31acfaf --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-denies-protected-property-write.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated access interceptors disallow protected property direct write +--FILE-- +createProxy(new Kitchen()); + +$proxy->sweets = 'stolen'; +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-isset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-isset.phpt new file mode 100644 index 0000000..4b7b916 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-isset.phpt @@ -0,0 +1,26 @@ +--TEST-- +Verifies that generated access interceptors disallow private property direct isset check +--SKIPIF-- + +--FILE-- +createProxy(new Kitchen()); + +var_dump(isset($proxy->sweets)); +?> +--EXPECT-- +bool(false) diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-read.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-read.phpt new file mode 100644 index 0000000..436b76b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-read.phpt @@ -0,0 +1,26 @@ +--TEST-- +Verifies that generated access interceptors disallow private property direct read +--SKIPIF-- + +--FILE-- +createProxy(new Kitchen()); + +$proxy->sweets; +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-unset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-unset.phpt new file mode 100644 index 0000000..c296ef4 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-unset.phpt @@ -0,0 +1,26 @@ +--TEST-- +Verifies that generated access interceptors disallow private property direct unset +--SKIPIF-- + +--FILE-- +createProxy(new Kitchen()); + +unset($proxy->sweets); +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-write.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-write.phpt new file mode 100644 index 0000000..bd8e115 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-private-property-write.phpt @@ -0,0 +1,26 @@ +--TEST-- +Verifies that generated access interceptors disallow private property direct write +--SKIPIF-- + +--FILE-- +createProxy(new Kitchen()); + +$proxy->sweets = 'stolen'; +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-isset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-isset.phpt new file mode 100644 index 0000000..f5de693 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-isset.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated access interceptors disallow protected property direct isset check +--FILE-- +createProxy(new Kitchen()); + +var_dump(isset($proxy->sweets)); +?> +--EXPECT-- +bool(false) diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-read.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-read.phpt new file mode 100644 index 0000000..d3519a4 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-read.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated access interceptors disallow protected property direct read +--FILE-- +createProxy(new Kitchen()); + +$proxy->sweets; +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-unset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-unset.phpt new file mode 100644 index 0000000..cb20b6d --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-unset.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated access interceptors disallow protected property direct unset +--FILE-- +createProxy(new Kitchen()); + +unset($proxy->sweets); +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-write.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-write.phpt new file mode 100644 index 0000000..b4ab7bd --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-scope-localizer-denies-protected-property-write.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated access interceptors disallow protected property direct write +--FILE-- +createProxy(new Kitchen()); + +$proxy->sweets = 'stolen'; +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-with-cache.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-with-cache.phpt new file mode 100644 index 0000000..0a180b2 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/access-interceptor-with-cache.phpt @@ -0,0 +1,34 @@ +--TEST-- +Verifies that access interceptor proxy file is generated +--FILE-- +setProxiesTargetDir(__DIR__ . '/cache'); +$fileLocator = new \ProxyManager\FileLocator\FileLocator($configuration->getProxiesTargetDir()); +$configuration->setGeneratorStrategy( + new \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy($fileLocator) +); + +$factory = new \ProxyManager\Factory\AccessInterceptorValueHolderFactory($configuration); + +$proxy = $factory->createProxy(new Kitchen()); + +$filename = $fileLocator->getProxyFileName(get_class($proxy)); +var_dump(file_exists($filename)); + +$proxy = $factory->createProxy(new Kitchen()); + +var_dump(file_exists($filename)); +@unlink($filename); + +?> +--EXPECT-- +bool(true) +bool(true) \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/cache/README.md b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/cache/README.md new file mode 100644 index 0000000..dcb0d38 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/cache/README.md @@ -0,0 +1,3 @@ +## Integration tests for PHP language features of proxies + +This folder is used for the caches \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/init.php b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/init.php new file mode 100644 index 0000000..cab4158 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/init.php @@ -0,0 +1,10 @@ +setGeneratorStrategy(new EvaluatingGeneratorStrategy()); diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-allows-inexisting-magic-property-read.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-allows-inexisting-magic-property-read.phpt new file mode 100644 index 0000000..2f318c7 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-allows-inexisting-magic-property-read.phpt @@ -0,0 +1,25 @@ +--TEST-- +Verifies that generated lazy loading ghost objects disallow reading non-existing properties via direct read +--FILE-- +createProxy('Kitchen', function () {}); + +echo $proxy->nonExisting; +?> +--EXPECTF-- +nonExisting \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-allows-inexisting-property-write.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-allows-inexisting-property-write.phpt new file mode 100644 index 0000000..e815d0f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-allows-inexisting-property-write.phpt @@ -0,0 +1,21 @@ +--TEST-- +Verifies that generated lazy loading ghost objects disallow reading non-existing properties via direct read +--FILE-- +createProxy('Kitchen', function () {}); + +$proxy->nonExisting = 'I do not exist'; +echo $proxy->nonExisting; +?> +--EXPECTF-- +I do not exist \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-inexisting-property-read.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-inexisting-property-read.phpt new file mode 100644 index 0000000..73042ab --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-inexisting-property-read.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated lazy loading ghost objects disallow reading non-existing properties via direct read +--FILE-- +createProxy('Kitchen', function () {}); + +$proxy->nonExisting; +?> +--EXPECTF-- +Notice: Undefined property: Kitchen::$nonExisting in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-isset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-isset.phpt new file mode 100644 index 0000000..05f741c --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-isset.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated lazy loading ghost objects disallow private property direct isset check +--FILE-- +createProxy('Kitchen', function () {}); + +var_dump(isset($proxy->sweets)); +?> +--EXPECT-- +bool(false) \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-read.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-read.phpt new file mode 100644 index 0000000..e1fd83b --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-read.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated lazy loading ghost objects disallow private property direct read +--FILE-- +createProxy('Kitchen', function () {}); + +$proxy->sweets; +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-unset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-unset.phpt new file mode 100644 index 0000000..62b1bf1 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-unset.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated lazy loading ghost objects disallow private property direct unset +--FILE-- +createProxy('Kitchen', function () {}); + +unset($proxy->sweets); +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-write.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-write.phpt new file mode 100644 index 0000000..e0840d7 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-private-property-write.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated lazy loading ghost objects disallow private property direct write +--FILE-- +createProxy('Kitchen', function () {}); + +$proxy->sweets = 'stolen'; +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-isset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-isset.phpt new file mode 100644 index 0000000..8fa8485 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-isset.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated lazy loading ghost objects disallow protected property direct isset check +--FILE-- +createProxy('Kitchen', function () {}); + +var_dump(isset($proxy->sweets)); +?> +--EXPECT-- +bool(false) \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-read.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-read.phpt new file mode 100644 index 0000000..1463370 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-read.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated lazy loading ghost objects disallow protected property direct read +--FILE-- +createProxy('Kitchen', function () {}); + +$proxy->sweets; +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-unset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-unset.phpt new file mode 100644 index 0000000..a0a6643 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-unset.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated lazy loading ghost objects disallow protected property direct unset +--FILE-- +createProxy('Kitchen', function () {}); + +unset($proxy->sweets); +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-write.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-write.phpt new file mode 100644 index 0000000..46f8178 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-denies-protected-property-write.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated lazy loading ghost objects disallow protected property direct write +--FILE-- +createProxy('Kitchen', function () {}); + +$proxy->sweets = 'stolen'; +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-with-cache.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-with-cache.phpt new file mode 100644 index 0000000..7a60948 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-ghost-with-cache.phpt @@ -0,0 +1,34 @@ +--TEST-- +Verifies that lazy loading ghost proxy file is generated +--FILE-- +setProxiesTargetDir(__DIR__ . '/cache'); +$fileLocator = new \ProxyManager\FileLocator\FileLocator($configuration->getProxiesTargetDir()); +$configuration->setGeneratorStrategy( + new \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy($fileLocator) +); + +$factory = new \ProxyManager\Factory\LazyLoadingGhostFactory($configuration); + +$proxy = $factory->createProxy('Kitchen', function () {}); + +$filename = $fileLocator->getProxyFileName(get_class($proxy)); +var_dump(file_exists($filename)); + +$proxy = $factory->createProxy('Kitchen', function () {}); + +var_dump(file_exists($filename)); +@unlink($filename); + +?> +--EXPECT-- +bool(true) +bool(true) \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-isset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-isset.phpt new file mode 100644 index 0000000..14e7989 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-isset.phpt @@ -0,0 +1,23 @@ +--TEST-- +Verifies that generated lazy loading value holders disallow private property direct isset check +--FILE-- +createProxy('Kitchen', function (& $wrapped, $proxy, $method, array $parameters, & $initializer) { + $initializer = null; + $wrapped = new Kitchen(); +}); + +var_dump(isset($proxy->sweets)); +?> +--EXPECT-- +bool(false) \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-read.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-read.phpt new file mode 100644 index 0000000..4660624 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-read.phpt @@ -0,0 +1,23 @@ +--TEST-- +Verifies that generated lazy loading value holders disallow private property direct read +--FILE-- +createProxy('Kitchen', function (& $wrapped, $proxy, $method, array $parameters, & $initializer) { + $initializer = null; + $wrapped = new Kitchen(); +}); + +$proxy->sweets; +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-unset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-unset.phpt new file mode 100644 index 0000000..443785f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-unset.phpt @@ -0,0 +1,23 @@ +--TEST-- +Verifies that generated lazy loading value holders disallow private property direct unset +--FILE-- +createProxy('Kitchen', function (& $wrapped, $proxy, $method, array $parameters, & $initializer) { + $initializer = null; + $wrapped = new Kitchen(); +}); + +unset($proxy->sweets); +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-write.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-write.phpt new file mode 100644 index 0000000..ad035ee --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-private-property-write.phpt @@ -0,0 +1,23 @@ +--TEST-- +Verifies that generated lazy loading value holders disallow private property direct write +--FILE-- +createProxy('Kitchen', function (& $wrapped, $proxy, $method, array $parameters, & $initializer) { + $initializer = null; + $wrapped = new Kitchen(); +}); + +$proxy->sweets = 'stolen'; +?> +--EXPECTF-- +Fatal error: Cannot access private property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-isset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-isset.phpt new file mode 100644 index 0000000..d33c0ba --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-isset.phpt @@ -0,0 +1,23 @@ +--TEST-- +Verifies that generated lazy loading value holders disallow protected property direct isset check +--FILE-- +createProxy('Kitchen', function (& $wrapped, $proxy, $method, array $parameters, & $initializer) { + $initializer = null; + $wrapped = new Kitchen(); +}); + +var_dump(isset($proxy->sweets)); +?> +--EXPECT-- +bool(false) \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-read.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-read.phpt new file mode 100644 index 0000000..cfd2690 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-read.phpt @@ -0,0 +1,23 @@ +--TEST-- +Verifies that generated lazy loading value holders disallow protected property direct read +--FILE-- +createProxy('Kitchen', function (& $wrapped, $proxy, $method, array $parameters, & $initializer) { + $initializer = null; + $wrapped = new Kitchen(); +}); + +$proxy->sweets; +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-unset.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-unset.phpt new file mode 100644 index 0000000..1fac6bb --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-unset.phpt @@ -0,0 +1,23 @@ +--TEST-- +Verifies that generated lazy loading value holders disallow protected property direct unset +--FILE-- +createProxy('Kitchen', function (& $wrapped, $proxy, $method, array $parameters, & $initializer) { + $initializer = null; + $wrapped = new Kitchen(); +}); + +unset($proxy->sweets); +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-write.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-write.phpt new file mode 100644 index 0000000..bb89a31 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-denies-protected-property-write.phpt @@ -0,0 +1,23 @@ +--TEST-- +Verifies that generated lazy loading value holders disallow protected property direct write +--FILE-- +createProxy('Kitchen', function (& $wrapped, $proxy, $method, array $parameters, & $initializer) { + $initializer = null; + $wrapped = new Kitchen(); +}); + +$proxy->sweets = 'stolen'; +?> +--EXPECTF-- +Fatal error: Cannot access protected property %s::$sweets in %s on line %d \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-with-cache.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-with-cache.phpt new file mode 100644 index 0000000..06afe47 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/lazy-loading-value-holder-with-cache.phpt @@ -0,0 +1,40 @@ +--TEST-- +Verifies that lazy loading value holder proxy file is generated +--FILE-- +setProxiesTargetDir(__DIR__ . '/cache'); +$fileLocator = new \ProxyManager\FileLocator\FileLocator($configuration->getProxiesTargetDir()); +$configuration->setGeneratorStrategy( + new \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy($fileLocator) +); + +$factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory($configuration); + +$proxy = $factory->createProxy('Kitchen', function (& $wrapped, $proxy, $method, array $parameters, & $initializer) { + $initializer = null; + $wrapped = new Kitchen(); +}); + +$filename = $fileLocator->getProxyFileName(get_class($proxy)); +var_dump(file_exists($filename)); + +$proxy = $factory->createProxy('Kitchen', function (& $wrapped, $proxy, $method, array $parameters, & $initializer) { + $initializer = null; + $wrapped = new Kitchen(); +}); + +var_dump(file_exists($filename)); +@unlink($filename); + +?> +--EXPECT-- +bool(true) +bool(true) \ No newline at end of file diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/null-object-public-function-empty.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/null-object-public-function-empty.phpt new file mode 100644 index 0000000..2453ea5 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/null-object-public-function-empty.phpt @@ -0,0 +1,23 @@ +--TEST-- +Verifies that generated null object disallow public function +--FILE-- +createProxy('Kitchen'); + +var_dump($proxy->foo()); +?> +--EXPECT-- +NULL diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/null-object-public-property-empty.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/null-object-public-property-empty.phpt new file mode 100644 index 0000000..9da1a41 --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/null-object-public-property-empty.phpt @@ -0,0 +1,20 @@ +--TEST-- +Verifies that generated null object disallow public function +--FILE-- +createProxy('Kitchen'); + +var_dump($proxy->foo); +?> +--EXPECT-- +NULL diff --git a/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/remote-object-json-adapter-denies-unknow-method.phpt b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/remote-object-json-adapter-denies-unknow-method.phpt new file mode 100644 index 0000000..fc0cb9f --- /dev/null +++ b/core/vendor/ocramius/proxy-manager/tests/language-feature-scripts/remote-object-json-adapter-denies-unknow-method.phpt @@ -0,0 +1,43 @@ +--TEST-- +Verifies that generated remote object can call public property +--FILE-- +createProxy('ProxyManagerTestAsset\RemoteProxy\FooServiceInterface'); + +var_dump($proxy->foo()); +var_dump($proxy->unknown()); +?> +--EXPECTF-- +string(3) "baz" + +Fatal error: Call to undefined method %s::unknown() in %s on line %d diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/CHANGELOG.md b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/CHANGELOG.md new file mode 100644 index 0000000..1f8f60c --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/CHANGELOG.md @@ -0,0 +1,7 @@ +CHANGELOG +========= + +2.3.0 +----- + + * First introduction of `Symfony\Bridge\ProxyManager` diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/LICENSE b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/LICENSE new file mode 100644 index 0000000..0b3292c --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2004-2014 Fabien Potencier + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php new file mode 100644 index 0000000..8a98b29 --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\ProxyManager\LazyProxy\Instantiator; + +use ProxyManager\Configuration; +use ProxyManager\Factory\LazyLoadingValueHolderFactory; +use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; +use ProxyManager\Proxy\LazyLoadingInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface; + +/** + * Runtime lazy loading proxy generator. + * + * @author Marco Pivetta + */ +class RuntimeInstantiator implements InstantiatorInterface +{ + /** + * @var \ProxyManager\Factory\LazyLoadingValueHolderFactory + */ + private $factory; + + /** + * Constructor + */ + public function __construct() + { + $config = new Configuration(); + + $config->setGeneratorStrategy(new EvaluatingGeneratorStrategy()); + + $this->factory = new LazyLoadingValueHolderFactory($config); + } + + /** + * {@inheritdoc} + */ + public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator) + { + return $this->factory->createProxy( + $definition->getClass(), + function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) { + $wrappedInstance = call_user_func($realInstantiator); + + $proxy->setProxyInitializer(null); + + return true; + } + ); + } +} diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php new file mode 100644 index 0000000..d354dde --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php @@ -0,0 +1,114 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper; + +use ProxyManager\Generator\ClassGenerator; +use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy; +use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator; +use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface; + +/** + * Generates dumped PHP code of proxies via reflection. + * + * @author Marco Pivetta + */ +class ProxyDumper implements DumperInterface +{ + /** + * @var \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator + */ + private $proxyGenerator; + + /** + * @var \ProxyManager\GeneratorStrategy\BaseGeneratorStrategy + */ + private $classGenerator; + + /** + * Constructor + */ + public function __construct() + { + $this->proxyGenerator = new LazyLoadingValueHolderGenerator(); + $this->classGenerator = new BaseGeneratorStrategy(); + } + + /** + * {@inheritdoc} + */ + public function isProxyCandidate(Definition $definition) + { + return $definition->isLazy() && ($class = $definition->getClass()) && class_exists($class); + } + + /** + * {@inheritdoc} + */ + public function getProxyFactoryCode(Definition $definition, $id) + { + $instantiation = 'return'; + + if (ContainerInterface::SCOPE_CONTAINER === $definition->getScope()) { + $instantiation .= " \$this->services['$id'] ="; + } elseif (ContainerInterface::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) { + $instantiation .= " \$this->services['$id'] = \$this->scopedServices['$scope']['$id'] ="; + } + + $methodName = 'get'.Container::camelize($id).'Service'; + $proxyClass = $this->getProxyClassName($definition); + + return <<$methodName(false); + + \$proxy->setProxyInitializer(null); + + return true; + } + ); + } + + +EOF; + } + + /** + * {@inheritdoc} + */ + public function getProxyCode(Definition $definition) + { + $generatedClass = new ClassGenerator($this->getProxyClassName($definition)); + + $this->proxyGenerator->generate(new \ReflectionClass($definition->getClass()), $generatedClass); + + return $this->classGenerator->generate($generatedClass); + } + + /** + * Produces the proxy class name for the given definition. + * + * @param Definition $definition + * + * @return string + */ + private function getProxyClassName(Definition $definition) + { + return str_replace('\\', '', $definition->getClass()).'_'.spl_object_hash($definition); + } +} diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/README.md b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/README.md new file mode 100644 index 0000000..a266a26 --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/README.md @@ -0,0 +1,15 @@ +ProxyManager Bridge +=================== + +Provides integration for [ProxyManager][1] with various Symfony2 components. + +Resources +--------- + +You can run the unit tests with the following command: + + $ cd path/to/Symfony/Bridge/ProxyManager/ + $ composer.phar install --dev + $ phpunit + +[1]: https://github.com/Ocramius/ProxyManager diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/ContainerBuilderTest.php b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/ContainerBuilderTest.php new file mode 100644 index 0000000..10faf8e --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/ContainerBuilderTest.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\ProxyManager\Tests\LazyProxy; + +require_once __DIR__.'/Fixtures/includes/foo.php'; + +use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +/** + * Integration tests for {@see \Symfony\Component\DependencyInjection\ContainerBuilder} combined + * with the ProxyManager bridge + * + * @author Marco Pivetta + */ +class ContainerBuilderTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService + */ + public function testCreateProxyServiceWithRuntimeInstantiator() + { + $builder = new ContainerBuilder(); + + $builder->setProxyInstantiator(new RuntimeInstantiator()); + + $builder->register('foo1', 'ProxyManagerBridgeFooClass')->setFile(__DIR__.'/Fixtures/includes/foo.php'); + $builder->getDefinition('foo1')->setLazy(true); + + /* @var $foo1 \ProxyManager\Proxy\LazyLoadingInterface|\ProxyManager\Proxy\ValueHolderInterface */ + $foo1 = $builder->get('foo1'); + + $this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved on multiple subsequent calls'); + $this->assertInstanceOf('\ProxyManagerBridgeFooClass', $foo1); + $this->assertInstanceOf('\ProxyManager\Proxy\LazyLoadingInterface', $foo1); + $this->assertFalse($foo1->isProxyInitialized()); + + $foo1->initializeProxy(); + + $this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved after initialization'); + $this->assertTrue($foo1->isProxyInitialized()); + $this->assertInstanceOf('\ProxyManagerBridgeFooClass', $foo1->getWrappedValueHolderValue()); + $this->assertNotInstanceOf('\ProxyManager\Proxy\LazyLoadingInterface', $foo1->getWrappedValueHolderValue()); + } +} diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php new file mode 100644 index 0000000..51dab3c --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php @@ -0,0 +1,68 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper; + +use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Dumper\PhpDumper; + +/** + * Integration tests for {@see \Symfony\Component\DependencyInjection\Dumper\PhpDumper} combined + * with the ProxyManager bridge + * + * @author Marco Pivetta + */ +class PhpDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDumpContainerWithProxyService() + { + $container = new ContainerBuilder(); + + $container->register('foo', 'stdClass'); + $container->getDefinition('foo')->setLazy(true); + $container->compile(); + + $dumper = new PhpDumper($container); + + $dumper->setProxyDumper(new ProxyDumper()); + + $dumpedString = $dumper->dump(); + + $this->assertStringMatchesFormatFile( + __DIR__.'/../Fixtures/php/lazy_service_structure.txt', + $dumpedString, + '->dump() does generate proxy lazy loading logic.' + ); + } + + /** + * Verifies that the generated container retrieves the same proxy instance on multiple subsequent requests + */ + public function testDumpContainerWithProxyServiceWillShareProxies() + { + require_once __DIR__.'/../Fixtures/php/lazy_service.php'; + + $container = new \LazyServiceProjectServiceContainer(); + + /* @var $proxy \stdClass_c1d194250ee2e2b7d2eab8b8212368a8 */ + $proxy = $container->get('foo'); + $this->assertInstanceOf('stdClass_c1d194250ee2e2b7d2eab8b8212368a8', $proxy); + $this->assertSame($proxy, $container->get('foo')); + + $this->assertFalse($proxy->isProxyInitialized()); + + $proxy->initializeProxy(); + + $this->assertTrue($proxy->isProxyInitialized()); + $this->assertSame($proxy, $container->get('foo')); + } +} diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/includes/foo.php b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/includes/foo.php new file mode 100644 index 0000000..1013a8c --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/includes/foo.php @@ -0,0 +1,36 @@ +arguments = $arguments; + } + + public static function getInstance($arguments = array()) + { + $obj = new self($arguments); + $obj->called = true; + + return $obj; + } + + public function initialize() + { + $this->initialized = true; + } + + public function configure() + { + $this->configured = true; + } + + public function setBar($value = null) + { + $this->bar = $value; + } +} diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service.php b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service.php new file mode 100644 index 0000000..b4618f9 --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service.php @@ -0,0 +1,197 @@ +services = + $this->scopedServices = + $this->scopeStacks = array(); + + $this->set('service_container', $this); + + $this->scopes = array(); + $this->scopeChildren = array(); + } + + /** + * Gets the 'foo' service. + * + * This service is shared. + * This method always returns the same instance of the service. + * + * @param bool $lazyLoad whether to try lazy-loading the service with a proxy + * + * @return stdClass A stdClass instance. + */ + public function getFooService($lazyLoad = true) + { + if ($lazyLoad) { + $container = $this; + + return $this->services['foo'] = new stdClass_c1d194250ee2e2b7d2eab8b8212368a8( + function (& $wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) { + $wrappedInstance = $container->getFooService(false); + + $proxy->setProxyInitializer(null); + + return true; + } + ); + } + + return new \stdClass(); + } +} + +class stdClass_c1d194250ee2e2b7d2eab8b8212368a8 extends \stdClass implements \ProxyManager\Proxy\LazyLoadingInterface, \ProxyManager\Proxy\ValueHolderInterface +{ + /** + * @var \Closure|null initializer responsible for generating the wrapped object + */ + private $valueHolder5157dd96e88c0 = null; + + /** + * @var \Closure|null initializer responsible for generating the wrapped object + */ + private $initializer5157dd96e8924 = null; + + /** + * @override constructor for lazy initialization + * + * @param \Closure|null $initializer + */ + public function __construct($initializer) + { + $this->initializer5157dd96e8924 = $initializer; + } + + /** + * @param string $name + */ + public function __get($name) + { + $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__get', array('name' => $name)); + + return $this->valueHolder5157dd96e88c0->$name; + } + + /** + * @param string $name + * @param mixed $value + */ + public function __set($name, $value) + { + $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__set', array('name' => $name, 'value' => $value)); + + $this->valueHolder5157dd96e88c0->$name = $value; + } + + /** + * @param string $name + * + * @return bool + */ + public function __isset($name) + { + $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__isset', array('name' => $name)); + + return isset($this->valueHolder5157dd96e88c0->$name); + } + + /** + * @param string $name + */ + public function __unset($name) + { + $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__unset', array('name' => $name)); + + unset($this->valueHolder5157dd96e88c0->$name); + } + + /** + * + */ + public function __clone() + { + $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__clone', array()); + + $this->valueHolder5157dd96e88c0 = clone $this->valueHolder5157dd96e88c0; + } + + /** + * + */ + public function __sleep() + { + $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__sleep', array()); + + return array('valueHolder5157dd96e88c0'); + } + + /** + * + */ + public function __wakeup() + { + } + + /** + * {@inheritdoc} + */ + public function setProxyInitializer(\Closure $initializer = null) + { + $this->initializer5157dd96e8924 = $initializer; + } + + /** + * {@inheritdoc} + */ + public function getProxyInitializer() + { + return $this->initializer5157dd96e8924; + } + + /** + * {@inheritdoc} + */ + public function initializeProxy() + { + return $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, 'initializeProxy', array()); + } + + /** + * {@inheritdoc} + */ + public function isProxyInitialized() + { + return null !== $this->valueHolder5157dd96e88c0; + } + + /** + * {@inheritdoc} + */ + public function getWrappedValueHolderValue() + { + return $this->valueHolder5157dd96e88c0; + } +} diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt new file mode 100644 index 0000000..332370c --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt @@ -0,0 +1,27 @@ +services['foo'] = new stdClass_%s( + function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) { + $wrappedInstance = $container->getFooService(false); + + $proxy->setProxyInitializer(null); + + return true; + } + ); + } + + return new \stdClass(); + } +} + +class stdClass_%s extends \stdClass implements \ProxyManager\Proxy\VirtualProxyInterface +{%a}%A \ No newline at end of file diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Instantiator/RuntimeInstantiatorTest.php b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Instantiator/RuntimeInstantiatorTest.php new file mode 100644 index 0000000..5c976e7 --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Instantiator/RuntimeInstantiatorTest.php @@ -0,0 +1,61 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\ProxyManager\Tests\LazyProxy\Instantiator; + +use ProxyManager\Proxy\LazyLoadingInterface; +use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Definition; + +/** + * Tests for {@see \Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator} + * + * @author Marco Pivetta + * + * @covers \Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator + */ +class RuntimeInstantiatorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var RuntimeInstantiator + */ + protected $instantiator; + + /** + * {@inheritdoc} + */ + public function setUp() + { + $this->instantiator = new RuntimeInstantiator(); + } + + public function testInstantiateProxy() + { + $instance = new \stdClass(); + $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $definition = new Definition('stdClass'); + $instantiator = function () use ($instance) { + return $instance; + }; + + /* @var $proxy \ProxyManager\Proxy\LazyLoadingInterface|\ProxyManager\Proxy\ValueHolderInterface */ + $proxy = $this->instantiator->instantiateProxy($container, $definition, 'foo', $instantiator); + + $this->assertInstanceOf('ProxyManager\Proxy\LazyLoadingInterface', $proxy); + $this->assertInstanceOf('ProxyManager\Proxy\ValueHolderInterface', $proxy); + $this->assertFalse($proxy->isProxyInitialized()); + + $proxy->initializeProxy(); + + $this->assertSame($instance, $proxy->getWrappedValueHolderValue()); + } +} diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php new file mode 100644 index 0000000..e3ef13d --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php @@ -0,0 +1,104 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\ProxyManager\Tests\LazyProxy\PhpDumper; + +use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; +use Symfony\Component\DependencyInjection\Definition; + +/** + * Tests for {@see \Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper} + * + * @author Marco Pivetta + * + * @covers \Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper + */ +class ProxyDumperTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ProxyDumper + */ + protected $dumper; + + /** + * {@inheritdoc} + */ + public function setUp() + { + $this->dumper = new ProxyDumper(); + } + + /** + * @dataProvider getProxyCandidates + * + * @param Definition $definition + * @param bool $expected + */ + public function testIsProxyCandidate(Definition $definition, $expected) + { + $this->assertSame($expected, $this->dumper->isProxyCandidate($definition)); + } + + public function testGetProxyCode() + { + $definition = new Definition(__CLASS__); + + $definition->setLazy(true); + + $code = $this->dumper->getProxyCode($definition); + + $this->assertStringMatchesFormat( + '%Aclass SymfonyBridgeProxyManagerTestsLazyProxyPhpDumperProxyDumperTest%aextends%w' + .'\Symfony\Bridge\ProxyManager\Tests\LazyProxy\PhpDumper\ProxyDumperTest%a', + $code + ); + } + + public function testGetProxyFactoryCode() + { + $definition = new Definition(__CLASS__); + + $definition->setLazy(true); + + $code = $this->dumper->getProxyFactoryCode($definition, 'foo'); + + $this->assertStringMatchesFormat( + '%wif ($lazyLoad) {%w$container = $this;%wreturn $this->services[\'foo\'] = new ' + .'SymfonyBridgeProxyManagerTestsLazyProxyPhpDumperProxyDumperTest_%s(%wfunction ' + .'(&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) {' + .'%w$wrappedInstance = $container->getFooService(false);%w$proxy->setProxyInitializer(null);' + .'%wreturn true;%w}%w);%w}%w', + $code + ); + } + + /** + * @return array + */ + public function getProxyCandidates() + { + $definitions = array( + array(new Definition(__CLASS__), true), + array(new Definition('stdClass'), true), + array(new Definition('foo'.uniqid()), false), + array(new Definition(), false), + ); + + array_map( + function ($definition) { + $definition[0]->setLazy(true); + }, + $definitions + ); + + return $definitions; + } +} diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/composer.json b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/composer.json new file mode 100644 index 0000000..8a71f49 --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/composer.json @@ -0,0 +1,38 @@ +{ + "name": "symfony/proxy-manager-bridge", + "type": "symfony-bridge", + "description": "Symfony ProxyManager Bridge", + "keywords": [], + "homepage": "http://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "require": { + "php": ">=5.3.3", + "symfony/dependency-injection": "~2.3", + "ocramius/proxy-manager": ">=0.3.1,<0.6-dev" + }, + "require-dev": { + "symfony/config": "2.3" + }, + "autoload": { + "psr-0": { + "Symfony\\Bridge\\ProxyManager\\": "" + } + }, + "target-dir": "Symfony/Bridge/ProxyManager", + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + } +} diff --git a/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/phpunit.xml.dist b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/phpunit.xml.dist new file mode 100644 index 0000000..0314075 --- /dev/null +++ b/core/vendor/symfony/proxy-manager-bridge/Symfony/Bridge/ProxyManager/phpunit.xml.dist @@ -0,0 +1,25 @@ + + + + + + ./Tests/ + + + + + + ./ + + ./Resources + ./Tests + ./vendor + + + + diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Annotation/AnnotationCollection.php b/core/vendor/zendframework/zend-code/Zend/Code/Annotation/AnnotationCollection.php new file mode 100644 index 0000000..a10c8bf --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Annotation/AnnotationCollection.php @@ -0,0 +1,32 @@ +setIdentifiers(array( + __CLASS__, + get_class($this), + )); + $this->events = $events; + + return $this; + } + + /** + * Retrieve event manager + * + * Lazy loads an instance if none registered. + * + * @return EventManagerInterface + */ + public function getEventManager() + { + if (null === $this->events) { + $this->setEventManager(new EventManager()); + } + + return $this->events; + } + + /** + * Attach a parser to listen to the createAnnotation event + * + * @param ParserInterface $parser + * @return AnnotationManager + */ + public function attach(ParserInterface $parser) + { + $this->getEventManager() + ->attach(self::EVENT_CREATE_ANNOTATION, array($parser, 'onCreateAnnotation')); + + return $this; + } + + /** + * Create Annotation + * + * @param array $annotationData + * @return false|\stdClass + */ + public function createAnnotation(array $annotationData) + { + $event = new Event(); + $event->setName(self::EVENT_CREATE_ANNOTATION); + $event->setTarget($this); + $event->setParams(array( + 'class' => $annotationData[0], + 'content' => $annotationData[1], + 'raw' => $annotationData[2], + )); + + $eventManager = $this->getEventManager(); + $results = $eventManager->trigger($event, function ($r) { + return (is_object($r)); + }); + + $annotation = $results->last(); + + return (is_object($annotation) ? $annotation : false); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Annotation/Parser/DoctrineAnnotationParser.php b/core/vendor/zendframework/zend-code/Zend/Code/Annotation/Parser/DoctrineAnnotationParser.php new file mode 100644 index 0000000..7406d41 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Annotation/Parser/DoctrineAnnotationParser.php @@ -0,0 +1,153 @@ +docParser = $docParser; + return $this; + } + + /** + * Retrieve the DocParser instance + * + * If none is registered, lazy-loads a new instance. + * + * @return DocParser + */ + public function getDocParser() + { + if (!$this->docParser instanceof DocParser) { + $this->setDocParser(new DocParser()); + } + + return $this->docParser; + } + + /** + * Handle annotation creation + * + * @param EventInterface $e + * @return false|\stdClass + */ + public function onCreateAnnotation(EventInterface $e) + { + $annotationClass = $e->getParam('class', false); + if (!$annotationClass) { + return false; + } + + if (!isset($this->allowedAnnotations[$annotationClass])) { + return false; + } + + $annotationString = $e->getParam('raw', false); + if (!$annotationString) { + return false; + } + + // Annotation classes provided by the AnnotationScanner are already + // resolved to fully-qualified class names. Adding the global namespace + // prefix allows the Doctrine annotation parser to locate the annotation + // class correctly. + $annotationString = preg_replace('/^(@)/', '$1\\', $annotationString); + + $parser = $this->getDocParser(); + $annotations = $parser->parse($annotationString); + if (empty($annotations)) { + return false; + } + + $annotation = array_shift($annotations); + if (!is_object($annotation)) { + return false; + } + + return $annotation; + } + + /** + * Specify an allowed annotation class + * + * @param string $annotation + * @return DoctrineAnnotationParser + */ + public function registerAnnotation($annotation) + { + $this->allowedAnnotations[$annotation] = true; + return $this; + } + + /** + * Set many allowed annotations at once + * + * @param array|Traversable $annotations Array or traversable object of + * annotation class names + * @throws Exception\InvalidArgumentException + * @return DoctrineAnnotationParser + */ + public function registerAnnotations($annotations) + { + if (!is_array($annotations) && !$annotations instanceof Traversable) { + throw new Exception\InvalidArgumentException(sprintf( + '%s: expects an array or Traversable; received "%s"', + __METHOD__, + (is_object($annotations) ? get_class($annotations) : gettype($annotations)) + )); + } + + foreach ($annotations as $annotation) { + $this->allowedAnnotations[$annotation] = true; + } + + return $this; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Annotation/Parser/GenericAnnotationParser.php b/core/vendor/zendframework/zend-code/Zend/Code/Annotation/Parser/GenericAnnotationParser.php new file mode 100644 index 0000000..6e64da9 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Annotation/Parser/GenericAnnotationParser.php @@ -0,0 +1,224 @@ +getParam('class', false); + if (!$class || !$this->hasAnnotation($class)) { + return false; + } + + $content = $e->getParam('content', ''); + $content = trim($content, '()'); + + if ($this->hasAlias($class)) { + $class = $this->resolveAlias($class); + } + + $index = array_search($class, $this->annotationNames); + $annotation = $this->annotations[$index]; + + $newAnnotation = clone $annotation; + if ($content) { + $newAnnotation->initialize($content); + } + + return $newAnnotation; + } + + /** + * Register annotations + * + * @param string|AnnotationInterface $annotation String class name of an + * AnnotationInterface implementation, or actual instance + * @return GenericAnnotationParser + * @throws Exception\InvalidArgumentException + */ + public function registerAnnotation($annotation) + { + $class = false; + if (is_string($annotation) && class_exists($annotation)) { + $class = $annotation; + $annotation = new $annotation(); + } + + if (!$annotation instanceof AnnotationInterface) { + throw new Exception\InvalidArgumentException(sprintf( + '%s: expects an instance of %s\AnnotationInterface; received "%s"', + __METHOD__, + __NAMESPACE__, + (is_object($annotation) ? get_class($annotation) : gettype($annotation)) + )); + } + + $class = $class ?: get_class($annotation); + + if (in_array($class, $this->annotationNames)) { + throw new Exception\InvalidArgumentException(sprintf( + 'An annotation for this class %s already exists', + $class + )); + } + + $this->annotations[] = $annotation; + $this->annotationNames[] = $class; + } + + /** + * Register many annotations at once + * + * @param array|Traversable $annotations + * @throws Exception\InvalidArgumentException + * @return GenericAnnotationParser + */ + public function registerAnnotations($annotations) + { + if (!is_array($annotations) && !$annotations instanceof Traversable) { + throw new Exception\InvalidArgumentException(sprintf( + '%s: expects an array or Traversable; received "%s"', + __METHOD__, + (is_object($annotations) ? get_class($annotations) : gettype($annotations)) + )); + } + + foreach ($annotations as $annotation) { + $this->registerAnnotation($annotation); + } + + return $this; + } + + /** + * Checks if the manager has annotations for a class + * + * @param string $class + * @return bool + */ + public function hasAnnotation($class) + { + if (in_array($class, $this->annotationNames)) { + return true; + } + + if ($this->hasAlias($class)) { + return true; + } + + return false; + } + + /** + * Alias an annotation name + * + * @param string $alias + * @param string $class May be either a registered annotation name or another alias + * @throws Exception\InvalidArgumentException + * @return GenericAnnotationParser + */ + public function setAlias($alias, $class) + { + if (!in_array($class, $this->annotationNames) && !$this->hasAlias($class)) { + throw new Exception\InvalidArgumentException(sprintf( + '%s: Cannot alias "%s" to "%s", as class "%s" is not currently a registered annotation or alias', + __METHOD__, + $alias, + $class, + $class + )); + } + + $alias = $this->normalizeAlias($alias); + $this->aliases[$alias] = $class; + + return $this; + } + + /** + * Normalize an alias name + * + * @param string $alias + * @return string + */ + protected function normalizeAlias($alias) + { + return strtolower(str_replace(array('-', '_', ' ', '\\', '/'), '', $alias)); + } + + /** + * Do we have an alias by the provided name? + * + * @param string $alias + * @return bool + */ + protected function hasAlias($alias) + { + $alias = $this->normalizeAlias($alias); + + return (isset($this->aliases[$alias])); + } + + /** + * Resolve an alias to a class name + * + * @param string $alias + * @return string + */ + protected function resolveAlias($alias) + { + do { + $normalized = $this->normalizeAlias($alias); + $class = $this->aliases[$normalized]; + } while ($this->hasAlias($class)); + + return $class; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Annotation/Parser/ParserInterface.php b/core/vendor/zendframework/zend-code/Zend/Code/Annotation/Parser/ParserInterface.php new file mode 100644 index 0000000..7e36eac --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Annotation/Parser/ParserInterface.php @@ -0,0 +1,39 @@ +setOptions($options); + } + } + + /** + * @param bool $isSourceDirty + * @return AbstractGenerator + */ + public function setSourceDirty($isSourceDirty = true) + { + $this->isSourceDirty = (bool) $isSourceDirty; + return $this; + } + + /** + * @return bool + */ + public function isSourceDirty() + { + return $this->isSourceDirty; + } + + /** + * @param string $indentation + * @return AbstractGenerator + */ + public function setIndentation($indentation) + { + $this->indentation = (string) $indentation; + return $this; + } + + /** + * @return string + */ + public function getIndentation() + { + return $this->indentation; + } + + /** + * @param string $sourceContent + * @return AbstractGenerator + */ + public function setSourceContent($sourceContent) + { + $this->sourceContent = (string) $sourceContent; + return $this; + } + + /** + * @return string + */ + public function getSourceContent() + { + return $this->sourceContent; + } + + /** + * @param array|Traversable $options + * @throws Exception\InvalidArgumentException + * @return AbstractGenerator + */ + public function setOptions($options) + { + if (!is_array($options) && !$options instanceof Traversable) { + throw new Exception\InvalidArgumentException(sprintf( + '%s expects an array or Traversable object; received "%s"', + __METHOD__, + (is_object($options) ? get_class($options) : gettype($options)) + )); + } + + foreach ($options as $optionName => $optionValue) { + $methodName = 'set' . $optionName; + if (method_exists($this, $methodName)) { + $this->{$methodName}($optionValue); + } + } + + return $this; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/AbstractMemberGenerator.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/AbstractMemberGenerator.php new file mode 100644 index 0000000..e425bbd --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/AbstractMemberGenerator.php @@ -0,0 +1,226 @@ +flags = $flags; + + return $this; + } + + /** + * @param int $flag + * @return AbstractMemberGenerator + */ + public function addFlag($flag) + { + $this->setFlags($this->flags | $flag); + return $this; + } + + /** + * @param int $flag + * @return AbstractMemberGenerator + */ + public function removeFlag($flag) + { + $this->setFlags($this->flags & ~$flag); + return $this; + } + + /** + * @param bool $isAbstract + * @return AbstractMemberGenerator + */ + public function setAbstract($isAbstract) + { + return (($isAbstract) ? $this->addFlag(self::FLAG_ABSTRACT) : $this->removeFlag(self::FLAG_ABSTRACT)); + } + + /** + * @return bool + */ + public function isAbstract() + { + return (bool) ($this->flags & self::FLAG_ABSTRACT); + } + + /** + * @param bool $isFinal + * @return AbstractMemberGenerator + */ + public function setFinal($isFinal) + { + return (($isFinal) ? $this->addFlag(self::FLAG_FINAL) : $this->removeFlag(self::FLAG_FINAL)); + } + + /** + * @return bool + */ + public function isFinal() + { + return (bool) ($this->flags & self::FLAG_FINAL); + } + + /** + * @param bool $isStatic + * @return AbstractMemberGenerator + */ + public function setStatic($isStatic) + { + return (($isStatic) ? $this->addFlag(self::FLAG_STATIC) : $this->removeFlag(self::FLAG_STATIC)); + } + + /** + * @return bool + */ + public function isStatic() + { + return (bool) ($this->flags & self::FLAG_STATIC); // is FLAG_STATIC in flags + } + + /** + * @param string $visibility + * @return AbstractMemberGenerator + */ + public function setVisibility($visibility) + { + switch ($visibility) { + case self::VISIBILITY_PUBLIC: + $this->removeFlag(self::FLAG_PRIVATE | self::FLAG_PROTECTED); // remove both + $this->addFlag(self::FLAG_PUBLIC); + break; + case self::VISIBILITY_PROTECTED: + $this->removeFlag(self::FLAG_PUBLIC | self::FLAG_PRIVATE); // remove both + $this->addFlag(self::FLAG_PROTECTED); + break; + case self::VISIBILITY_PRIVATE: + $this->removeFlag(self::FLAG_PUBLIC | self::FLAG_PROTECTED); // remove both + $this->addFlag(self::FLAG_PRIVATE); + break; + } + + return $this; + } + + /** + * @return string + */ + public function getVisibility() + { + switch (true) { + case ($this->flags & self::FLAG_PROTECTED): + return self::VISIBILITY_PROTECTED; + case ($this->flags & self::FLAG_PRIVATE): + return self::VISIBILITY_PRIVATE; + default: + return self::VISIBILITY_PUBLIC; + } + } + + /** + * @param string $name + * @return AbstractMemberGenerator + */ + public function setName($name) + { + $this->name = (string) $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param DocBlockGenerator|string $docBlock + * @throws Exception\InvalidArgumentException + * @return AbstractMemberGenerator + */ + public function setDocBlock($docBlock) + { + if (is_string($docBlock)) { + $docBlock = new DocBlockGenerator($docBlock); + } elseif (!$docBlock instanceof DocBlockGenerator) { + throw new Exception\InvalidArgumentException(sprintf( + '%s is expecting either a string, array or an instance of %s\DocBlockGenerator', + __METHOD__, + __NAMESPACE__ + )); + } + + $this->docBlock = $docBlock; + + return $this; + } + + /** + * @return DocBlockGenerator + */ + public function getDocBlock() + { + return $this->docBlock; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/BodyGenerator.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/BodyGenerator.php new file mode 100644 index 0000000..b9103c3 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/BodyGenerator.php @@ -0,0 +1,44 @@ +content = (string) $content; + return $this; + } + + /** + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * @return string + */ + public function generate() + { + return $this->getContent(); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/ClassGenerator.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/ClassGenerator.php new file mode 100644 index 0000000..80eedaa --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/ClassGenerator.php @@ -0,0 +1,744 @@ +getName()); + + $cg->setSourceContent($cg->getSourceContent()); + $cg->setSourceDirty(false); + + if ($classReflection->getDocComment() != '') { + $cg->setDocBlock(DocBlockGenerator::fromReflection($classReflection->getDocBlock())); + } + + $cg->setAbstract($classReflection->isAbstract()); + + // set the namespace + if ($classReflection->inNamespace()) { + $cg->setNamespaceName($classReflection->getNamespaceName()); + } + + /* @var \Zend\Code\Reflection\ClassReflection $parentClass */ + $parentClass = $classReflection->getParentClass(); + if ($parentClass) { + $cg->setExtendedClass($parentClass->getName()); + $interfaces = array_diff($classReflection->getInterfaces(), $parentClass->getInterfaces()); + } else { + $interfaces = $classReflection->getInterfaces(); + } + + $interfaceNames = array(); + foreach ($interfaces AS $interface) { + /* @var \Zend\Code\Reflection\ClassReflection $interface */ + $interfaceNames[] = $interface->getName(); + } + + $cg->setImplementedInterfaces($interfaceNames); + + $properties = array(); + foreach ($classReflection->getProperties() as $reflectionProperty) { + if ($reflectionProperty->getDeclaringClass()->getName() == $classReflection->getName()) { + $properties[] = PropertyGenerator::fromReflection($reflectionProperty); + } + } + $cg->addProperties($properties); + + $methods = array(); + foreach ($classReflection->getMethods() as $reflectionMethod) { + if ($reflectionMethod->getDeclaringClass()->getName() == $cg->getNamespaceName() . "\\" . $cg->getName()) { + $methods[] = MethodGenerator::fromReflection($reflectionMethod); + } + } + $cg->addMethods($methods); + + return $cg; + } + + /** + * Generate from array + * + * @configkey name string [required] Class Name + * @configkey filegenerator FileGenerator File generator that holds this class + * @configkey namespacename string The namespace for this class + * @configkey docblock string The docblock information + * @configkey flags int Flags, one of ClassGenerator::FLAG_ABSTRACT ClassGenerator::FLAG_FINAL + * @configkey extendedclass string Class which this class is extending + * @configkey implementedinterfaces + * @configkey properties + * @configkey methods + * + * @throws Exception\InvalidArgumentException + * @param array $array + * @return ClassGenerator + */ + public static function fromArray(array $array) + { + if (!isset($array['name'])) { + throw new Exception\InvalidArgumentException( + 'Class generator requires that a name is provided for this object' + ); + } + + $cg = new static($array['name']); + foreach ($array as $name => $value) { + // normalize key + switch (strtolower(str_replace(array('.', '-', '_'), '', $name))) { + case 'containingfile': + $cg->setContainingFileGenerator($value); + break; + case 'namespacename': + $cg->setNamespaceName($value); + break; + case 'docblock': + $docBlock = ($value instanceof DocBlockGenerator) ? $value : DocBlockGenerator::fromArray($value); + $cg->setDocBlock($docBlock); + break; + case 'flags': + $cg->setFlags($value); + break; + case 'extendedclass': + $cg->setExtendedClass($value); + break; + case 'implementedinterfaces': + $cg->setImplementedInterfaces($value); + break; + case 'properties': + $cg->addProperties($value); + break; + case 'methods': + $cg->addMethods($value); + break; + } + } + + return $cg; + } + + /** + * @param string $name + * @param string $namespaceName + * @param array|string $flags + * @param string $extends + * @param array $interfaces + * @param array $properties + * @param array $methods + * @param DocBlockGenerator $docBlock + */ + public function __construct($name = null, $namespaceName = null, $flags = null, $extends = null, + $interfaces = array(), $properties = array(), $methods = array(), $docBlock = null) + { + if ($name !== null) { + $this->setName($name); + } + if ($namespaceName !== null) { + $this->setNamespaceName($namespaceName); + } + if ($flags !== null) { + $this->setFlags($flags); + } + if ($properties !== array()) { + $this->addProperties($properties); + } + if ($extends !== null) { + $this->setExtendedClass($extends); + } + if (is_array($interfaces)) { + $this->setImplementedInterfaces($interfaces); + } + if ($methods !== array()) { + $this->addMethods($methods); + } + if ($docBlock !== null) { + $this->setDocBlock($docBlock); + } + } + + /** + * @param string $name + * @return ClassGenerator + */ + public function setName($name) + { + if (strstr($name, '\\')) { + $namespace = substr($name, 0, strrpos($name, '\\')); + $name = substr($name, strrpos($name, '\\') + 1); + $this->setNamespaceName($namespace); + } + + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $namespaceName + * @return ClassGenerator + */ + public function setNamespaceName($namespaceName) + { + $this->namespaceName = $namespaceName; + return $this; + } + + /** + * @return string + */ + public function getNamespaceName() + { + return $this->namespaceName; + } + + /** + * @param FileGenerator $fileGenerator + * @return ClassGenerator + */ + public function setContainingFileGenerator(FileGenerator $fileGenerator) + { + $this->containingFileGenerator = $fileGenerator; + return $this; + } + + /** + * @return FileGenerator + */ + public function getContainingFileGenerator() + { + return $this->containingFileGenerator; + } + + /** + * @param DocBlockGenerator $docBlock + * @return ClassGenerator + */ + public function setDocBlock(DocBlockGenerator $docBlock) + { + $this->docBlock = $docBlock; + return $this; + } + + /** + * @return DocBlockGenerator + */ + public function getDocBlock() + { + return $this->docBlock; + } + + /** + * @param array|string $flags + * @return ClassGenerator + */ + public function setFlags($flags) + { + if (is_array($flags)) { + $flagsArray = $flags; + $flags = 0x00; + foreach ($flagsArray as $flag) { + $flags |= $flag; + } + } + // check that visibility is one of three + $this->flags = $flags; + + return $this; + } + + /** + * @param string $flag + * @return ClassGenerator + */ + public function addFlag($flag) + { + $this->setFlags($this->flags | $flag); + return $this; + } + + /** + * @param string $flag + * @return ClassGenerator + */ + public function removeFlag($flag) + { + $this->setFlags($this->flags & ~$flag); + return $this; + } + + /** + * @param bool $isAbstract + * @return ClassGenerator + */ + public function setAbstract($isAbstract) + { + return (($isAbstract) ? $this->addFlag(self::FLAG_ABSTRACT) : $this->removeFlag(self::FLAG_ABSTRACT)); + } + + /** + * @return bool + */ + public function isAbstract() + { + return (bool) ($this->flags & self::FLAG_ABSTRACT); + } + + /** + * @param bool $isFinal + * @return ClassGenerator + */ + public function setFinal($isFinal) + { + return (($isFinal) ? $this->addFlag(self::FLAG_FINAL) : $this->removeFlag(self::FLAG_FINAL)); + } + + /** + * @return bool + */ + public function isFinal() + { + return ($this->flags & self::FLAG_FINAL); + } + + /** + * @param string $extendedClass + * @return ClassGenerator + */ + public function setExtendedClass($extendedClass) + { + $this->extendedClass = $extendedClass; + return $this; + } + + /** + * @return string + */ + public function getExtendedClass() + { + return $this->extendedClass; + } + + /** + * @param array $implementedInterfaces + * @return ClassGenerator + */ + public function setImplementedInterfaces(array $implementedInterfaces) + { + $this->implementedInterfaces = $implementedInterfaces; + return $this; + } + + /** + * @return array + */ + public function getImplementedInterfaces() + { + return $this->implementedInterfaces; + } + + /** + * @param array $properties + * @return ClassGenerator + */ + public function addProperties(array $properties) + { + foreach ($properties as $property) { + if ($property instanceof PropertyGenerator) { + $this->addPropertyFromGenerator($property); + } else { + if (is_string($property)) { + $this->addProperty($property); + } elseif (is_array($property)) { + call_user_func_array(array($this, 'addProperty'), $property); + } + } + } + + return $this; + } + + /** + * Add Property from scalars + * + * @param string $name + * @param string|array $defaultValue + * @param int $flags + * @throws Exception\InvalidArgumentException + * @return ClassGenerator + */ + public function addProperty($name, $defaultValue = null, $flags = PropertyGenerator::FLAG_PUBLIC) + { + if (!is_string($name)) { + throw new Exception\InvalidArgumentException(sprintf( + '%s expects string for name', + __METHOD__ + )); + } + + return $this->addPropertyFromGenerator(new PropertyGenerator($name, $defaultValue, $flags)); + } + + /** + * Add property from PropertyGenerator + * + * @param string|PropertyGenerator $property + * @throws Exception\InvalidArgumentException + * @return ClassGenerator + */ + public function addPropertyFromGenerator(PropertyGenerator $property) + { + $propertyName = $property->getName(); + + if (isset($this->properties[$propertyName])) { + throw new Exception\InvalidArgumentException(sprintf( + 'A property by name %s already exists in this class.', + $propertyName + )); + } + + $this->properties[$propertyName] = $property; + return $this; + } + + /** + * Add a class to "use" classes + * + * @param string $use + * @param string|null $useAlias + * @return ClassGenerator + */ + public function addUse($use, $useAlias = null) + { + if (!empty($useAlias)) { + $use .= ' as ' . $useAlias; + } + + $this->uses[] = $use; + return $this; + } + + /** + * @return PropertyGenerator[] + */ + public function getProperties() + { + return $this->properties; + } + + /** + * @param string $propertyName + * @return PropertyGenerator|false + */ + public function getProperty($propertyName) + { + foreach ($this->getProperties() as $property) { + if ($property->getName() == $propertyName) { + return $property; + } + } + + return false; + } + + /** + * Returns the "use" classes + * + * @return array + */ + public function getUses() + { + return $this->uses; + } + + /** + * @param string $propertyName + * @return bool + */ + public function hasProperty($propertyName) + { + return isset($this->properties[$propertyName]); + } + + /** + * @param array $methods + * @return ClassGenerator + */ + public function addMethods(array $methods) + { + foreach ($methods as $method) { + if ($method instanceof MethodGenerator) { + $this->addMethodFromGenerator($method); + } else { + if (is_string($method)) { + $this->addMethod($method); + } elseif (is_array($method)) { + call_user_func_array(array($this, 'addMethod'), $method); + } + } + } + + return $this; + } + + /** + * Add Method from scalars + * + * @param string $name + * @param array $parameters + * @param int $flags + * @param string $body + * @param string $docBlock + * @throws Exception\InvalidArgumentException + * @return ClassGenerator + */ + public function addMethod($name = null, array $parameters = array(), $flags = MethodGenerator::FLAG_PUBLIC, + $body = null, $docBlock = null) + { + if (!is_string($name)) { + throw new Exception\InvalidArgumentException(sprintf( + '%s expects string for name', + __METHOD__ + )); + } + + return $this->addMethodFromGenerator(new MethodGenerator($name, $parameters, $flags, $body, $docBlock)); + } + + /** + * Add Method from MethodGenerator + * + * @param MethodGenerator $method + * @throws Exception\InvalidArgumentException + * @return ClassGenerator + */ + public function addMethodFromGenerator(MethodGenerator $method) + { + $methodName = $method->getName(); + + if (isset($this->methods[$methodName])) { + throw new Exception\InvalidArgumentException(sprintf( + 'A method by name %s already exists in this class.', + $methodName + )); + } + + $this->methods[$methodName] = $method; + return $this; + } + + /** + * @return MethodGenerator[] + */ + public function getMethods() + { + return $this->methods; + } + + /** + * @param string $methodName + * @return MethodGenerator|false + */ + public function getMethod($methodName) + { + foreach ($this->methods as $method) { + if ($method->getName() == $methodName) { + return $method; + } + } + + return false; + } + + /** + * @param string $methodName + * @return ClassGenerator + */ + public function removeMethod($methodName) + { + foreach ($this->methods as $key => $method) { + if ($method->getName() == $methodName) { + unset($this->methods[$key]); + break; + } + } + + return $this; + } + + /** + * @param string $methodName + * @return bool + */ + public function hasMethod($methodName) + { + return isset($this->methods[$methodName]); + } + + /** + * @return bool + */ + public function isSourceDirty() + { + if (($docBlock = $this->getDocBlock()) && $docBlock->isSourceDirty()) { + return true; + } + + foreach ($this->getProperties() as $property) { + if ($property->isSourceDirty()) { + return true; + } + } + + foreach ($this->getMethods() as $method) { + if ($method->isSourceDirty()) { + return true; + } + } + + return parent::isSourceDirty(); + } + + /** + * @return string + */ + public function generate() + { + if (!$this->isSourceDirty()) { + $output = $this->getSourceContent(); + if (!empty($output)) { + return $output; + } + } + + $output = ''; + + if (null !== ($namespace = $this->getNamespaceName())) { + $output .= 'namespace ' . $namespace . ';' . self::LINE_FEED . self::LINE_FEED; + } + + $uses = $this->getUses(); + if (!empty($uses)) { + foreach ($uses as $use) { + $output .= 'use ' . $use . ';' . self::LINE_FEED; + } + $output .= self::LINE_FEED; + } + + if (null !== ($docBlock = $this->getDocBlock())) { + $docBlock->setIndentation(''); + $output .= $docBlock->generate(); + } + + if ($this->isAbstract()) { + $output .= 'abstract '; + } + + $output .= 'class ' . $this->getName(); + + if (!empty($this->extendedClass)) { + $output .= ' extends ' . $this->extendedClass; + } + + $implemented = $this->getImplementedInterfaces(); + if (!empty($implemented)) { + $output .= ' implements ' . implode(', ', $implemented); + } + + $output .= self::LINE_FEED . '{' . self::LINE_FEED . self::LINE_FEED; + + $properties = $this->getProperties(); + if (!empty($properties)) { + foreach ($properties as $property) { + $output .= $property->generate() . self::LINE_FEED . self::LINE_FEED; + } + } + + $methods = $this->getMethods(); + if (!empty($methods)) { + foreach ($methods as $method) { + $output .= $method->generate() . self::LINE_FEED; + } + } + + $output .= self::LINE_FEED . '}' . self::LINE_FEED; + + return $output; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag.php new file mode 100644 index 0000000..5478b32 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag.php @@ -0,0 +1,133 @@ + ' + ), + array( + 'return', + '@return ' + ), + array( + 'tag', + '@ ' + ) + ); + + /** + * @var string + */ + protected $name = null; + + /** + * @var string + */ + protected $description = null; + + /** + * @param array $options + */ + public function __construct(array $options = array()) + { + if (isset($options['name'])) { + $this->setName($options['name']); + } + if (isset($options['description'])) { + $this->setDescription($options['description']); + } + } + + /** + * Build a Tag generator object from a reflection object + * + * @param ReflectionDocBlockTag $reflectionTag + * @return Tag + */ + public static function fromReflection(ReflectionDocBlockTag $reflectionTag) + { + $tagName = $reflectionTag->getName(); + + $codeGenDocBlockTag = new static(); + $codeGenDocBlockTag->setName($tagName); + + // transport any properties via accessors and mutators from reflection to codegen object + $reflectionClass = new ReflectionClass($reflectionTag); + foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { + if (substr($method->getName(), 0, 3) == 'get') { + $propertyName = substr($method->getName(), 3); + if (method_exists($codeGenDocBlockTag, 'set' . $propertyName)) { + $codeGenDocBlockTag->{'set' . $propertyName}($reflectionTag->{'get' . $propertyName}()); + } + } + } + + return $codeGenDocBlockTag; + } + + /** + * @param string $name + * @return Tag + */ + public function setName($name) + { + $this->name = ltrim($name, '@'); + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $description + * @return Tag + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @return string + */ + public function generate() + { + $output = '@' . $this->name + . (($this->description != null) ? ' ' . $this->description : ''); + + return $output; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/AuthorTag.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/AuthorTag.php new file mode 100644 index 0000000..bced4e2 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/AuthorTag.php @@ -0,0 +1,92 @@ +setName('author') + ->setAuthorName($reflectionTagParam->getType()) // @todo rename + ->setAuthorEmail($reflectionTagParam->getVariableName()) + ->setDescription($reflectionTagParam->getDescription()); + + return $authorTag; + } + + /** + * @param string $datatype + * @return AuthorTag + */ + public function setDatatype($datatype) + { + $this->datatype = (string) $datatype; + return $this; + } + + /** + * @return string + */ + public function getDatatype() + { + return $this->datatype; + } + + /** + * @param string $paramName + * @return AuthorTag + */ + public function setParamName($paramName) + { + $this->paramName = (string) $paramName; + return $this; + } + + /** + * @return string + */ + public function getParamName() + { + return $this->paramName; + } + + /** + * @return string + */ + public function generate() + { + $output = '@param ' + . (($this->datatype != null) ? $this->datatype : 'unknown') + . (($this->paramName != null) ? ' $' . $this->paramName : '') + . (($this->description != null) ? ' ' . $this->description : ''); + + return $output; + } + +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/LicenseTag.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/LicenseTag.php new file mode 100644 index 0000000..d6149c3 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/LicenseTag.php @@ -0,0 +1,106 @@ +setUrl($options['url']); + } + + if (empty($this->name)) { + $this->setName('license'); + } + } + + /** + * @param ReflectionDocBlockTag $reflectionTagLicense + * @return LicenseTag + */ + public static function fromReflection(ReflectionDocBlockTag $reflectionTagLicense) + { + $licenseTag = new static(); + $licenseTag + ->setName('license') + ->setUrl($reflectionTagLicense->getUrl()) + ->setLicenseName($reflectionTagLicense->getDescription()); + + return $licenseTag; + } + + /** + * @param string $url + * @return LicenseTag + */ + public function setUrl($url) + { + $this->url = $url; + return $this; + } + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string $name + * @return LicenseTag + */ + public function setLicenseName($name) + { + $this->licenseName = $name; + return $this; + } + + /** + * @return string + */ + public function getLicenseName() + { + return $this->licenseName; + } + + /** + * @return string + */ + public function generate() + { + $output = '@license ' + . (($this->url != null) ? $this->url : 'unknown') + . (($this->licenseName != null) ? ' ' . $this->licenseName : '') + . (($this->description != null) ? ' ' . $this->description : ''); + + return $output; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/ParamTag.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/ParamTag.php new file mode 100644 index 0000000..175df2f --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/ParamTag.php @@ -0,0 +1,91 @@ +setName('param') + ->setDatatype($reflectionTagParam->getType()) // @todo rename + ->setParamName($reflectionTagParam->getVariableName()) + ->setDescription($reflectionTagParam->getDescription()); + + return $paramTag; + } + + /** + * @param string $datatype + * @return ParamTag + */ + public function setDatatype($datatype) + { + $this->datatype = $datatype; + return $this; + } + + /** + * @return string + */ + public function getDatatype() + { + return $this->datatype; + } + + /** + * @param string $paramName + * @return ParamTag + */ + public function setParamName($paramName) + { + $this->paramName = $paramName; + return $this; + } + + /** + * @return string + */ + public function getParamName() + { + return $this->paramName; + } + + /** + * @return string + */ + public function generate() + { + $output = '@param ' + . (($this->datatype != null) ? $this->datatype : 'unknown') + . (($this->paramName != null) ? ' $' . $this->paramName : '') + . (($this->description != null) ? ' ' . $this->description : ''); + + return $output; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/ReturnTag.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/ReturnTag.php new file mode 100644 index 0000000..8ff364b --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlock/Tag/ReturnTag.php @@ -0,0 +1,62 @@ +setName('return') + ->setDatatype($reflectionTagReturn->getType()) // @todo rename + ->setDescription($reflectionTagReturn->getDescription()); + + return $returnTag; + } + + /** + * @param string $datatype + * @return ReturnTag + */ + public function setDatatype($datatype) + { + $this->datatype = $datatype; + return $this; + } + + /** + * @return string + */ + public function getDatatype() + { + return $this->datatype; + } + + /** + * @return string + */ + public function generate() + { + return '@return ' . $this->datatype . ' ' . $this->description; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlockGenerator.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlockGenerator.php new file mode 100644 index 0000000..0758fb3 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/DocBlockGenerator.php @@ -0,0 +1,260 @@ +setSourceContent($reflectionDocBlock->getContents()); + $docBlock->setSourceDirty(false); + + $docBlock->setShortDescription($reflectionDocBlock->getShortDescription()); + $docBlock->setLongDescription($reflectionDocBlock->getLongDescription()); + + foreach ($reflectionDocBlock->getTags() as $tag) { + $docBlock->setTag(DockBlockTag::fromReflection($tag)); + } + + return $docBlock; + } + + /** + * Generate from array + * + * @configkey shortdescription string The short description for this doc block + * @configkey longdescription string The long description for this doc block + * @configkey tags array + * + * @throws Exception\InvalidArgumentException + * @param array $array + * @return DocBlockGenerator + */ + public static function fromArray(array $array) + { + $docBlock = new static(); + + foreach ($array as $name => $value) { + // normalize key + switch (strtolower(str_replace(array('.', '-', '_'), '', $name))) { + case 'shortdescription': + $docBlock->setShortDescription($value); + case 'longdescription': + $docBlock->setLongDescription($value); + break; + case 'tags': + $docBlock->setTags($value); + break; + } + } + + return $docBlock; + } + + /** + * @param string $shortDescription + * @param string $longDescription + * @param array $tags + */ + public function __construct($shortDescription = null, $longDescription = null, array $tags = array()) + { + if ($shortDescription) { + $this->setShortDescription($shortDescription); + } + if ($longDescription) { + $this->setLongDescription($longDescription); + } + if (is_array($tags) && $tags) { + $this->setTags($tags); + } + } + + /** + * @param string $shortDescription + * @return DocBlockGenerator + */ + public function setShortDescription($shortDescription) + { + $this->shortDescription = $shortDescription; + return $this; + } + + /** + * @return string + */ + public function getShortDescription() + { + return $this->shortDescription; + } + + /** + * @param string $longDescription + * @return DocBlockGenerator + */ + public function setLongDescription($longDescription) + { + $this->longDescription = $longDescription; + return $this; + } + + /** + * @return string + */ + public function getLongDescription() + { + return $this->longDescription; + } + + /** + * @param array $tags + * @return DocBlockGenerator + */ + public function setTags(array $tags) + { + foreach ($tags as $tag) { + $this->setTag($tag); + } + + return $this; + } + + /** + * @param array|DockBlockTag $tag + * @throws Exception\InvalidArgumentException + * @return DocBlockGenerator + */ + public function setTag($tag) + { + if (is_array($tag)) { + $tag = new DockBlockTag($tag); + } elseif (!$tag instanceof DockBlockTag) { + throw new Exception\InvalidArgumentException(sprintf( + '%s expects either an array of method options or an instance of %s\DocBlock\Tag', + __METHOD__, + __NAMESPACE__ + )); + } + + $this->tags[] = $tag; + return $this; + } + + /** + * @return DockBlockTag[] + */ + public function getTags() + { + return $this->tags; + } + + /** + * Set the word wrap + * + * @param bool $value + * @return \Zend\Code\Generator\DocBlockGenerator + */ + public function setWordWrap($value) + { + $this->wordwrap = (bool) $value; + return $this; + } + + /** + * Get the word wrap + * + * @return bool + */ + public function getWordWrap() + { + return $this->wordwrap; + } + + /** + * @return string + */ + public function generate() + { + if (!$this->isSourceDirty()) { + return $this->docCommentize(trim($this->getSourceContent())); + } + + $output = ''; + if (null !== ($sd = $this->getShortDescription())) { + $output .= $sd . self::LINE_FEED . self::LINE_FEED; + } + if (null !== ($ld = $this->getLongDescription())) { + $output .= $ld . self::LINE_FEED . self::LINE_FEED; + } + + foreach ($this->getTags() as $tag) { + $output .= $tag->generate() . self::LINE_FEED; + } + + return $this->docCommentize(trim($output)); + } + + /** + * @param string $content + * @return string + */ + protected function docCommentize($content) + { + $indent = $this->getIndentation(); + $output = $indent . '/**' . self::LINE_FEED; + $content = $this->getWordWrap() == true ? wordwrap($content, 80, self::LINE_FEED) : $content; + $lines = explode(self::LINE_FEED, $content); + foreach ($lines as $line) { + $output .= $indent . ' *'; + if ($line) { + $output .= " $line"; + } + $output .= self::LINE_FEED; + } + $output .= $indent . ' */' . self::LINE_FEED; + + return $output; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/Exception/ExceptionInterface.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/Exception/ExceptionInterface.php new file mode 100644 index 0000000..77981f8 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/Exception/ExceptionInterface.php @@ -0,0 +1,15 @@ +setOptions($options); + } + } + + /** + * Use this if you intend on generating code generation objects based on the same file. + * This will keep previous changes to the file in tact during the same PHP process + * + * @param string $filePath + * @param bool $includeIfNotAlreadyIncluded + * @throws Exception\InvalidArgumentException + * @return FileGenerator + */ + public static function fromReflectedFileName($filePath, $includeIfNotAlreadyIncluded = true) + { + $realpath = realpath($filePath); + + if ($realpath === false) { + $realpath = stream_resolve_include_path($filePath); + } + + if (!$realpath || !in_array($realPath, get_included_files())) { + throw new Exception\InvalidArgumentException(sprintf( + 'No file for %s was found.', + $filePath + )); + } + + if ($includeIfNotAlreadyIncluded && !in_array($realpath, get_included_files())) { + include $realpath; + } + + $fileReflector = new FileReflection($realpath); + $codeGenerator = static::fromReflection($fileReflector); + + return $codeGenerator; + } + + /** + * @param FileReflection $fileReflection + * @return FileGenerator + */ + public static function fromReflection(FileReflection $fileReflection) + { + $file = new static(); + + $file->setSourceContent($fileReflection->getContents()); + $file->setSourceDirty(false); + + $body = $fileReflection->getContents(); + + foreach ($fileReflection->getClasses() as $class) { + $phpClass = ClassGenerator::fromReflection($class); + $phpClass->setContainingFileGenerator($file); + + $file->setClass($phpClass); + + $classStartLine = $class->getStartLine(true); + $classEndLine = $class->getEndLine(); + + $bodyLines = explode("\n", $body); + $bodyReturn = array(); + for ($lineNum = 1, $count = count($bodyLines); $lineNum <= $count; $lineNum++) { + if ($lineNum == $classStartLine) { + $bodyReturn[] = str_replace( + '?', + $class->getName(), + '/* Zend_Code_Generator_Php_File-ClassMarker: {?} */' + ); + + $lineNum = $classEndLine; + } else { + $bodyReturn[] = $bodyLines[$lineNum - 1]; // adjust for index -> line conversion + } + } + $body = implode("\n", $bodyReturn); + unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine); + } + + $namespace = $fileReflection->getNamespace(); + + if ($namespace != '') { + $file->setNamespace($namespace); + } + + $uses = $fileReflection->getUses(); + if ($uses) { + $file->setUses($uses); + } + + if (($fileReflection->getDocComment() != '')) { + $docBlock = $fileReflection->getDocBlock(); + $file->setDocBlock(DocBlockGenerator::fromReflection($docBlock)); + + $bodyLines = explode("\n", $body); + $bodyReturn = array(); + for ($lineNum = 1, $count = count($bodyLines); $lineNum <= $count; $lineNum++) { + if ($lineNum == $docBlock->getStartLine()) { + $bodyReturn[] = str_replace( + '?', + $class->getName(), + '/* Zend_Code_Generator_FileGenerator-DocBlockMarker */' + ); + $lineNum = $docBlock->getEndLine(); + } else { + $bodyReturn[] = $bodyLines[$lineNum - 1]; // adjust for index -> line conversion + } + } + $body = implode("\n", $bodyReturn); + unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine); + } + + $file->setBody($body); + + return $file; + } + + /** + * @param array $values + * @return FileGenerator + */ + public static function fromArray(array $values) + { + $fileGenerator = new static; + foreach ($values as $name => $value) { + switch (strtolower(str_replace(array('.', '-', '_'), '', $name))) { + case 'filename': + $fileGenerator->setFilename($value); + continue; + case 'class': + $fileGenerator->setClass(($value instanceof ClassGenerator) ? $value : ClassGenerator::fromArray($value)); + continue; + case 'requiredfiles': + $fileGenerator->setRequiredFiles($value); + continue; + default: + if (property_exists($fileGenerator, $name)) { + $fileGenerator->{$name} = $value; + } elseif (method_exists($fileGenerator, 'set' . $name)) { + $fileGenerator->{'set' . $name}($value); + } + } + } + + return $fileGenerator; + } + + /** + * @param DocBlockGenerator|string $docBlock + * @throws Exception\InvalidArgumentException + * @return FileGenerator + */ + public function setDocBlock($docBlock) + { + if (is_string($docBlock)) { + $docBlock = array('shortDescription' => $docBlock); + } + + if (is_array($docBlock)) { + $docBlock = new DocBlockGenerator($docBlock); + } elseif (!$docBlock instanceof DocBlockGenerator) { + throw new Exception\InvalidArgumentException(sprintf( + '%s is expecting either a string, array or an instance of %s\DocBlockGenerator', + __METHOD__, + __NAMESPACE__ + )); + } + + $this->docBlock = $docBlock; + return $this; + } + + /** + * @return DocBlockGenerator + */ + public function getDocBlock() + { + return $this->docBlock; + } + + /** + * @param array $requiredFiles + * @return FileGenerator + */ + public function setRequiredFiles(array $requiredFiles) + { + $this->requiredFiles = $requiredFiles; + return $this; + } + + /** + * @return array + */ + public function getRequiredFiles() + { + return $this->requiredFiles; + } + + /** + * @param array $classes + * @return FileGenerator + */ + public function setClasses(array $classes) + { + foreach ($classes as $class) { + $this->setClass($class); + } + + return $this; + } + + /** + * @return string + */ + public function getNamespace() + { + return $this->namespace; + } + + /** + * @param string $namespace + * @return FileGenerator + */ + public function setNamespace($namespace) + { + $this->namespace = (string) $namespace; + return $this; + } + + /** + * Returns an array with the first element the use statement, second is the as part. + * If $withResolvedAs is set to true, there will be a third element that is the + * "resolved" as statement, as the second part is not required in use statements + * + * @param bool $withResolvedAs + * @return array + */ + public function getUses($withResolvedAs = false) + { + $uses = $this->uses; + if ($withResolvedAs) { + for ($useIndex = 0, $count = count($uses); $useIndex < $count; $useIndex++) { + if ($uses[$useIndex][1] == '') { + if (($lastSeparator = strrpos($uses[$useIndex][0], '\\')) !== false) { + $uses[$useIndex][2] = substr($uses[$useIndex][0], $lastSeparator + 1); + } else { + $uses[$useIndex][2] = $uses[$useIndex][0]; + } + } else { + $uses[$useIndex][2] = $uses[$useIndex][1]; + } + } + } + + return $uses; + } + + /** + * @param array $uses + * @return FileGenerator + */ + public function setUses(array $uses) + { + foreach ($uses as $use) { + $use = (array)$use; + if (array_key_exists('use', $use) && array_key_exists('as', $use)) { + $import = $use['use']; + $alias = $use['as']; + } elseif (count($use) == 2) { + list($import, $alias) = $use; + } else { + $import = current($use); + $alias = null; + } + $this->setUse($import, $alias); + } + return $this; + } + + /** + * @param string $use + * @param null|string $as + * @return FileGenerator + */ + public function setUse($use, $as = null) + { + if (!in_array(array($use, $as), $this->uses)) { + $this->uses[] = array($use, $as); + } + return $this; + } + + /** + * @param string $name + * @return ClassGenerator + */ + public function getClass($name = null) + { + if ($name == null) { + reset($this->classes); + + return current($this->classes); + } + + return $this->classes[(string) $name]; + } + + /** + * @param array|string|ClassGenerator $class + * @throws Exception\InvalidArgumentException + * @return FileGenerator + */ + public function setClass($class) + { + if (is_array($class)) { + $class = ClassGenerator::fromArray($class); + } elseif (is_string($class)) { + $class = new ClassGenerator($class); + } elseif (!$class instanceof ClassGenerator) { + throw new Exception\InvalidArgumentException(sprintf( + '%s is expecting either a string, array or an instance of %s\ClassGenerator', + __METHOD__, + __NAMESPACE__ + )); + } + + // @todo check for dup here + $className = $class->getName(); + $this->classes[$className] = $class; + + return $this; + } + + /** + * @param string $filename + * @return FileGenerator + */ + public function setFilename($filename) + { + $this->filename = (string) $filename; + return $this; + } + + /** + * @return string + */ + public function getFilename() + { + return $this->filename; + } + + /** + * @return ClassGenerator[] + */ + public function getClasses() + { + return $this->classes; + } + + /** + * @param string $body + * @return FileGenerator + */ + public function setBody($body) + { + $this->body = (string) $body; + return $this; + } + + /** + * @return string + */ + public function getBody() + { + return $this->body; + } + + /** + * @return bool + */ + public function isSourceDirty() + { + $docBlock = $this->getDocBlock(); + if ($docBlock && $docBlock->isSourceDirty()) { + return true; + } + + foreach ($this->classes as $class) { + if ($class->isSourceDirty()) { + return true; + } + } + + return parent::isSourceDirty(); + } + + /** + * @return string + */ + public function generate() + { + if ($this->isSourceDirty() === false) { + return $this->sourceContent; + } + + $output = ''; + + // start with the body (if there), or open tag + $body = $this->getBody(); + if (preg_match('#(?:\s*)<\?php#', $body) == false) { + $output = 'getDocBlock())) { + $docBlock->setIndentation(''); + + if (preg_match('#/* Zend_Code_Generator_FileGenerator-DocBlockMarker */#', $output)) { + $output = preg_replace('#/* Zend_CodeGenerator_Php_File-DocBlockMarker */#', $docBlock->generate(), + $output, 1); + } else { + $output .= $docBlock->generate() . self::LINE_FEED; + } + } + + // newline + $output .= self::LINE_FEED; + + // namespace, if any + $namespace = $this->getNamespace(); + if ($namespace) { + $output .= sprintf('namespace %s;%s', $namespace, str_repeat(self::LINE_FEED, 2)); + } + + // process required files + // @todo marker replacement for required files + $requiredFiles = $this->getRequiredFiles(); + if (!empty($requiredFiles)) { + foreach ($requiredFiles as $requiredFile) { + $output .= 'require_once \'' . $requiredFile . '\';' . self::LINE_FEED; + } + + $output .= self::LINE_FEED; + } + + // process import statements + $uses = $this->getUses(); + if (!empty($uses)) { + foreach ($uses as $use) { + list($import, $alias) = $use; + if (null === $alias) { + $output .= sprintf('use %s;%s', $import, self::LINE_FEED); + } else { + $output .= sprintf('use %s as %s;%s', $import, $alias, self::LINE_FEED); + } + } + $output .= self::LINE_FEED; + } + + // process classes + $classes = $this->getClasses(); + if (!empty($classes)) { + foreach ($classes as $class) { + $regex = str_replace('?', $class->getName(), + '/* Zend_Code_Generator_FileGenerator-ClassMarker: {?} */'); + $regex = preg_quote($regex, '#'); + if (preg_match('#' . $regex . '#', $output)) { + $output = preg_replace('#' . $regex . '#', $class->generate(), $output, 1); + } else { + if ($namespace) { + $class->setNamespaceName(null); + } + $output .= $class->generate() . self::LINE_FEED; + } + } + } + + if (!empty($body)) { + // add an extra space between classes and + if (!empty($classes)) { + $output .= self::LINE_FEED; + } + + $output .= $body; + } + + return $output; + } + + /** + * @return FileGenerator + * @throws Exception\RuntimeException + */ + public function write() + { + if ($this->filename == '' || !is_writable(dirname($this->filename))) { + throw new Exception\RuntimeException('This code generator object is not writable.'); + } + file_put_contents($this->filename, $this->generate()); + + return $this; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/FileGeneratorRegistry.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/FileGeneratorRegistry.php new file mode 100644 index 0000000..27538e8 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/FileGeneratorRegistry.php @@ -0,0 +1,44 @@ +getFilename(); + } + + if ($fileName == '') { + throw new RuntimeException('FileName does not exist.'); + } + + // cannot use realpath since the file might not exist, but we do need to have the index + // in the same DIRECTORY_SEPARATOR that realpath would use: + $fileName = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $fileName); + + static::$fileCodeGenerators[$fileName] = $fileCodeGenerator; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/GeneratorInterface.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/GeneratorInterface.php new file mode 100644 index 0000000..e9e587a --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/GeneratorInterface.php @@ -0,0 +1,15 @@ +setSourceContent($reflectionMethod->getContents(false)); + $method->setSourceDirty(false); + + if ($reflectionMethod->getDocComment() != '') { + $method->setDocBlock(DocBlockGenerator::fromReflection($reflectionMethod->getDocBlock())); + } + + $method->setFinal($reflectionMethod->isFinal()); + + if ($reflectionMethod->isPrivate()) { + $method->setVisibility(self::VISIBILITY_PRIVATE); + } elseif ($reflectionMethod->isProtected()) { + $method->setVisibility(self::VISIBILITY_PROTECTED); + } else { + $method->setVisibility(self::VISIBILITY_PUBLIC); + } + + $method->setStatic($reflectionMethod->isStatic()); + + $method->setName($reflectionMethod->getName()); + + foreach ($reflectionMethod->getParameters() as $reflectionParameter) { + $method->setParameter(ParameterGenerator::fromReflection($reflectionParameter)); + } + + $method->setBody($reflectionMethod->getBody()); + + return $method; + } + + /** + * Generate from array + * + * @configkey name string [required] Class Name + * @configkey docblock string The docblock information + * @configkey flags int Flags, one of MethodGenerator::FLAG_ABSTRACT MethodGenerator::FLAG_FINAL + * @configkey parameters string Class which this class is extending + * @configkey body string + * @configkey abstract bool + * @configkey final bool + * @configkey static bool + * @configkey visibility string + * + * @throws Exception\InvalidArgumentException + * @param array $array + * @return MethodGenerator + */ + public static function fromArray(array $array) + { + if (!isset($array['name'])) { + throw new Exception\InvalidArgumentException( + 'Method generator requires that a name is provided for this object' + ); + } + + $method = new static($array['name']); + foreach ($array as $name => $value) { + // normalize key + switch (strtolower(str_replace(array('.', '-', '_'), '', $name))) { + case 'docblock': + $docBlock = ($value instanceof DocBlockGenerator) ? $value : DocBlockGenerator::fromArray($value); + $method->setDocBlock($docBlock); + break; + case 'flags': + $method->setFlags($value); + break; + case 'parameters': + $method->setParameters($value); + break; + case 'body': + $method->setBody($value); + break; + case 'abstract': + $method->setAbstract($value); + break; + case 'final': + $method->setFinal($value); + break; + case 'static': + $method->setStatic($value); + break; + case 'visibility': + $method->setVisibility($value); + break; + } + } + + return $method; + } + + /** + * @param string $name + * @param array $parameters + * @param int|array $flags + * @param string $body + * @param DocBlockGenerator|string $docBlock + */ + public function __construct($name = null, array $parameters = array(), $flags = self::FLAG_PUBLIC, $body = null, + $docBlock = null) + { + if ($name) { + $this->setName($name); + } + if ($parameters) { + $this->setParameters($parameters); + } + if ($flags !== self::FLAG_PUBLIC) { + $this->setFlags($flags); + } + if ($body) { + $this->setBody($body); + } + if ($docBlock) { + $this->setDocBlock($docBlock); + } + } + + /** + * @param array $parameters + * @return MethodGenerator + */ + public function setParameters(array $parameters) + { + foreach ($parameters as $parameter) { + $this->setParameter($parameter); + } + + return $this; + } + + /** + * @param ParameterGenerator|string $parameter + * @throws Exception\InvalidArgumentException + * @return MethodGenerator + */ + public function setParameter($parameter) + { + if (is_string($parameter)) { + $parameter = new ParameterGenerator($parameter); + } elseif (!$parameter instanceof ParameterGenerator) { + throw new Exception\InvalidArgumentException(sprintf( + '%s is expecting either a string, array or an instance of %s\ParameterGenerator', + __METHOD__, + __NAMESPACE__ + )); + } + + $parameterName = $parameter->getName(); + + $this->parameters[$parameterName] = $parameter; + + return $this; + } + + /** + * @return ParameterGenerator[] + */ + public function getParameters() + { + return $this->parameters; + } + + /** + * @param string $body + * @return MethodGenerator + */ + public function setBody($body) + { + $this->body = $body; + return $this; + } + + /** + * @return string + */ + public function getBody() + { + return $this->body; + } + + /** + * @return string + */ + public function generate() + { + $output = ''; + + $indent = $this->getIndentation(); + + if (($docBlock = $this->getDocBlock()) !== null) { + $docBlock->setIndentation($indent); + $output .= $docBlock->generate(); + } + + $output .= $indent; + + if ($this->isAbstract()) { + $output .= 'abstract '; + } else { + $output .= (($this->isFinal()) ? 'final ' : ''); + } + + $output .= $this->getVisibility() + . (($this->isStatic()) ? ' static' : '') + . ' function ' . $this->getName() . '('; + + $parameters = $this->getParameters(); + if (!empty($parameters)) { + foreach ($parameters as $parameter) { + $parameterOutput[] = $parameter->generate(); + } + + $output .= implode(', ', $parameterOutput); + } + + $output .= ')' . self::LINE_FEED . $indent . '{' . self::LINE_FEED; + + if ($this->body) { + $output .= preg_replace('#^(.+?)$#m', $indent . $indent . '$1', trim($this->body)) + . self::LINE_FEED; + } + + $output .= $indent . '}' . self::LINE_FEED; + + return $output; + } + + public function __toString() + { + return $this->generate(); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/ParameterGenerator.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/ParameterGenerator.php new file mode 100644 index 0000000..f85d7d4 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/ParameterGenerator.php @@ -0,0 +1,296 @@ +setName($reflectionParameter->getName()); + + if ($reflectionParameter->isArray()) { + $param->setType('array'); + } elseif (method_exists($reflectionParameter, 'isCallable') && $reflectionParameter->isCallable()) { + $param->setType('callable'); + } else { + $typeClass = $reflectionParameter->getClass(); + if ($typeClass) { + $parameterType = $typeClass->getName(); + $currentNamespace = $reflectionParameter->getDeclaringClass()->getNamespaceName(); + + if (substr($parameterType, 0, strlen($currentNamespace)) == $currentNamespace) { + $parameterType = substr($parameterType, strlen($currentNamespace)+1); + } + + $param->setType($parameterType); + } + } + + $param->setPosition($reflectionParameter->getPosition()); + + if ($reflectionParameter->isOptional()) { + $param->setDefaultValue($reflectionParameter->getDefaultValue()); + } + $param->setPassedByReference($reflectionParameter->isPassedByReference()); + + return $param; + } + + /** + * Generate from array + * + * @configkey name string [required] Class Name + * @configkey type string + * @configkey defaultvalue null|bool|string|int|float|array|ValueGenerator + * @configkey passedbyreference bool + * @configkey position int + * @configkey sourcedirty bool + * @configkey indentation string + * @configkey sourcecontent string + * + * @throws Exception\InvalidArgumentException + * @param array $array + * @return ParameterGenerator + */ + public static function fromArray(array $array) + { + if (!isset($array['name'])) { + throw new Exception\InvalidArgumentException( + 'Paramerer generator requires that a name is provided for this object' + ); + } + + $param = new static($array['name']); + foreach ($array as $name => $value) { + // normalize key + switch (strtolower(str_replace(array('.', '-', '_'), '', $name))) { + case 'type': + $param->setType($value); + break; + case 'defaultvalue': + $param->setDefaultValue($value); + break; + case 'passedbyreference': + $param->setPassedByReference($value); + break; + case 'position': + $param->setPosition($value); + break; + case 'sourcedirty': + $param->setSourceDirty($value); + break; + case 'indentation': + $param->setIndentation($value); + break; + case 'sourcecontent': + $param->setSourceContent($value); + break; + } + } + + return $param; + } + + /** + * @param string $name + * @param string $type + * @param mixed $defaultValue + * @param int $position + * @param bool $passByReference + */ + public function __construct($name = null, $type = null, $defaultValue = null, $position = null, + $passByReference = false) + { + if (null !== $name) { + $this->setName($name); + } + if (null !== $type) { + $this->setType($type); + } + if (null !== $defaultValue) { + $this->setDefaultValue($defaultValue); + } + if (null !== $position) { + $this->setPosition($position); + } + if (false !== $passByReference) { + $this->setPassedByReference(true); + } + } + + /** + * @param string $type + * @return ParameterGenerator + */ + public function setType($type) + { + $this->type = (string) $type; + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $name + * @return ParameterGenerator + */ + public function setName($name) + { + $this->name = (string) $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set the default value of the parameter. + * + * Certain variables are difficult to express + * + * @param null|bool|string|int|float|array|ValueGenerator $defaultValue + * @return ParameterGenerator + */ + public function setDefaultValue($defaultValue) + { + if (!($defaultValue instanceof ValueGenerator)) { + $defaultValue = new ValueGenerator($defaultValue); + } + $this->defaultValue = $defaultValue; + + return $this; + } + + /** + * @return string + */ + public function getDefaultValue() + { + return $this->defaultValue; + } + + /** + * @param int $position + * @return ParameterGenerator + */ + public function setPosition($position) + { + $this->position = (int) $position; + return $this; + } + + /** + * @return int + */ + public function getPosition() + { + return $this->position; + } + + /** + * @return bool + */ + public function getPassedByReference() + { + return $this->passedByReference; + } + + /** + * @param bool $passedByReference + * @return ParameterGenerator + */ + public function setPassedByReference($passedByReference) + { + $this->passedByReference = (bool) $passedByReference; + return $this; + } + + /** + * @return string + */ + public function generate() + { + $output = ''; + + if ($this->type && !in_array($this->type, static::$simple)) { + $output .= $this->type . ' '; + } + + if (true === $this->passedByReference) { + $output .= '&'; + } + + $output .= '$' . $this->name; + + if ($this->defaultValue !== null) { + $output .= ' = '; + if (is_string($this->defaultValue)) { + $output .= ValueGenerator::escape($this->defaultValue); + } elseif ($this->defaultValue instanceof ValueGenerator) { + $this->defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE); + $output .= $this->defaultValue; + } else { + $output .= $this->defaultValue; + } + } + + return $output; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/PropertyGenerator.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/PropertyGenerator.php new file mode 100644 index 0000000..1e9ad3a --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/PropertyGenerator.php @@ -0,0 +1,227 @@ +setName($reflectionProperty->getName()); + + $allDefaultProperties = $reflectionProperty->getDeclaringClass()->getDefaultProperties(); + + $property->setDefaultValue($allDefaultProperties[$reflectionProperty->getName()]); + + if ($reflectionProperty->getDocComment() != '') { + $property->setDocBlock(DocBlockGenerator::fromReflection($reflectionProperty->getDocBlock())); + } + + if ($reflectionProperty->isStatic()) { + $property->setStatic(true); + } + + if ($reflectionProperty->isPrivate()) { + $property->setVisibility(self::VISIBILITY_PRIVATE); + } elseif ($reflectionProperty->isProtected()) { + $property->setVisibility(self::VISIBILITY_PROTECTED); + } else { + $property->setVisibility(self::VISIBILITY_PUBLIC); + } + + $property->setSourceDirty(false); + + return $property; + } + + /** + * Generate from array + * + * @configkey name string [required] Class Name + * @configkey const bool + * @configkey defaultvalue null|bool|string|int|float|array|ValueGenerator + * @configkey flags int + * @configkey abstract bool + * @configkey final bool + * @configkey static bool + * @configkey visibility string + * + * @throws Exception\InvalidArgumentException + * @param array $array + * @return PropertyGenerator + */ + public static function fromArray(array $array) + { + if (!isset($array['name'])) { + throw new Exception\InvalidArgumentException( + 'Property generator requires that a name is provided for this object' + ); + } + + $property = new static($array['name']); + foreach ($array as $name => $value) { + // normalize key + switch (strtolower(str_replace(array('.', '-', '_'), '', $name))) { + case 'const': + $property->setConst($value); + break; + case 'defaultvalue': + $property->setDefaultValue($value); + break; + case 'docblock': + $docBlock = ($value instanceof DocBlockGenerator) ? $value : DocBlockGenerator::fromArray($value); + $property->setDocBlock($docBlock); + break; + case 'flags': + $property->setFlags($value); + break; + case 'abstract': + $property->setAbstract($value); + break; + case 'final': + $property->setFinal($value); + break; + case 'static': + $property->setStatic($value); + break; + case 'visibility': + $property->setVisibility($value); + break; + } + } + + return $property; + } + + /** + * @param string $name + * @param PropertyValueGenerator|string|array $defaultValue + * @param int|array $flags + */ + public function __construct($name = null, $defaultValue = null, $flags = self::FLAG_PUBLIC) + { + if (null !== $name) { + $this->setName($name); + } + if (null !== $defaultValue) { + $this->setDefaultValue($defaultValue); + } + if ($flags !== self::FLAG_PUBLIC) { + $this->setFlags($flags); + } + } + + /** + * @param bool $const + * @return PropertyGenerator + */ + public function setConst($const) + { + if ($const) { + $this->removeFlag(self::FLAG_PUBLIC | self::FLAG_PRIVATE | self::FLAG_PROTECTED); + $this->setFlags(self::FLAG_CONSTANT); + } else { + $this->removeFlag(self::FLAG_CONSTANT); + } + + return $this; + } + + /** + * @return bool + */ + public function isConst() + { + return (bool) ($this->flags & self::FLAG_CONSTANT); + } + + /** + * @param PropertyValueGenerator|mixed $defaultValue + * @param string $defaultValueType + * @param string $defaultValueOutputMode + * + * @return PropertyGenerator + */ + public function setDefaultValue($defaultValue, $defaultValueType = PropertyValueGenerator::TYPE_AUTO, $defaultValueOutputMode = PropertyValueGenerator::OUTPUT_MULTIPLE_LINE) + { + if (!($defaultValue instanceof PropertyValueGenerator)) { + + $defaultValue = new PropertyValueGenerator($defaultValue, $defaultValueType, $defaultValueOutputMode); + } + + $this->defaultValue = $defaultValue; + + return $this; + } + + /** + * @return PropertyValueGenerator + */ + public function getDefaultValue() + { + return $this->defaultValue; + } + + /** + * @throws Exception\RuntimeException + * @return string + */ + public function generate() + { + $name = $this->getName(); + $defaultValue = $this->getDefaultValue(); + + $output = ''; + + if (($docBlock = $this->getDocBlock()) !== null) { + $docBlock->setIndentation(' '); + $output .= $docBlock->generate(); + } + + if ($this->isConst()) { + if ($defaultValue != null && !$defaultValue->isValidConstantType()) { + throw new Exception\RuntimeException(sprintf( + 'The property %s is said to be ' + . 'constant but does not have a valid constant value.', + $this->name + )); + } + $output .= $this->indentation . 'const ' . $name . ' = ' + . (($defaultValue !== null) ? $defaultValue->generate() : 'null;'); + } else { + $output .= $this->indentation + . $this->getVisibility() + . (($this->isStatic()) ? ' static' : '') + . ' $' . $name . ' = ' + . (($defaultValue !== null) ? $defaultValue->generate() : 'null;'); + } + + return $output; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Generator/PropertyValueGenerator.php b/core/vendor/zendframework/zend-code/Zend/Code/Generator/PropertyValueGenerator.php new file mode 100644 index 0000000..227b55c --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Generator/PropertyValueGenerator.php @@ -0,0 +1,21 @@ +setValue($value); + } + if ($type !== self::TYPE_AUTO) { + $this->setType($type); + } + if ($outputMode !== self::OUTPUT_MULTIPLE_LINE) { + $this->setOutputMode($outputMode); + } + if ($constants !== null) { + $this->constants = $constants; + } else { + $this->constants = new ArrayObject(); + } + + } + + /** + * Init constant list by defined and magic constants + */ + public function initEnvironmentConstants() + { + $constants = array( + '__DIR__', + '__FILE__', + '__LINE__', + '__CLASS__', + '__TRAIT__', + '__METHOD__', + '__FUNCTION__', + '__NAMESPACE__', + '::' + ); + $constants = array_merge($constants, array_keys(get_defined_constants()), $this->constants->getArrayCopy()); + $this->constants->exchangeArray($constants); + } + + /** + * Add constant to list + * + * @param string $constant + * + * @return $this + */ + public function addConstant($constant) + { + $this->constants->append($constant); + + return $this; + } + + /** + * Delete constant from constant list + * + * @param string $constant + * + * @return bool + */ + public function deleteConstant($constant) + { + if (($index = array_search($constant, $this->constants->getArrayCopy())) !== false) { + $this->constants->offsetUnset($index); + } + + return $index !== false; + } + + /** + * Return constant list + * + * @return ArrayObject + */ + public function getConstants() + { + return $this->constants; + } + + /** + * @return bool + */ + public function isValidConstantType() + { + if ($this->type == self::TYPE_AUTO) { + $type = $this->getAutoDeterminedType($this->value); + } else { + $type = $this->type; + } + + // valid types for constants + $scalarTypes = array( + self::TYPE_BOOLEAN, + self::TYPE_BOOL, + self::TYPE_NUMBER, + self::TYPE_INTEGER, + self::TYPE_INT, + self::TYPE_FLOAT, + self::TYPE_DOUBLE, + self::TYPE_STRING, + self::TYPE_CONSTANT, + self::TYPE_NULL + ); + + return in_array($type, $scalarTypes); + } + + /** + * @param mixed $value + * @return ValueGenerator + */ + public function setValue($value) + { + $this->value = $value; + return $this; + } + + /** + * @return mixed + */ + public function getValue() + { + return $this->value; + } + + /** + * @param string $type + * @return ValueGenerator + */ + public function setType($type) + { + $this->type = (string) $type; + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param int $arrayDepth + * @return ValueGenerator + */ + public function setArrayDepth($arrayDepth) + { + $this->arrayDepth = (int) $arrayDepth; + return $this; + } + + /** + * @return int + */ + public function getArrayDepth() + { + return $this->arrayDepth; + } + + /** + * @param string $type + * @return string + */ + protected function getValidatedType($type) + { + $types = array( + self::TYPE_AUTO, + self::TYPE_BOOLEAN, + self::TYPE_BOOL, + self::TYPE_NUMBER, + self::TYPE_INTEGER, + self::TYPE_INT, + self::TYPE_FLOAT, + self::TYPE_DOUBLE, + self::TYPE_STRING, + self::TYPE_ARRAY, + self::TYPE_CONSTANT, + self::TYPE_NULL, + self::TYPE_OBJECT, + self::TYPE_OTHER + ); + + if (in_array($type, $types)) { + return $type; + } + + return self::TYPE_AUTO; + } + + /** + * @param mixed $value + * @return string + */ + public function getAutoDeterminedType($value) + { + switch (gettype($value)) { + case 'boolean': + return self::TYPE_BOOLEAN; + case 'string': + foreach ($this->constants as $constant) { + if (strpos($value, $constant) !== false) { + return self::TYPE_CONSTANT; + } + } + return self::TYPE_STRING; + case 'double': + case 'float': + case 'integer': + return self::TYPE_NUMBER; + case 'array': + return self::TYPE_ARRAY; + case 'NULL': + return self::TYPE_NULL; + case 'object': + case 'resource': + case 'unknown type': + default: + return self::TYPE_OTHER; + } + } + + /** + * @throws Exception\RuntimeException + * @return string + */ + public function generate() + { + $type = $this->type; + + if ($type != self::TYPE_AUTO) { + $type = $this->getValidatedType($type); + } + + $value = $this->value; + + if ($type == self::TYPE_AUTO) { + $type = $this->getAutoDeterminedType($value); + + if ($type == self::TYPE_ARRAY) { + $rii = new \RecursiveIteratorIterator( + $it = new \RecursiveArrayIterator($value), + \RecursiveIteratorIterator::SELF_FIRST + ); + foreach ($rii as $curKey => $curValue) { + if (!$curValue instanceof ValueGenerator) { + $curValue = new self($curValue, self::TYPE_AUTO, self::OUTPUT_MULTIPLE_LINE, $this->getConstants()); + $rii->getSubIterator()->offsetSet($curKey, $curValue); + } + $curValue->setArrayDepth($rii->getDepth()); + } + $value = $rii->getSubIterator()->getArrayCopy(); + } + + } + + $output = ''; + + switch ($type) { + case self::TYPE_BOOLEAN: + case self::TYPE_BOOL: + $output .= ($value ? 'true' : 'false'); + break; + case self::TYPE_STRING: + $output .= self::escape($value); + break; + case self::TYPE_NULL: + $output .= 'null'; + break; + case self::TYPE_NUMBER: + case self::TYPE_INTEGER: + case self::TYPE_INT: + case self::TYPE_FLOAT: + case self::TYPE_DOUBLE: + case self::TYPE_CONSTANT: + $output .= $value; + break; + case self::TYPE_ARRAY: + $output .= 'array('; + $curArrayMultiblock = false; + if (count($value) > 1) { + $curArrayMultiblock = true; + if ($this->outputMode == self::OUTPUT_MULTIPLE_LINE) { + $output .= self::LINE_FEED . str_repeat($this->indentation, $this->arrayDepth + 1); + } + } + $outputParts = array(); + $noKeyIndex = 0; + foreach ($value as $n => $v) { + /* @var $v ValueGenerator */ + $v->setArrayDepth($this->arrayDepth + 1); + $partV = $v->generate(); + $short = false; + if (is_int($n)) { + if ($n === $noKeyIndex) { + $short = true; + $noKeyIndex++; + } else { + $noKeyIndex = max($n + 1, $noKeyIndex); + } + } + + if ($short) { + $outputParts[] = $partV; + } else { + $outputParts[] = (is_int($n) ? $n : self::escape($n)) . ' => ' . $partV; + } + } + $padding = ($this->outputMode == self::OUTPUT_MULTIPLE_LINE) + ? self::LINE_FEED . str_repeat($this->indentation, $this->arrayDepth + 1) + : ' '; + $output .= implode(',' . $padding, $outputParts); + if ($curArrayMultiblock == true && $this->outputMode == self::OUTPUT_MULTIPLE_LINE) { + $output .= self::LINE_FEED . str_repeat($this->indentation, $this->arrayDepth + 1); + } + $output .= ')'; + break; + case self::TYPE_OTHER: + default: + throw new Exception\RuntimeException(sprintf( + 'Type "%s" is unknown or cannot be used as property default value.', + get_class($value) + )); + } + + return $output; + } + + /** + * Quotes value for PHP code. + * + * @param string $input Raw string. + * @param bool $quote Whether add surrounding quotes or not. + * @return string PHP-ready code. + */ + public static function escape($input, $quote = true) + { + $output = addcslashes($input, "'"); + + // adds quoting strings + if ($quote) { + $output = "'" . $output . "'"; + } + + return $output; + } + + /** + * @param string $outputMode + * @return ValueGenerator + */ + public function setOutputMode($outputMode) + { + $this->outputMode = (string) $outputMode; + return $this; + } + + /** + * @return string + */ + public function getOutputMode() + { + return $this->outputMode; + } + + public function __toString() + { + return $this->generate(); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/NameInformation.php b/core/vendor/zendframework/zend-code/Zend/Code/NameInformation.php new file mode 100644 index 0000000..dc4a85c --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/NameInformation.php @@ -0,0 +1,157 @@ +setNamespace($namespace); + } + if ($uses) { + $this->setUses($uses); + } + } + + /** + * @param string $namespace + * @return NameInformation + */ + public function setNamespace($namespace) + { + $this->namespace = (string) $namespace; + return $this; + } + + /** + * @return string + */ + public function getNamespace() + { + return $this->namespace; + } + + /** + * @return bool + */ + public function hasNamespace() + { + return ($this->namespace != null); + } + + /** + * @param array $uses + * @return NameInformation + */ + public function setUses(array $uses) + { + $this->uses = array(); + $this->addUses($uses); + + return $this; + } + + /** + * @param array $uses + * @return NameInformation + */ + public function addUses(array $uses) + { + foreach ($uses as $use => $as) { + if (is_int($use)) { + $this->addUse($as); + } elseif (is_string($use)) { + $this->addUse($use, $as); + } + + } + + return $this; + } + + /** + * @param array|string $use + * @param string $as + */ + public function addUse($use, $as = null) + { + if (is_array($use) && array_key_exists('use', $use) && array_key_exists('as', $use)) { + $uses = $use; + $use = $uses['use']; + $as = $uses['as']; + } + + $use = trim($use, '\\'); + if ($as === null) { + $as = trim($use, '\\'); + $nsSeparatorPosition = strrpos($as, '\\'); + if ($nsSeparatorPosition !== false && $nsSeparatorPosition !== 0 && $nsSeparatorPosition != strlen($as)) { + $as = substr($as, $nsSeparatorPosition + 1); + } + } + + $this->uses[$use] = $as; + } + + /** + * @return array + */ + public function getUses() + { + return $this->uses; + } + + /** + * @param string $name + * @return string + */ + public function resolveName($name) + { + if ($this->namespace && !$this->uses && strlen($name) > 0 && $name{0} != '\\') { + return $this->namespace . '\\' . $name; + } + + if (!$this->uses || strlen($name) <= 0 || $name{0} == '\\') { + return ltrim($name, '\\'); + } + + if ($this->namespace || $this->uses) { + $firstPart = $name; + if (($firstPartEnd = strpos($firstPart, '\\')) !== false) { + $firstPart = substr($firstPart, 0, $firstPartEnd); + } else { + $firstPartEnd = strlen($firstPart); + } + if (($fqns = array_search($firstPart, $this->uses)) !== false) { + return substr_replace($name, $fqns, 0, $firstPartEnd); + } + if ($this->namespace) { + return $this->namespace . '\\' . $name; + } + } + + return $name; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/README.md b/core/vendor/zendframework/zend-code/Zend/Code/README.md new file mode 100644 index 0000000..640084b --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/README.md @@ -0,0 +1,15 @@ +Code Component from ZF2 +======================= + +This is the Code component for ZF2. + +- File issues at https://github.com/zendframework/zf2/issues +- Create pull requests against https://github.com/zendframework/zf2 +- Documentation is at http://framework.zend.com/docs + +LICENSE +------- + +The files in this archive are released under the [Zend Framework +license](http://framework.zend.com/license), which is a 3-clause BSD license. + diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/ClassReflection.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/ClassReflection.php new file mode 100644 index 0000000..5e87a4f --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/ClassReflection.php @@ -0,0 +1,230 @@ +getFileName()); + + return $instance; + } + + /** + * Return the classes DocBlock reflection object + * + * @return DocBlockReflection + * @throws Exception\ExceptionInterface for missing DocBock or invalid reflection class + */ + public function getDocBlock() + { + if (isset($this->docBlock)) { + return $this->docBlock; + } + + if ('' == $this->getDocComment()) { + return false; + } + + $this->docBlock = new DocBlockReflection($this); + + return $this->docBlock; + } + + /** + * @param AnnotationManager $annotationManager + * @return AnnotationCollection + */ + public function getAnnotations(AnnotationManager $annotationManager) + { + $docComment = $this->getDocComment(); + if ($docComment == '') { + return false; + } + + if (!$this->annotations) { + $fileScanner = new FileScanner($this->getFileName()); + $nameInformation = $fileScanner->getClassNameInformation($this->getName()); + $this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation); + } + + return $this->annotations; + } + + /** + * Return the start line of the class + * + * @param bool $includeDocComment + * @return int + */ + public function getStartLine($includeDocComment = false) + { + if ($includeDocComment && $this->getDocComment() != '') { + return $this->getDocBlock()->getStartLine(); + } + + return parent::getStartLine(); + } + + /** + * Return the contents of the class + * + * @param bool $includeDocBlock + * @return string + */ + public function getContents($includeDocBlock = true) + { + $filename = $this->getFileName(); + $filelines = file($filename); + $startnum = $this->getStartLine($includeDocBlock); + $endnum = $this->getEndLine() - $this->getStartLine(); + + // Ensure we get between the open and close braces + $lines = array_slice($filelines, $startnum, $endnum); + array_unshift($lines, $filelines[$startnum-1]); + + return strstr(implode('', $lines), '{'); + } + + /** + * Get all reflection objects of implemented interfaces + * + * @return ClassReflection[] + */ + public function getInterfaces() + { + $phpReflections = parent::getInterfaces(); + $zendReflections = array(); + while ($phpReflections && ($phpReflection = array_shift($phpReflections))) { + $instance = new ClassReflection($phpReflection->getName()); + $zendReflections[] = $instance; + unset($phpReflection); + } + unset($phpReflections); + + return $zendReflections; + } + + /** + * Return method reflection by name + * + * @param string $name + * @return MethodReflection + */ + public function getMethod($name) + { + $method = new MethodReflection($this->getName(), parent::getMethod($name)->getName()); + + return $method; + } + + /** + * Get reflection objects of all methods + * + * @param string $filter + * @return MethodReflection[] + */ + public function getMethods($filter = -1) + { + $methods = array(); + foreach (parent::getMethods($filter) as $method) { + $instance = new MethodReflection($this->getName(), $method->getName()); + $methods[] = $instance; + } + + return $methods; + } + + /** + * Get parent reflection class of reflected class + * + * @return ClassReflection|bool + */ + public function getParentClass() + { + $phpReflection = parent::getParentClass(); + if ($phpReflection) { + $zendReflection = new ClassReflection($phpReflection->getName()); + unset($phpReflection); + + return $zendReflection; + } + + return false; + } + + /** + * Return reflection property of this class by name + * + * @param string $name + * @return PropertyReflection + */ + public function getProperty($name) + { + $phpReflection = parent::getProperty($name); + $zendReflection = new PropertyReflection($this->getName(), $phpReflection->getName()); + unset($phpReflection); + + return $zendReflection; + } + + /** + * Return reflection properties of this class + * + * @param int $filter + * @return PropertyReflection[] + */ + public function getProperties($filter = -1) + { + $phpReflections = parent::getProperties($filter); + $zendReflections = array(); + while ($phpReflections && ($phpReflection = array_shift($phpReflections))) { + $instance = new PropertyReflection($this->getName(), $phpReflection->getName()); + $zendReflections[] = $instance; + unset($phpReflection); + } + unset($phpReflections); + + return $zendReflections; + } + + public function toString() + { + return parent::__toString(); + } + + public function __toString() + { + return parent::__toString(); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/AuthorTag.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/AuthorTag.php new file mode 100644 index 0000000..9d21f7a --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/AuthorTag.php @@ -0,0 +1,74 @@ +]*)\>)?(.*)$/u', $tagDocblockLine, $match)) { + return; + } + + if ($match[1] !== '') { + $this->authorName = rtrim($match[1]); + } + + if (isset($match[3]) && $match[3] !== '') { + $this->authorEmail = $match[3]; + } + } + + /** + * @return null|string + */ + public function getAuthorName() + { + return $this->authorName; + } + + /** + * @return null|string + */ + public function getAuthorEmail() + { + return $this->authorEmail; + } + + public function __toString() + { + return 'DocBlock Tag [ * @' . $this->getName() . ' ]' . PHP_EOL; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/GenericTag.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/GenericTag.php new file mode 100644 index 0000000..3f31249 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/GenericTag.php @@ -0,0 +1,107 @@ +contentSplitCharacter = $contentSplitCharacter; + } + + /** + * @param string $tagDocBlockLine + * @return void + */ + public function initialize($tagDocBlockLine) + { + $this->parse($tagDocBlockLine); + } + + /** + * Get annotation tag name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * @param int $position + * @return string + */ + public function returnValue($position) + { + return $this->values[$position]; + } + + /** + * Serialize to string + * + * Required by Reflector + * + * @todo What should this do? + * @return string + */ + public function __toString() + { + return 'DocBlock Tag [ * @' . $this->name . ' ]' . PHP_EOL; + } + + /** + * @param string $docBlockLine + */ + protected function parse($docBlockLine) + { + $this->content = trim($docBlockLine); + $this->values = explode($this->contentSplitCharacter, $docBlockLine); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/LicenseTag.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/LicenseTag.php new file mode 100644 index 0000000..76ae619 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/LicenseTag.php @@ -0,0 +1,74 @@ +url = trim($match[1]); + } + + if (isset($match[2]) && $match[2] !== '') { + $this->licenseName = $match[2]; + } + } + + /** + * @return null|string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @return null|string + */ + public function getLicenseName() + { + return $this->licenseName; + } + + public function __toString() + { + return 'DocBlock Tag [ * @' . $this->getName() . ' ]' . PHP_EOL; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/MethodTag.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/MethodTag.php new file mode 100644 index 0000000..d07d495 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/MethodTag.php @@ -0,0 +1,124 @@ +isStatic = true; + } + + if ($match[2] !== '') { + $this->types = explode('|', rtrim($match[2])); + } + + $this->methodName = $match[3]; + + if ($match[4] !== '') { + $this->description = $match[4]; + } + } + + /** + * Get return value type + * + * @return null|string + * @deprecated 2.0.4 use getTypes instead + */ + public function getReturnType() + { + if (empty($this->types)) { + return null; + } + + return $this->types[0]; + } + + public function getTypes() + { + return $this->types; + } + + /** + * @return string + */ + public function getMethodName() + { + return $this->methodName; + } + + /** + * @return null|string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Is method static + * + * @return bool + */ + public function isStatic() + { + return $this->isStatic; + } + + public function __toString() + { + return 'DocBlock Tag [ * @' . $this->getName() . ' ]' . PHP_EOL; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/ParamTag.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/ParamTag.php new file mode 100644 index 0000000..1fddda3 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/ParamTag.php @@ -0,0 +1,98 @@ +types = explode('|', $matches[1]); + + if (isset($matches[2])) { + $this->variableName = $matches[2]; + } + + if (isset($matches[3])) { + $this->description = trim(preg_replace('#\s+#', ' ', $matches[3])); + } + } + + /** + * Get parameter variable type + * + * @return string + * @deprecated 2.0.4 use getTypes instead + */ + public function getType() + { + if (empty($this->types)) { + return ''; + } + + return $this->types[0]; + } + + public function getTypes() + { + return $this->types; + } + + /** + * Get parameter name + * + * @return string + */ + public function getVariableName() + { + return $this->variableName; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/PhpDocTypedTagInterface.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/PhpDocTypedTagInterface.php new file mode 100644 index 0000000..2e277cf --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/PhpDocTypedTagInterface.php @@ -0,0 +1,20 @@ +types = explode('|', rtrim($match[1])); + } + + if ($match[2] !== '') { + $this->propertyName = $match[2]; + } + + if ($match[3] !== '') { + $this->description = $match[3]; + } + } + + /** + * @return null|string + * @deprecated 2.0.4 use getTypes instead + */ + public function getType() + { + if (empty($this->types)) { + return null; + } + + return $this->types[0]; + } + + public function getTypes() + { + return $this->types; + } + + /** + * @return null|string + */ + public function getPropertyName() + { + return $this->propertyName; + } + + /** + * @return null|string + */ + public function getDescription() + { + return $this->description; + } + + public function __toString() + { + return 'DocBlock Tag [ * @' . $this->getName() . ' ]' . PHP_EOL; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/ReturnTag.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/ReturnTag.php new file mode 100644 index 0000000..b8f99c0 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/ReturnTag.php @@ -0,0 +1,75 @@ +types = explode('|', $matches[1]); + + if (isset($matches[2])) { + $this->description = trim(preg_replace('#\s+#', ' ', $matches[2])); + } + } + + /** + * @return string + * @deprecated 2.0.4 use getTypes instead + */ + public function getType() + { + if (empty($this->types)) { + return ''; + } + + return $this->types[0]; + } + + public function getTypes() + { + return $this->types; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/TagInterface.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/TagInterface.php new file mode 100644 index 0000000..08d5cf9 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/Tag/TagInterface.php @@ -0,0 +1,24 @@ +type = $matches[1]; + + if (isset($matches[2])) { + $this->description = $matches[2]; + } + } + + /** + * Get return variable type + * + * @return string + * @deprecated 2.0.4 use getTypes instead + */ + public function getType() + { + return $this->type; + } + + public function getTypes() + { + return array($this->type); + } + + public function getDescription() + { + return $this->description; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/TagManager.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/TagManager.php new file mode 100644 index 0000000..761b39c --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlock/TagManager.php @@ -0,0 +1,124 @@ +addTagPrototype($prototype); + } + } elseif ($prototypes === self::USE_DEFAULT_PROTOTYPES) { + $this->useDefaultPrototypes(); + } + } + + /** + * @return void + */ + public function useDefaultPrototypes() + { + $this->addTagPrototype(new Tag\ParamTag()); + $this->addTagPrototype(new Tag\ReturnTag()); + $this->addTagPrototype(new Tag\MethodTag()); + $this->addTagPrototype(new Tag\PropertyTag()); + $this->addTagPrototype(new Tag\AuthorTag()); + $this->addTagPrototype(new Tag\LicenseTag()); + $this->addTagPrototype(new Tag\ThrowsTag()); + $this->addTagPrototype(new Tag\GenericTag()); + } + + /** + * @param TagInterface $tag + * @throws Exception\InvalidArgumentException + */ + public function addTagPrototype(TagInterface $tag) + { + $tagName = str_replace(array('-', '_'), '', $tag->getName()); + + if (in_array($tagName, $this->tagNames)) { + throw new Exception\InvalidArgumentException('A tag with this name already exists in this manager'); + } + + $this->tagNames[] = $tagName; + $this->tags[] = $tag; + + if ($tag instanceof GenericTag) { + $this->genericTag = $tag; + } + } + + /** + * @param string $tagName + * @return bool + */ + public function hasTag($tagName) + { + // otherwise, only if its name exists as a key + return in_array(str_replace(array('-', '_'), '', $tagName), $this->tagNames); + } + + /** + * @param string $tagName + * @param string $content + * @return GenericTag + * @throws Exception\RuntimeException + */ + public function createTag($tagName, $content = null) + { + $tagName = str_replace(array('-', '_'), '', $tagName); + + if (!$this->hasTag($tagName) && !isset($this->genericTag)) { + throw new Exception\RuntimeException('This tag name is not supported by this tag manager'); + } + + $index = array_search($tagName, $this->tagNames); + + /* @var TagInterface $tag */ + $tag = ($index !== false) ? $this->tags[$index] : $this->genericTag; + + $newTag = clone $tag; + if ($content) { + $newTag->initialize($content); + } + + if ($newTag instanceof GenericTag) { + $newTag->setName($tagName); + } + + return $newTag; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlockReflection.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlockReflection.php new file mode 100644 index 0000000..3b2257e --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/DocBlockReflection.php @@ -0,0 +1,292 @@ +tagManager = $tagManager ? : new DocBlockTagManager(DocBlockTagManager::USE_DEFAULT_PROTOTYPES); + + if ($commentOrReflector instanceof Reflector) { + $this->reflector = $commentOrReflector; + if (!method_exists($commentOrReflector, 'getDocComment')) { + throw new Exception\InvalidArgumentException('Reflector must contain method "getDocComment"'); + } + /* @var MethodReflection $commentOrReflector */ + $this->docComment = $commentOrReflector->getDocComment(); + + // determine line numbers + $lineCount = substr_count($this->docComment, "\n"); + $this->startLine = $this->reflector->getStartLine() - $lineCount - 1; + $this->endLine = $this->reflector->getStartLine() - 1; + + } elseif (is_string($commentOrReflector)) { + $this->docComment = $commentOrReflector; + } else { + throw new Exception\InvalidArgumentException(sprintf( + '%s must have a (string) DocComment or a Reflector in the constructor', + get_class($this) + )); + } + + if ($this->docComment == '') { + throw new Exception\InvalidArgumentException('DocComment cannot be empty'); + } + + $this->reflect(); + } + + /** + * Retrieve contents of DocBlock + * + * @return string + */ + public function getContents() + { + $this->reflect(); + + return $this->cleanDocComment; + } + + /** + * Get start line (position) of DocBlock + * + * @return int + */ + public function getStartLine() + { + $this->reflect(); + + return $this->startLine; + } + + /** + * Get last line (position) of DocBlock + * + * @return int + */ + public function getEndLine() + { + $this->reflect(); + + return $this->endLine; + } + + /** + * Get DocBlock short description + * + * @return string + */ + public function getShortDescription() + { + $this->reflect(); + + return $this->shortDescription; + } + + /** + * Get DocBlock long description + * + * @return string + */ + public function getLongDescription() + { + $this->reflect(); + + return $this->longDescription; + } + + /** + * Does the DocBlock contain the given annotation tag? + * + * @param string $name + * @return bool + */ + public function hasTag($name) + { + $this->reflect(); + foreach ($this->tags as $tag) { + if ($tag->getName() == $name) { + return true; + } + } + + return false; + } + + /** + * Retrieve the given DocBlock tag + * + * @param string $name + * @return DocBlockTagInterface|false + */ + public function getTag($name) + { + $this->reflect(); + foreach ($this->tags as $tag) { + if ($tag->getName() == $name) { + return $tag; + } + } + + return false; + } + + /** + * Get all DocBlock annotation tags + * + * @param string $filter + * @return DocBlockTagInterface[] + */ + public function getTags($filter = null) + { + $this->reflect(); + if ($filter === null || !is_string($filter)) { + return $this->tags; + } + + $returnTags = array(); + foreach ($this->tags as $tag) { + if ($tag->getName() == $filter) { + $returnTags[] = $tag; + } + } + + return $returnTags; + } + + /** + * Parse the DocBlock + * + * @return void + */ + protected function reflect() + { + if ($this->isReflected) { + return; + } + + $docComment = $this->docComment; // localize variable + + // create a clean docComment + $this->cleanDocComment = preg_replace("#[ \t]*(?:/\*\*|\*/|\*)[ ]{0,1}(.*)?#", '$1', $docComment); + $this->cleanDocComment = ltrim($this->cleanDocComment, + "\r\n"); // @todo should be changed to remove first and last empty line + + $scanner = new DocBlockScanner($docComment); + $this->shortDescription = ltrim($scanner->getShortDescription()); + $this->longDescription = ltrim($scanner->getLongDescription()); + + foreach ($scanner->getTags() as $tag) { + $this->tags[] = $this->tagManager->createTag(ltrim($tag['name'], '@'), ltrim($tag['value'])); + } + + $this->isReflected = true; + } + + public function toString() + { + $str = "DocBlock [ /* DocBlock */ ] {" . PHP_EOL . PHP_EOL; + $str .= " - Tags [" . count($this->tags) . "] {" . PHP_EOL; + + foreach ($this->tags AS $tag) { + $str .= " " . $tag; + } + + $str .= " }" . PHP_EOL; + $str .= "}" . PHP_EOL; + + return $str; + } + + /** + * Serialize to string + * + * Required by the Reflector interface + * + * @return string + */ + public function __toString() + { + return $this->toString(); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/Exception/BadMethodCallException.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/Exception/BadMethodCallException.php new file mode 100644 index 0000000..a1eae8c --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/Exception/BadMethodCallException.php @@ -0,0 +1,16 @@ +filePath = $fileRealPath; + $this->reflect(); + } + + /** + * Required by the Reflector interface. + * + * @todo What should this do? + * @return null + */ + public static function export() + { + return null; + } + + /** + * Return the file name of the reflected file + * + * @return string + */ + public function getFileName() + { + // @todo get file name from path + return $this->filePath; + } + + /** + * Get the start line - Always 1, staying consistent with the Reflection API + * + * @return int + */ + public function getStartLine() + { + return $this->startLine; + } + + /** + * Get the end line / number of lines + * + * @return int + */ + public function getEndLine() + { + return $this->endLine; + } + + /** + * @return string + */ + public function getDocComment() + { + return $this->docComment; + } + + /** + * @return DocBlockReflection + */ + public function getDocBlock() + { + if (!($docComment = $this->getDocComment())) { + return false; + } + + $instance = new DocBlockReflection($docComment); + + return $instance; + } + + /** + * @return array + */ + public function getNamespaces() + { + return $this->namespaces; + } + + /** + * @return string + */ + public function getNamespace() + { + if (count($this->namespaces) == 0) { + return null; + } + + return $this->namespaces[0]; + } + + /** + * @return array + */ + public function getUses() + { + return $this->uses; + } + + /** + * Return the reflection classes of the classes found inside this file + * + * @return ClassReflection[] + */ + public function getClasses() + { + $classes = array(); + foreach ($this->classes as $class) { + $classes[] = new ClassReflection($class); + } + + return $classes; + } + + /** + * Return the reflection functions of the functions found inside this file + * + * @return FunctionReflection[] + */ + public function getFunctions() + { + $functions = array(); + foreach ($this->functions as $function) { + $functions[] = new FunctionReflection($function); + } + + return $functions; + } + + /** + * Retrieve the reflection class of a given class found in this file + * + * @param null|string $name + * @return ClassReflection + * @throws Exception\InvalidArgumentException for invalid class name or invalid reflection class + */ + public function getClass($name = null) + { + if (null === $name) { + reset($this->classes); + $selected = current($this->classes); + + return new ClassReflection($selected); + } + + if (in_array($name, $this->classes)) { + return new ClassReflection($name); + } + + throw new Exception\InvalidArgumentException(sprintf( + 'Class by name %s not found.', + $name + )); + } + + /** + * Return the full contents of file + * + * @return string + */ + public function getContents() + { + return file_get_contents($this->filePath); + } + + public function toString() + { + return ''; // @todo + } + + /** + * Serialize to string + * + * Required by the Reflector interface + * + * @todo What should this serialization look like? + * @return string + */ + public function __toString() + { + return ''; + } + + /** + * This method does the work of "reflecting" the file + * + * Uses Zend\Code\Scanner\FileScanner to gather file information + * + * @return void + */ + protected function reflect() + { + $scanner = new CachingFileScanner($this->filePath); + $this->docComment = $scanner->getDocComment(); + $this->requiredFiles = $scanner->getIncludes(); + $this->classes = $scanner->getClassNames(); + $this->namespaces = $scanner->getNamespaces(); + $this->uses = $scanner->getUses(); + } + + /** + * Validate / check a file level DocBlock + * + * @param array $tokens Array of tokenizer tokens + * @return void + */ + protected function checkFileDocBlock($tokens) + { + foreach ($tokens as $token) { + $type = $token[0]; + $value = $token[1]; + $lineNum = $token[2]; + if (($type == T_OPEN_TAG) || ($type == T_WHITESPACE)) { + continue; + } elseif ($type == T_DOC_COMMENT) { + $this->docComment = $value; + $this->startLine = $lineNum + substr_count($value, "\n") + 1; + + return; + } else { + // Only whitespace is allowed before file DocBlocks + return; + } + } + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/FunctionReflection.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/FunctionReflection.php new file mode 100644 index 0000000..75b7ab8 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/FunctionReflection.php @@ -0,0 +1,124 @@ +getDocComment())) { + throw new Exception\InvalidArgumentException(sprintf( + '%s does not have a DocBlock', + $this->getName() + )); + } + + $instance = new DocBlockReflection($comment); + + return $instance; + } + + /** + * Get start line (position) of function + * + * @param bool $includeDocComment + * @return int + */ + public function getStartLine($includeDocComment = false) + { + if ($includeDocComment) { + if ($this->getDocComment() != '') { + return $this->getDocBlock()->getStartLine(); + } + } + + return parent::getStartLine(); + } + + /** + * Get contents of function + * + * @param bool $includeDocBlock + * @return string + */ + public function getContents($includeDocBlock = true) + { + return implode("\n", + array_splice( + file($this->getFileName()), + $this->getStartLine($includeDocBlock), + ($this->getEndLine() - $this->getStartLine()), + true + ) + ); + } + + /** + * Get function parameters + * + * @return ParameterReflection[] + */ + public function getParameters() + { + $phpReflections = parent::getParameters(); + $zendReflections = array(); + while ($phpReflections && ($phpReflection = array_shift($phpReflections))) { + $instance = new ParameterReflection($this->getName(), $phpReflection->getName()); + $zendReflections[] = $instance; + unset($phpReflection); + } + unset($phpReflections); + + return $zendReflections; + } + + /** + * Get return type tag + * + * @throws Exception\InvalidArgumentException + * @return ReturnTag + */ + public function getReturn() + { + $docBlock = $this->getDocBlock(); + if (!$docBlock->hasTag('return')) { + throw new Exception\InvalidArgumentException( + 'Function does not specify an @return annotation tag; cannot determine return type' + ); + } + + $tag = $docBlock->getTag('return'); + return new DocBlockReflection('@return ' . $tag->getDescription()); + } + + public function toString() + { + return $this->__toString(); + } + + /** + * Required due to bug in php + * + * @return string + */ + public function __toString() + { + return parent::__toString(); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/MethodReflection.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/MethodReflection.php new file mode 100644 index 0000000..4ca55c4 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/MethodReflection.php @@ -0,0 +1,169 @@ +getDocComment()) { + return false; + } + + $instance = new DocBlockReflection($this); + + return $instance; + } + + /** + * @param AnnotationManager $annotationManager + * @return AnnotationScanner + */ + public function getAnnotations(AnnotationManager $annotationManager) + { + if (($docComment = $this->getDocComment()) == '') { + return false; + } + + if (!$this->annotations) { + $cachingFileScanner = new CachingFileScanner($this->getFileName()); + $nameInformation = $cachingFileScanner->getClassNameInformation($this->getDeclaringClass()->getName()); + + $this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation); + } + + return $this->annotations; + } + + /** + * Get start line (position) of method + * + * @param bool $includeDocComment + * @return int + */ + public function getStartLine($includeDocComment = false) + { + if ($includeDocComment) { + if ($this->getDocComment() != '') { + return $this->getDocBlock()->getStartLine(); + } + } + + return parent::getStartLine(); + } + + /** + * Get reflection of declaring class + * + * @return ClassReflection + */ + public function getDeclaringClass() + { + $phpReflection = parent::getDeclaringClass(); + $zendReflection = new ClassReflection($phpReflection->getName()); + unset($phpReflection); + + return $zendReflection; + } + + /** + * Get all method parameter reflection objects + * + * @return ParameterReflection[] + */ + public function getParameters() + { + $phpReflections = parent::getParameters(); + $zendReflections = array(); + while ($phpReflections && ($phpReflection = array_shift($phpReflections))) { + $instance = new ParameterReflection(array( + $this->getDeclaringClass()->getName(), + $this->getName()), + $phpReflection->getName() + ); + $zendReflections[] = $instance; + unset($phpReflection); + } + unset($phpReflections); + + return $zendReflections; + } + + /** + * Get method contents + * + * @param bool $includeDocBlock + * @return string + */ + public function getContents($includeDocBlock = true) + { + $fileContents = file($this->getFileName()); + $startNum = $this->getStartLine($includeDocBlock); + $endNum = ($this->getEndLine() - $this->getStartLine()); + + return implode("\n", array_splice($fileContents, $startNum, $endNum, true)); + } + + /** + * Get method body + * + * @return string + */ + public function getBody() + { + $lines = array_slice( + file($this->getDeclaringClass()->getFileName(), FILE_IGNORE_NEW_LINES), + $this->getStartLine(), + ($this->getEndLine() - $this->getStartLine()), + true + ); + + $firstLine = array_shift($lines); + + if (trim($firstLine) !== '{') { + array_unshift($lines, $firstLine); + } + + $lastLine = array_pop($lines); + + if (trim($lastLine) !== '}') { + array_push($lines, $lastLine); + } + + // just in case we had code on the bracket lines + return rtrim(ltrim(implode("\n", $lines), '{'), '}'); + } + + public function toString() + { + return parent::__toString(); + } + + public function __toString() + { + return parent::__toString(); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/ParameterReflection.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/ParameterReflection.php new file mode 100644 index 0000000..4b8b067 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/ParameterReflection.php @@ -0,0 +1,110 @@ +getName()); + unset($phpReflection); + + return $zendReflection; + } + + /** + * Get class reflection object + * + * @return ClassReflection + */ + public function getClass() + { + $phpReflection = parent::getClass(); + if ($phpReflection == null) { + return null; + } + + $zendReflection = new ClassReflection($phpReflection->getName()); + unset($phpReflection); + + return $zendReflection; + } + + /** + * Get declaring function reflection object + * + * @return FunctionReflection|MethodReflection + */ + public function getDeclaringFunction() + { + $phpReflection = parent::getDeclaringFunction(); + if ($phpReflection instanceof \ReflectionMethod) { + $zendReflection = new MethodReflection($this->getDeclaringClass()->getName(), $phpReflection->getName()); + } else { + $zendReflection = new FunctionReflection($phpReflection->getName()); + } + unset($phpReflection); + + return $zendReflection; + } + + /** + * Get parameter type + * + * @return string + */ + public function getType() + { + if ($this->isArray()) { + return 'array'; + } elseif (method_exists($this, 'isCallable') && $this->isCallable()) { + return 'callable'; + } + + if (($class = $this->getClass()) instanceof \ReflectionClass) { + return $class->getName(); + } + + $docBlock = $this->getDeclaringFunction()->getDocBlock(); + if (!$docBlock instanceof DocBlockReflection) { + return null; + } + + $params = $docBlock->getTags('param'); + if (isset($params[$this->getPosition()])) { + return $params[$this->getPosition()]->getType(); + } + + return null; + } + + public function toString() + { + return parent::__toString(); + } + + public function __toString() + { + return parent::__toString(); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/PropertyReflection.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/PropertyReflection.php new file mode 100644 index 0000000..62b7751 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/PropertyReflection.php @@ -0,0 +1,91 @@ +getName()); + unset($phpReflection); + + return $zendReflection; + } + + /** + * Get DocBlock comment + * + * @return string|false False if no DocBlock defined + */ + public function getDocComment() + { + return parent::getDocComment(); + } + + /** + * @return false|DocBlockReflection + */ + public function getDocBlock() + { + if (!($docComment = $this->getDocComment())) { + return false; + } + + $docBlockReflection = new DocBlockReflection($docComment); + + return $docBlockReflection; + } + + /** + * @param AnnotationManager $annotationManager + * @return AnnotationScanner + */ + public function getAnnotations(AnnotationManager $annotationManager) + { + if (null !== $this->annotations) { + return $this->annotations; + } + + if (($docComment = $this->getDocComment()) == '') { + return false; + } + + $class = $this->getDeclaringClass(); + $cachingFileScanner = new CachingFileScanner($class->getFileName()); + $nameInformation = $cachingFileScanner->getClassNameInformation($class->getName()); + $this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation); + + return $this->annotations; + } + + public function toString() + { + return $this->__toString(); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Reflection/ReflectionInterface.php b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/ReflectionInterface.php new file mode 100644 index 0000000..862576a --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Reflection/ReflectionInterface.php @@ -0,0 +1,17 @@ +directories as $scanner) { + $classes += $scanner->getClasses(); + } + if ($returnScannerClass) { + foreach ($classes as $index => $class) { + $classes[$index] = $this->getClass($class, $returnScannerClass, $returnDerivedScannerClass); + } + } + + return $classes; + } + + /** + * @param string $class + * @return bool + */ + public function hasClass($class) + { + foreach ($this->directories as $scanner) { + if ($scanner->hasClass($class)) { + break; + } else { + unset($scanner); + } + } + + return (isset($scanner)); + } + + /** + * @param string $class + * @param bool $returnScannerClass + * @param bool $returnDerivedScannerClass + * @return ClassScanner|DerivedClassScanner + * @throws Exception\RuntimeException + */ + public function getClass($class, $returnScannerClass = true, $returnDerivedScannerClass = false) + { + foreach ($this->directories as $scanner) { + if ($scanner->hasClass($class)) { + break; + } else { + unset($scanner); + } + } + + if (!isset($scanner)) { + throw new Exception\RuntimeException('Class by that name was not found.'); + } + + $classScanner = $scanner->getClass($class); + + return new DerivedClassScanner($classScanner, $this); + } + + /** + * @param bool $returnScannerClass + */ + public function getFunctions($returnScannerClass = false) + { + $this->scan(); + + if (!$returnScannerClass) { + $functions = array(); + foreach ($this->infos as $info) { + if ($info['type'] == 'function') { + $functions[] = $info['name']; + } + } + + return $functions; + } + $scannerClass = new FunctionScanner(); + // @todo + } + + /* + public static function export() + { + // @todo + } + + public function __toString() + { + // @todo + } + */ + +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/AnnotationScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/AnnotationScanner.php new file mode 100644 index 0000000..4770b6d --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/AnnotationScanner.php @@ -0,0 +1,337 @@ +annotationManager = $annotationManager; + $this->docComment = $docComment; + $this->nameInformation = $nameInformation; + $this->scan($this->tokenize()); + } + + /** + * @param NameInformation $nameInformation + */ + public function setNameInformation(NameInformation $nameInformation) + { + $this->nameInformation = $nameInformation; + } + + /** + * @param array $tokens + */ + protected function scan(array $tokens) + { + $annotations = array(); + $annotationIndex = -1; + $contentEnd = false; + + reset($tokens); + + SCANNER_TOP: + $token = current($tokens); + + switch ($token[0]) { + + case 'ANNOTATION_CLASS': + + $contentEnd = false; + $annotationIndex++; + $class = substr($token[1], 1); + $class = $this->nameInformation->resolveName($class); + $annotations[$annotationIndex] = array($class, null); + goto SCANNER_CONTINUE; + + case 'ANNOTATION_CONTENT_START': + + $annotations[$annotationIndex][1] = ''; + + case 'ANNOTATION_CONTENT_END': + case 'ANNOTATION_CONTENT': + case 'ANNOTATION_WHITESPACE': + case 'ANNOTATION_NEWLINE': + + if (!$contentEnd && isset($annotations[$annotationIndex]) && is_string($annotations[$annotationIndex][1])) { + $annotations[$annotationIndex][1] .= $token[1]; + } + + if ($token[0] === 'ANNOTATION_CONTENT_END') { + $contentEnd = true; + } + + goto SCANNER_CONTINUE; + } + + SCANNER_CONTINUE: + if (next($tokens) === false) { + goto SCANNER_END; + } + goto SCANNER_TOP; + + SCANNER_END: + + foreach ($annotations as $annotation) { + $annotation[] = '@' . $annotation[0] . $annotation[1]; + $annotationObject = $this->annotationManager->createAnnotation($annotation); + if ($annotationObject) { + $this->append($annotationObject); + } + } + } + + /** + * @return array + */ + protected function tokenize() + { + static $CONTEXT_DOCBLOCK = 0x01; + static $CONTEXT_ASTERISK = 0x02; + static $CONTEXT_CLASS = 0x04; + static $CONTEXT_CONTENT = 0x08; + + $context = 0x00; + $stream = $this->docComment; + $streamIndex = null; + $tokens = array(); + $tokenIndex = null; + $currentChar = null; + $currentWord = null; + $currentLine = null; + + $annotationParentCount = 0; + + $MACRO_STREAM_ADVANCE_CHAR = function ($positionsForward = 1) use (&$stream, &$streamIndex, &$currentChar, &$currentWord, &$currentLine) { + $positionsForward = ($positionsForward > 0) ? $positionsForward : 1; + $streamIndex = ($streamIndex === null) ? 0 : $streamIndex + $positionsForward; + if (!isset($stream[$streamIndex])) { + $currentChar = false; + + return false; + } + $currentChar = $stream[$streamIndex]; + $matches = array(); + $currentLine = (preg_match('#(.*)\n#', $stream, $matches, null, + $streamIndex) === 1) ? $matches[1] : substr($stream, $streamIndex); + if ($currentChar === ' ') { + $currentWord = (preg_match('#( +)#', $currentLine, $matches) === 1) ? $matches[1] : $currentLine; + } else { + $currentWord = (($matches = strpos($currentLine, ' ')) !== false) ? substr($currentLine, 0, + $matches) : $currentLine; + } + + return $currentChar; + }; + $MACRO_STREAM_ADVANCE_WORD = function () use (&$currentWord, &$MACRO_STREAM_ADVANCE_CHAR) { + return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentWord)); + }; + $MACRO_STREAM_ADVANCE_LINE = function () use (&$currentLine, &$MACRO_STREAM_ADVANCE_CHAR) { + return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentLine)); + }; + $MACRO_TOKEN_ADVANCE = function () use (&$tokenIndex, &$tokens) { + $tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1; + $tokens[$tokenIndex] = array('ANNOTATION_UNKNOWN', ''); + }; + $MACRO_TOKEN_SET_TYPE = function ($type) use (&$tokenIndex, &$tokens) { + $tokens[$tokenIndex][0] = $type; + }; + $MACRO_TOKEN_APPEND_CHAR = function () use (&$currentChar, &$tokens, &$tokenIndex) { + $tokens[$tokenIndex][1] .= $currentChar; + }; + $MACRO_TOKEN_APPEND_WORD = function () use (&$currentWord, &$tokens, &$tokenIndex) { + $tokens[$tokenIndex][1] .= $currentWord; + }; + $MACRO_TOKEN_APPEND_LINE = function () use (&$currentLine, &$tokens, &$tokenIndex) { + $tokens[$tokenIndex][1] .= $currentLine; + }; + $MACRO_HAS_CONTEXT = function ($which) use (&$context) { + return (($context & $which) === $which); + }; + + $MACRO_STREAM_ADVANCE_CHAR(); + $MACRO_TOKEN_ADVANCE(); + + TOKENIZER_TOP: + + if ($context === 0x00 && $currentChar === '/' && $currentWord === '/**') { + $MACRO_TOKEN_SET_TYPE('ANNOTATION_COMMENTSTART'); + $MACRO_TOKEN_APPEND_WORD(); + $MACRO_TOKEN_ADVANCE(); + $context |= $CONTEXT_DOCBLOCK; + $context |= $CONTEXT_ASTERISK; + if ($MACRO_STREAM_ADVANCE_WORD() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($MACRO_HAS_CONTEXT($CONTEXT_CLASS)) { + if (in_array($currentChar, array(' ', '(', "\n"))) { + $context &= ~$CONTEXT_CLASS; + $MACRO_TOKEN_ADVANCE(); + } else { + $MACRO_TOKEN_APPEND_CHAR(); + if ($MACRO_STREAM_ADVANCE_CHAR() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + } + + if ($currentChar === "\n") { + $MACRO_TOKEN_SET_TYPE('ANNOTATION_NEWLINE'); + $MACRO_TOKEN_APPEND_CHAR(); + $MACRO_TOKEN_ADVANCE(); + $context &= ~$CONTEXT_ASTERISK; + $context &= ~$CONTEXT_CLASS; + if ($MACRO_STREAM_ADVANCE_CHAR() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($currentChar === ' ') { + $MACRO_TOKEN_SET_TYPE(($MACRO_HAS_CONTEXT($CONTEXT_ASTERISK)) ? 'ANNOTATION_WHITESPACE' : 'ANNOTATION_WHITESPACE_INDENT'); + $MACRO_TOKEN_APPEND_WORD(); + $MACRO_TOKEN_ADVANCE(); + if ($MACRO_STREAM_ADVANCE_WORD() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($MACRO_HAS_CONTEXT($CONTEXT_CONTENT) && $MACRO_HAS_CONTEXT($CONTEXT_ASTERISK)) { + $MACRO_TOKEN_SET_TYPE('ANNOTATION_CONTENT'); + $annotationParentCount += substr_count($currentWord, '('); + $annotationParentCount -= substr_count($currentWord, ')'); + + if ($annotationParentCount === 0) { + $context &= ~$CONTEXT_CONTENT; + $MACRO_TOKEN_SET_TYPE('ANNOTATION_CONTENT_END'); + } + $MACRO_TOKEN_APPEND_WORD(); + $MACRO_TOKEN_ADVANCE(); + if ($MACRO_STREAM_ADVANCE_WORD() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($currentChar === '(' && $tokens[$tokenIndex - 1][0] === 'ANNOTATION_CLASS') { + $context |= $CONTEXT_CONTENT; + $annotationParentCount = 1; + $MACRO_TOKEN_SET_TYPE('ANNOTATION_CONTENT_START'); + $MACRO_TOKEN_APPEND_CHAR(); + $MACRO_TOKEN_ADVANCE(); + if ($MACRO_STREAM_ADVANCE_CHAR() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($MACRO_HAS_CONTEXT($CONTEXT_DOCBLOCK) && $currentWord === '*/') { + $MACRO_TOKEN_SET_TYPE('ANNOTATION_COMMENTEND'); + $MACRO_TOKEN_APPEND_WORD(); + $MACRO_TOKEN_ADVANCE(); + $context &= ~$CONTEXT_DOCBLOCK; + if ($MACRO_STREAM_ADVANCE_WORD() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($currentChar === '*') { + if ($MACRO_HAS_CONTEXT($CONTEXT_DOCBLOCK) && ($MACRO_HAS_CONTEXT($CONTEXT_ASTERISK))) { + $MACRO_TOKEN_SET_TYPE('ANNOTATION_IGNORE'); + } else { + $MACRO_TOKEN_SET_TYPE('ANNOTATION_ASTERISK'); + $context |= $CONTEXT_ASTERISK; + } + $MACRO_TOKEN_APPEND_CHAR(); + $MACRO_TOKEN_ADVANCE(); + if ($MACRO_STREAM_ADVANCE_CHAR() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($currentChar === '@') { + $MACRO_TOKEN_SET_TYPE('ANNOTATION_CLASS'); + $context |= $CONTEXT_CLASS; + $MACRO_TOKEN_APPEND_CHAR(); + if ($MACRO_STREAM_ADVANCE_CHAR() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + TOKENIZER_CONTINUE: + + if ($context && $CONTEXT_CONTENT) { + $MACRO_TOKEN_APPEND_CHAR(); + if ($MACRO_STREAM_ADVANCE_CHAR() === false) { + goto TOKENIZER_END; + } + } else { + $MACRO_TOKEN_SET_TYPE('ANNOTATION_IGNORE'); + $MACRO_TOKEN_APPEND_LINE(); + $MACRO_TOKEN_ADVANCE(); + if ($MACRO_STREAM_ADVANCE_LINE() === false) { + goto TOKENIZER_END; + } + } + goto TOKENIZER_TOP; + + TOKENIZER_END: + + array_pop($tokens); + + return $tokens; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/CachingFileScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/CachingFileScanner.php new file mode 100644 index 0000000..e88aa03 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/CachingFileScanner.php @@ -0,0 +1,160 @@ +fileScanner = static::$cache[$cacheId]; + } else { + $this->fileScanner = new FileScanner($file, $annotationManager); + static::$cache[$cacheId] = $this->fileScanner; + } + } + + /** + * @return void + */ + public static function clearCache() + { + static::$cache = array(); + } + + /** + * @return AnnotationManager + */ + public function getAnnotationManager() + { + return $this->fileScanner->getAnnotationManager(); + } + + /** + * @return array|null|string + */ + public function getFile() + { + return $this->fileScanner->getFile(); + } + + /** + * @return null|string + */ + public function getDocComment() + { + return $this->fileScanner->getDocComment(); + } + + /** + * @return array + */ + public function getNamespaces() + { + return $this->fileScanner->getNamespaces(); + } + + /** + * @param null|string $namespace + * @return array|null + */ + public function getUses($namespace = null) + { + return $this->fileScanner->getUses($namespace); + } + + /** + * @return array + */ + public function getIncludes() + { + return $this->fileScanner->getIncludes(); + } + + /** + * @return array + */ + public function getClassNames() + { + return $this->fileScanner->getClassNames(); + } + + /** + * @return array + */ + public function getClasses() + { + return $this->fileScanner->getClasses(); + } + + /** + * @param int|string $className + * @return ClassScanner + */ + public function getClass($className) + { + return $this->fileScanner->getClass($className); + } + + /** + * @param string $className + * @return bool|null|NameInformation + */ + public function getClassNameInformation($className) + { + return $this->fileScanner->getClassNameInformation($className); + } + + /** + * @return array + */ + public function getFunctionNames() + { + return $this->fileScanner->getFunctionNames(); + } + + /** + * @return array + */ + public function getFunctions() + { + return $this->fileScanner->getFunctions(); + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ClassScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ClassScanner.php new file mode 100644 index 0000000..ae02f24 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ClassScanner.php @@ -0,0 +1,953 @@ +tokens = $classTokens; + $this->nameInformation = $nameInformation; + } + + /** + * Get annotations + * + * @param Annotation\AnnotationManager $annotationManager + * @return Annotation\AnnotationCollection + */ + public function getAnnotations(Annotation\AnnotationManager $annotationManager) + { + if (($docComment = $this->getDocComment()) == '') { + return false; + } + + return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation); + } + + /** + * Return documentation comment + * + * @return null|string + */ + public function getDocComment() + { + $this->scan(); + + return $this->docComment; + } + + /** + * Return documentation block + * + * @return false|DocBlockScanner + */ + public function getDocBlock() + { + if (!$docComment = $this->getDocComment()) { + return false; + } + + return new DocBlockScanner($docComment); + } + + /** + * Return a name of class + * + * @return null|string + */ + public function getName() + { + $this->scan(); + return $this->name; + } + + /** + * Return short name of class + * + * @return null|string + */ + public function getShortName() + { + $this->scan(); + return $this->shortName; + } + + /** + * Return number of first line + * + * @return int|null + */ + public function getLineStart() + { + $this->scan(); + return $this->lineStart; + } + + /** + * Return number of last line + * + * @return int|null + */ + public function getLineEnd() + { + $this->scan(); + return $this->lineEnd; + } + + /** + * Verify if class is final + * + * @return bool + */ + public function isFinal() + { + $this->scan(); + return $this->isFinal; + } + + /** + * Verify if class is instantiable + * + * @return bool + */ + public function isInstantiable() + { + $this->scan(); + return (!$this->isAbstract && !$this->isInterface); + } + + /** + * Verify if class is an abstract class + * + * @return bool + */ + public function isAbstract() + { + $this->scan(); + return $this->isAbstract; + } + + /** + * Verify if class is an interface + * + * @return bool + */ + public function isInterface() + { + $this->scan(); + return $this->isInterface; + } + + /** + * Verify if class has parent + * + * @return bool + */ + public function hasParentClass() + { + $this->scan(); + return ($this->parentClass != null); + } + + /** + * Return a name of parent class + * + * @return null|string + */ + public function getParentClass() + { + $this->scan(); + return $this->parentClass; + } + + /** + * Return a list of interface names + * + * @return array + */ + public function getInterfaces() + { + $this->scan(); + return $this->interfaces; + } + + /** + * Return a list of constant names + * + * @return array + */ + public function getConstantNames() + { + $this->scan(); + + $return = array(); + foreach ($this->infos as $info) { + if ($info['type'] != 'constant') { + continue; + } + + $return[] = $info['name']; + } + + return $return; + } + + /** + * Return a list of constants + * + * @param bool $namesOnly Set false to return instances of ConstantScanner + * @return array|ConstantScanner[] + */ + public function getConstants($namesOnly = true) + { + if (true === $namesOnly) { + trigger_error('Use method getConstantNames() instead', E_USER_DEPRECATED); + return $this->getConstantNames(); + } + + $this->scan(); + + $return = array(); + foreach ($this->infos as $info) { + if ($info['type'] != 'constant') { + continue; + } + + $return[] = $this->getConstant($info['name']); + } + + return $return; + } + + /** + * Return a single constant by given name or index of info + * + * @param string|int $constantNameOrInfoIndex + * @throws Exception\InvalidArgumentException + * @return bool|ConstantScanner + */ + public function getConstant($constantNameOrInfoIndex) + { + $this->scan(); + + if (is_int($constantNameOrInfoIndex)) { + $info = $this->infos[$constantNameOrInfoIndex]; + if ($info['type'] != 'constant') { + throw new Exception\InvalidArgumentException('Index of info offset is not about a constant'); + } + } elseif (is_string($constantNameOrInfoIndex)) { + $constantFound = false; + foreach ($this->infos as $info) { + if ($info['type'] === 'constant' && $info['name'] === $constantNameOrInfoIndex) { + $constantFound = true; + break; + } + } + if (!$constantFound) { + return false; + } + } else { + throw new Exception\InvalidArgumentException('Invalid constant name of info index type. Must be of type int or string'); + } + if (!isset($info)) { + return false; + } + $p = new ConstantScanner( + array_slice($this->tokens, $info['tokenStart'], $info['tokenEnd'] - $info['tokenStart'] + 1), + $this->nameInformation + ); + $p->setClass($this->name); + $p->setScannerClass($this); + return $p; + } + + /** + * Verify if class has constant + * + * @param string $name + * @return bool + */ + public function hasConstant($name) + { + $this->scan(); + + foreach ($this->infos as $info) { + if ($info['type'] === 'constant' && $info['name'] === $name) { + return true; + } + } + + return false; + } + + /** + * Return a list of property names + * + * @return array + */ + public function getPropertyNames() + { + $this->scan(); + + $return = array(); + foreach ($this->infos as $info) { + if ($info['type'] != 'property') { + continue; + } + + $return[] = $info['name']; + } + + return $return; + } + + /** + * Return a list of properties + * + * @return PropertyScanner + */ + public function getProperties() + { + $this->scan(); + + $return = array(); + foreach ($this->infos as $info) { + if ($info['type'] != 'property') { + continue; + } + + $return[] = $this->getProperty($info['name']); + } + + return $return; + } + + /** + * Return a single property by given name or index of info + * + * @param string|int $propertyNameOrInfoIndex + * @throws Exception\InvalidArgumentException + * @return bool|PropertyScanner + */ + public function getProperty($propertyNameOrInfoIndex) + { + $this->scan(); + + if (is_int($propertyNameOrInfoIndex)) { + $info = $this->infos[$propertyNameOrInfoIndex]; + if ($info['type'] != 'property') { + throw new Exception\InvalidArgumentException('Index of info offset is not about a property'); + } + } elseif (is_string($propertyNameOrInfoIndex)) { + $propertyFound = false; + foreach ($this->infos as $info) { + if ($info['type'] === 'property' && $info['name'] === $propertyNameOrInfoIndex) { + $propertyFound = true; + break; + } + } + if (!$propertyFound) { + return false; + } + } else { + throw new Exception\InvalidArgumentException('Invalid property name of info index type. Must be of type int or string'); + } + if (!isset($info)) { + return false; + } + $p = new PropertyScanner( + array_slice($this->tokens, $info['tokenStart'], $info['tokenEnd'] - $info['tokenStart'] + 1), + $this->nameInformation + ); + $p->setClass($this->name); + $p->setScannerClass($this); + return $p; + } + + /** + * Verify if class has property + * + * @param string $name + * @return bool + */ + public function hasProperty($name) + { + $this->scan(); + + foreach ($this->infos as $info) { + if ($info['type'] === 'property' && $info['name'] === $name) { + return true; + } + } + + return false; + } + + /** + * Return a list of method names + * + * @return array + */ + public function getMethodNames() + { + $this->scan(); + + $return = array(); + foreach ($this->infos as $info) { + if ($info['type'] != 'method') { + continue; + } + + $return[] = $info['name']; + } + + return $return; + } + + /** + * Return a list of methods + * + * @return MethodScanner[] + */ + public function getMethods() + { + $this->scan(); + + $return = array(); + foreach ($this->infos as $info) { + if ($info['type'] != 'method') { + continue; + } + + $return[] = $this->getMethod($info['name']); + } + + return $return; + } + + /** + * Return a single method by given name or index of info + * + * @param string|int $methodNameOrInfoIndex + * @throws Exception\InvalidArgumentException + * @return MethodScanner + */ + public function getMethod($methodNameOrInfoIndex) + { + $this->scan(); + + if (is_int($methodNameOrInfoIndex)) { + $info = $this->infos[$methodNameOrInfoIndex]; + if ($info['type'] != 'method') { + throw new Exception\InvalidArgumentException('Index of info offset is not about a method'); + } + } elseif (is_string($methodNameOrInfoIndex)) { + $methodFound = false; + foreach ($this->infos as $info) { + if ($info['type'] === 'method' && $info['name'] === $methodNameOrInfoIndex) { + $methodFound = true; + break; + } + } + if (!$methodFound) { + return false; + } + } + if (!isset($info)) { + // @todo find a way to test this + die('Massive Failure, test this'); + } + $m = new MethodScanner( + array_slice($this->tokens, $info['tokenStart'], $info['tokenEnd'] - $info['tokenStart'] + 1), + $this->nameInformation + ); + $m->setClass($this->name); + $m->setScannerClass($this); + + return $m; + } + + /** + * Verify if class has method by given name + * + * @param string $name + * @return bool + */ + public function hasMethod($name) + { + $this->scan(); + + foreach ($this->infos as $info) { + if ($info['type'] === 'method' && $info['name'] === $name) { + return true; + } + } + + return false; + } + + public static function export() + { + // @todo + } + + public function __toString() + { + // @todo + } + + /** + * Scan tokens + * + * @return void + * @throws Exception\RuntimeException + */ + protected function scan() + { + if ($this->isScanned) { + return; + } + + if (!$this->tokens) { + throw new Exception\RuntimeException('No tokens were provided'); + } + + /** + * Variables & Setup + */ + + $tokens = &$this->tokens; // localize + $infos = &$this->infos; // localize + $tokenIndex = null; + $token = null; + $tokenType = null; + $tokenContent = null; + $tokenLine = null; + $namespace = null; + $infoIndex = 0; + $braceCount = 0; + + /* + * MACRO creation + */ + $MACRO_TOKEN_ADVANCE = function () use (&$tokens, &$tokenIndex, &$token, &$tokenType, &$tokenContent, &$tokenLine) { + static $lastTokenArray = null; + $tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1; + if (!isset($tokens[$tokenIndex])) { + $token = false; + $tokenContent = false; + $tokenType = false; + $tokenLine = false; + + return false; + } + $token = $tokens[$tokenIndex]; + + if (is_string($token)) { + $tokenType = null; + $tokenContent = $token; + $tokenLine = $tokenLine + substr_count($lastTokenArray[1], + "\n"); // adjust token line by last known newline count + } else { + $lastTokenArray = $token; + list($tokenType, $tokenContent, $tokenLine) = $token; + } + + return $tokenIndex; + }; + $MACRO_INFO_ADVANCE = function () use (&$infoIndex, &$infos, &$tokenIndex, &$tokenLine) { + $infos[$infoIndex]['tokenEnd'] = $tokenIndex; + $infos[$infoIndex]['lineEnd'] = $tokenLine; + $infoIndex++; + + return $infoIndex; + }; + + /** + * START FINITE STATE MACHINE FOR SCANNING TOKENS + */ + + // Initialize token + $MACRO_TOKEN_ADVANCE(); + + SCANNER_TOP: + + switch ($tokenType) { + + case T_DOC_COMMENT: + + $this->docComment = $tokenContent; + goto SCANNER_CONTINUE; + + case T_FINAL: + case T_ABSTRACT: + case T_CLASS: + case T_INTERFACE: + + // CLASS INFORMATION + + $classContext = null; + $classInterfaceIndex = 0; + + SCANNER_CLASS_INFO_TOP: + + if (is_string($tokens[$tokenIndex + 1]) && $tokens[$tokenIndex + 1] === '{') { + goto SCANNER_CLASS_INFO_END; + } + + $this->lineStart = $tokenLine; + + switch ($tokenType) { + + case T_FINAL: + $this->isFinal = true; + goto SCANNER_CLASS_INFO_CONTINUE; + + case T_ABSTRACT: + $this->isAbstract = true; + goto SCANNER_CLASS_INFO_CONTINUE; + + case T_INTERFACE: + $this->isInterface = true; + case T_CLASS: + $this->shortName = $tokens[$tokenIndex + 2][1]; + if ($this->nameInformation && $this->nameInformation->hasNamespace()) { + $this->name = $this->nameInformation->getNamespace() . '\\' . $this->shortName; + } else { + $this->name = $this->shortName; + } + goto SCANNER_CLASS_INFO_CONTINUE; + + case T_NS_SEPARATOR: + case T_STRING: + switch ($classContext) { + case T_EXTENDS: + $this->shortParentClass .= $tokenContent; + break; + case T_IMPLEMENTS: + $this->shortInterfaces[$classInterfaceIndex] .= $tokenContent; + break; + } + goto SCANNER_CLASS_INFO_CONTINUE; + + case T_EXTENDS: + case T_IMPLEMENTS: + $classContext = $tokenType; + if (($this->isInterface && $classContext === T_EXTENDS) || $classContext === T_IMPLEMENTS) { + $this->shortInterfaces[$classInterfaceIndex] = ''; + } elseif (!$this->isInterface && $classContext === T_EXTENDS) { + $this->shortParentClass = ''; + } + goto SCANNER_CLASS_INFO_CONTINUE; + + case null: + if ($classContext == T_IMPLEMENTS && $tokenContent == ',') { + $classInterfaceIndex++; + $this->shortInterfaces[$classInterfaceIndex] = ''; + } + + } + + SCANNER_CLASS_INFO_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_CLASS_INFO_TOP; + + SCANNER_CLASS_INFO_END: + + goto SCANNER_CONTINUE; + + } + + if ($tokenType === null && $tokenContent === '{' && $braceCount === 0) { + + $braceCount++; + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + + SCANNER_CLASS_BODY_TOP: + + if ($braceCount === 0) { + goto SCANNER_CLASS_BODY_END; + } + + switch ($tokenType) { + + case T_CONST: + + $infos[$infoIndex] = array( + 'type' => 'constant', + 'tokenStart' => $tokenIndex, + 'tokenEnd' => null, + 'lineStart' => $tokenLine, + 'lineEnd' => null, + 'name' => null, + 'value' => null, + ); + + SCANNER_CLASS_BODY_CONST_TOP: + + if ($tokenContent === ';') { + goto SCANNER_CLASS_BODY_CONST_END; + } + + if ($tokenType === T_STRING && null === $infos[$infoIndex]['name']) { + $infos[$infoIndex]['name'] = $tokenContent; + } + + SCANNER_CLASS_BODY_CONST_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_CLASS_BODY_CONST_TOP; + + SCANNER_CLASS_BODY_CONST_END: + + $MACRO_INFO_ADVANCE(); + goto SCANNER_CLASS_BODY_CONTINUE; + + case T_DOC_COMMENT: + case T_PUBLIC: + case T_PROTECTED: + case T_PRIVATE: + case T_ABSTRACT: + case T_FINAL: + case T_VAR: + case T_FUNCTION: + + $infos[$infoIndex] = array( + 'type' => null, + 'tokenStart' => $tokenIndex, + 'tokenEnd' => null, + 'lineStart' => $tokenLine, + 'lineEnd' => null, + 'name' => null, + ); + + $memberContext = null; + $methodBodyStarted = false; + + SCANNER_CLASS_BODY_MEMBER_TOP: + + if ($memberContext === 'method') { + switch ($tokenContent) { + case '{': + $methodBodyStarted = true; + $braceCount++; + goto SCANNER_CLASS_BODY_MEMBER_CONTINUE; + case '}': + $braceCount--; + goto SCANNER_CLASS_BODY_MEMBER_CONTINUE; + } + } + + if ($memberContext !== null) { + if ( + ($memberContext === 'property' && $tokenContent === ';') + || ($memberContext === 'method' && $methodBodyStarted && $braceCount === 1) + || ($memberContext === 'method' && $this->isInterface && $tokenContent === ';') + ) { + goto SCANNER_CLASS_BODY_MEMBER_END; + } + } + + + switch ($tokenType) { + + case T_CONST: + $memberContext = 'constant'; + $infos[$infoIndex]['type'] = 'constant'; + goto SCANNER_CLASS_BODY_CONST_CONTINUE; + + case T_VARIABLE: + if ($memberContext === null) { + $memberContext = 'property'; + $infos[$infoIndex]['type'] = 'property'; + $infos[$infoIndex]['name'] = ltrim($tokenContent, '$'); + } + goto SCANNER_CLASS_BODY_MEMBER_CONTINUE; + + case T_FUNCTION: + $memberContext = 'method'; + $infos[$infoIndex]['type'] = 'method'; + goto SCANNER_CLASS_BODY_MEMBER_CONTINUE; + + case T_STRING: + if ($memberContext === 'method' && null === $infos[$infoIndex]['name']) { + $infos[$infoIndex]['name'] = $tokenContent; + } + goto SCANNER_CLASS_BODY_MEMBER_CONTINUE; + } + + SCANNER_CLASS_BODY_MEMBER_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_CLASS_BODY_MEMBER_TOP; + + SCANNER_CLASS_BODY_MEMBER_END: + + $memberContext = null; + $MACRO_INFO_ADVANCE(); + goto SCANNER_CLASS_BODY_CONTINUE; + + case null: // no type, is a string + + switch ($tokenContent) { + case '{': + $braceCount++; + goto SCANNER_CLASS_BODY_CONTINUE; + case '}': + $braceCount--; + goto SCANNER_CLASS_BODY_CONTINUE; + } + } + + SCANNER_CLASS_BODY_CONTINUE: + + if ($braceCount === 0 || $MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_CONTINUE; + } + goto SCANNER_CLASS_BODY_TOP; + + SCANNER_CLASS_BODY_END: + + goto SCANNER_CONTINUE; + + } + + SCANNER_CONTINUE: + + if ($tokenContent === '}') { + $this->lineEnd = $tokenLine; + } + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_TOP; + + SCANNER_END: + + // process short names + if ($this->nameInformation) { + if ($this->shortParentClass) { + $this->parentClass = $this->nameInformation->resolveName($this->shortParentClass); + } + if ($this->shortInterfaces) { + foreach ($this->shortInterfaces as $siIndex => $si) { + $this->interfaces[$siIndex] = $this->nameInformation->resolveName($si); + } + } + } else { + $this->parentClass = $this->shortParentClass; + $this->interfaces = $this->shortInterfaces; + } + + $this->isScanned = true; + + return; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ConstantScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ConstantScanner.php new file mode 100644 index 0000000..02617c7 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ConstantScanner.php @@ -0,0 +1,233 @@ +tokens = $constantTokens; + $this->nameInformation = $nameInformation; + } + + /** + * @param string $class + */ + public function setClass($class) + { + $this->class = $class; + } + + /** + * @param ClassScanner $scannerClass + */ + public function setScannerClass(ClassScanner $scannerClass) + { + $this->scannerClass = $scannerClass; + } + + /** + * @return ClassScanner + */ + public function getClassScanner() + { + return $this->scannerClass; + } + + /** + * @return string + */ + public function getName() + { + $this->scan(); + return $this->name; + } + + /** + * @return string + */ + public function getValue() + { + $this->scan(); + return $this->value; + } + + /** + * @return string + */ + public function getDocComment() + { + $this->scan(); + return $this->docComment; + } + + /** + * @param Annotation\AnnotationManager $annotationManager + * @return AnnotationScanner + */ + public function getAnnotations(Annotation\AnnotationManager $annotationManager) + { + if (($docComment = $this->getDocComment()) == '') { + return false; + } + + return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation); + } + + /** + * @return string + */ + public function __toString() + { + $this->scan(); + return var_export($this, true); + } + + /** + * Scan tokens + * + * @throws Exception\RuntimeException + */ + protected function scan() + { + if ($this->isScanned) { + return; + } + + if (!$this->tokens) { + throw new Exception\RuntimeException('No tokens were provided'); + } + + /** + * Variables & Setup + */ + $tokens = &$this->tokens; + + reset($tokens); + + SCANNER_TOP: + + $token = current($tokens); + + if (!is_string($token)) { + list($tokenType, $tokenContent, $tokenLine) = $token; + + switch ($tokenType) { + case T_DOC_COMMENT: + if ($this->docComment === null && $this->name === null) { + $this->docComment = $tokenContent; + } + goto SCANNER_CONTINUE; + + case T_STRING: + $string = (is_string($token)) ? $token : $tokenContent; + + if (null === $this->name) { + $this->name = $string; + } else { + if ('self' == strtolower($string)) { + list($tokenNextType, $tokenNextContent, $tokenNextLine) = next($tokens); + + if ('::' == $tokenNextContent) { + list($tokenNextType, $tokenNextContent, $tokenNextLine) = next($tokens); + + if ($this->getClassScanner()->getConstant($tokenNextContent)) { + $this->value = $this->getClassScanner()->getConstant($tokenNextContent)->getValue(); + } + } + } + } + + goto SCANNER_CONTINUE; + + case T_CONSTANT_ENCAPSED_STRING: + case T_DNUMBER: + case T_LNUMBER: + $string = (is_string($token)) ? $token : $tokenContent; + + if (substr($string, 0, 1) === '"' || substr($string, 0, 1) === "'") { + $this->value = substr($string, 1, -1); // Remove quotes + } else { + $this->value = $string; + } + goto SCANNER_CONTINUE; + + default: + goto SCANNER_CONTINUE; + } + } + + SCANNER_CONTINUE: + + if (next($this->tokens) === false) { + goto SCANNER_END; + } + goto SCANNER_TOP; + + SCANNER_END: + + $this->isScanned = true; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/DerivedClassScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/DerivedClassScanner.php new file mode 100644 index 0000000..76156ba --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/DerivedClassScanner.php @@ -0,0 +1,381 @@ +classScanner = $classScanner; + $this->directoryScanner = $directoryScanner; + + $currentScannerClass = $classScanner; + + while ($currentScannerClass && $currentScannerClass->hasParentClass()) { + $currentParentClassName = $currentScannerClass->getParentClass(); + if ($directoryScanner->hasClass($currentParentClassName)) { + $currentParentClass = $directoryScanner->getClass($currentParentClassName); + $this->parentClassScanners[$currentParentClassName] = $currentParentClass; + $currentScannerClass = $currentParentClass; + } else { + $currentScannerClass = false; + } + } + + foreach ($interfaces = $this->classScanner->getInterfaces() as $iName) { + if ($directoryScanner->hasClass($iName)) { + $this->interfaceClassScanners[$iName] = $directoryScanner->getClass($iName); + } + } + } + + /** + * @return null|string + */ + public function getName() + { + return $this->classScanner->getName(); + } + + /** + * @return null|string + */ + public function getShortName() + { + return $this->classScanner->getShortName(); + } + + /** + * @return bool + */ + public function isInstantiable() + { + return $this->classScanner->isInstantiable(); + } + + /** + * @return bool + */ + public function isFinal() + { + return $this->classScanner->isFinal(); + } + + /** + * @return bool + */ + public function isAbstract() + { + return $this->classScanner->isAbstract(); + } + + /** + * @return bool + */ + public function isInterface() + { + return $this->classScanner->isInterface(); + } + + /** + * @return array + */ + public function getParentClasses() + { + return array_keys($this->parentClassScanners); + } + + /** + * @return bool + */ + public function hasParentClass() + { + return ($this->classScanner->getParentClass() != null); + } + + /** + * @return null|string + */ + public function getParentClass() + { + return $this->classScanner->getParentClass(); + } + + /** + * @param bool $returnClassScanners + * @return array + */ + public function getInterfaces($returnClassScanners = false) + { + if ($returnClassScanners) { + return $this->interfaceClassScanners; + } + + $interfaces = $this->classScanner->getInterfaces(); + foreach ($this->parentClassScanners as $pClassScanner) { + $interfaces = array_merge($interfaces, $pClassScanner->getInterfaces()); + } + + return $interfaces; + } + + /** + * Return a list of constant names + * + * @return array + */ + public function getConstantNames() + { + $constants = $this->classScanner->getConstantNames(); + foreach ($this->parentClassScanners as $pClassScanner) { + $constants = array_merge($constants, $pClassScanner->getConstantNames()); + } + + return $constants; + } + + /** + * Return a list of constants + * + * @param bool $namesOnly Set false to return instances of ConstantScanner + * @return array|ConstantScanner[] + */ + public function getConstants($namesOnly = true) + { + if (true === $namesOnly) { + trigger_error('Use method getConstantNames() instead', E_USER_DEPRECATED); + return $this->getConstantNames(); + } + + $constants = $this->classScanner->getConstants(); + foreach ($this->parentClassScanners as $pClassScanner) { + $constants = array_merge($constants, $pClassScanner->getConstants($namesOnly)); + } + + return $constants; + } + + /** + * Return a single constant by given name or index of info + * + * @param string|int $constantNameOrInfoIndex + * @throws Exception\InvalidArgumentException + * @return bool|ConstantScanner + */ + public function getConstant($constantNameOrInfoIndex) + { + if ($this->classScanner->hasConstant($constantNameOrInfoIndex)) { + return $this->classScanner->getConstant($constantNameOrInfoIndex); + } + + foreach ($this->parentClassScanners as $pClassScanner) { + if ($pClassScanner->hasConstant($constantNameOrInfoIndex)) { + return $pClassScanner->getConstant($constantNameOrInfoIndex); + } + } + + throw new Exception\InvalidArgumentException(sprintf( + 'Constant %s not found in %s', + $constantNameOrInfoIndex, + $this->classScanner->getName() + )); + } + + /** + * Verify if class or parent class has constant + * + * @param string $name + * @return bool + */ + public function hasConstant($name) + { + if ($this->classScanner->hasConstant($name)) { + return true; + } + foreach ($this->parentClassScanners as $pClassScanner) { + if ($pClassScanner->hasConstant($name)) { + return true; + } + } + + return false; + } + + /** + * Return a list of property names + * + * @return array + */ + public function getPropertyNames() + { + $properties = $this->classScanner->getPropertyNames(); + foreach ($this->parentClassScanners as $pClassScanner) { + $properties = array_merge($properties, $pClassScanner->getPropertyNames()); + } + + return $properties; + } + + /** + * @param bool $returnScannerProperty + * @return array + */ + public function getProperties($returnScannerProperty = false) + { + $properties = $this->classScanner->getProperties($returnScannerProperty); + foreach ($this->parentClassScanners as $pClassScanner) { + $properties = array_merge($properties, $pClassScanner->getProperties($returnScannerProperty)); + } + + return $properties; + } + + /** + * Return a single property by given name or index of info + * + * @param string|int $propertyNameOrInfoIndex + * @throws Exception\InvalidArgumentException + * @return bool|PropertyScanner + */ + public function getProperty($propertyNameOrInfoIndex) + { + if ($this->classScanner->hasProperty($propertyNameOrInfoIndex)) { + return $this->classScanner->getProperty($propertyNameOrInfoIndex); + } + + foreach ($this->parentClassScanners as $pClassScanner) { + if ($pClassScanner->hasProperty($propertyNameOrInfoIndex)) { + return $pClassScanner->getProperty($propertyNameOrInfoIndex); + } + } + + throw new Exception\InvalidArgumentException(sprintf( + 'Property %s not found in %s', + $propertyNameOrInfoIndex, + $this->classScanner->getName() + )); + } + + /** + * Verify if class or parent class has property + * + * @param string $name + * @return bool + */ + public function hasProperty($name) + { + if ($this->classScanner->hasProperty($name)) { + return true; + } + foreach ($this->parentClassScanners as $pClassScanner) { + if ($pClassScanner->hasProperty($name)) { + return true; + } + } + + return false; + } + + /** + * @return array + */ + public function getMethodNames() + { + $methods = $this->classScanner->getMethodNames(); + foreach ($this->parentClassScanners as $pClassScanner) { + $methods = array_merge($methods, $pClassScanner->getMethodNames()); + } + + return $methods; + } + + /** + * @return MethodScanner[] + */ + public function getMethods() + { + $methods = $this->classScanner->getMethods(); + foreach ($this->parentClassScanners as $pClassScanner) { + $methods = array_merge($methods, $pClassScanner->getMethods()); + } + + return $methods; + } + + /** + * @param int|string $methodNameOrInfoIndex + * @return MethodScanner + * @throws Exception\InvalidArgumentException + */ + public function getMethod($methodNameOrInfoIndex) + { + if ($this->classScanner->hasMethod($methodNameOrInfoIndex)) { + return $this->classScanner->getMethod($methodNameOrInfoIndex); + } + + foreach ($this->parentClassScanners as $pClassScanner) { + if ($pClassScanner->hasMethod($methodNameOrInfoIndex)) { + return $pClassScanner->getMethod($methodNameOrInfoIndex); + } + } + + throw new Exception\InvalidArgumentException(sprintf( + 'Method %s not found in %s', + $methodNameOrInfoIndex, + $this->classScanner->getName() + )); + } + + /** + * Verify if class or parent class has method by given name + * + * @param string $name + * @return bool + */ + public function hasMethod($name) + { + if ($this->classScanner->hasMethod($name)) { + return true; + } + foreach ($this->parentClassScanners as $pClassScanner) { + if ($pClassScanner->hasMethod($name)) { + return true; + } + } + + return false; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/DirectoryScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/DirectoryScanner.php new file mode 100644 index 0000000..4bae226 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/DirectoryScanner.php @@ -0,0 +1,272 @@ +addDirectory($directory); + } elseif (is_array($directory)) { + foreach ($directory as $d) { + $this->addDirectory($d); + } + } + } + } + + /** + * @param DirectoryScanner|string $directory + * @return void + * @throws Exception\InvalidArgumentException + */ + public function addDirectory($directory) + { + if ($directory instanceof DirectoryScanner) { + $this->directories[] = $directory; + } elseif (is_string($directory)) { + $realDir = realpath($directory); + if (!$realDir || !is_dir($realDir)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Directory "%s" does not exist', + $realDir + )); + } + $this->directories[] = $realDir; + } else { + throw new Exception\InvalidArgumentException( + 'The argument provided was neither a DirectoryScanner or directory path' + ); + } + } + + /** + * @param DirectoryScanner $directoryScanner + * @return void + */ + public function addDirectoryScanner(DirectoryScanner $directoryScanner) + { + $this->addDirectory($directoryScanner); + } + + /** + * @param FileScanner $fileScanner + * @return void + */ + public function addFileScanner(FileScanner $fileScanner) + { + $this->fileScanners[] = $fileScanner; + } + + /** + * @return void + */ + protected function scan() + { + if ($this->isScanned) { + return; + } + + // iterate directories creating file scanners + foreach ($this->directories as $directory) { + if ($directory instanceof DirectoryScanner) { + $directory->scan(); + if ($directory->fileScanners) { + $this->fileScanners = array_merge($this->fileScanners, $directory->fileScanners); + } + } else { + $rdi = new RecursiveDirectoryIterator($directory); + foreach (new RecursiveIteratorIterator($rdi) as $item) { + if ($item->isFile() && pathinfo($item->getRealPath(), PATHINFO_EXTENSION) == 'php') { + $this->fileScanners[] = new FileScanner($item->getRealPath()); + } + } + } + } + + $this->isScanned = true; + } + + /** + * @todo implement method + */ + public function getNamespaces() + { + // @todo + } + + /** + * @param bool $returnFileScanners + * @return array + */ + public function getFiles($returnFileScanners = false) + { + $this->scan(); + + $return = array(); + foreach ($this->fileScanners as $fileScanner) { + $return[] = ($returnFileScanners) ? $fileScanner : $fileScanner->getFile(); + } + + return $return; + } + + /** + * @return array + */ + public function getClassNames() + { + $this->scan(); + + if ($this->classToFileScanner === null) { + $this->createClassToFileScannerCache(); + } + + return array_keys($this->classToFileScanner); + } + + /** + * @param bool $returnDerivedScannerClass + * @return array + */ + public function getClasses($returnDerivedScannerClass = false) + { + $this->scan(); + + if ($this->classToFileScanner === null) { + $this->createClassToFileScannerCache(); + } + + $returnClasses = array(); + foreach ($this->classToFileScanner as $className => $fsIndex) { + $classScanner = $this->fileScanners[$fsIndex]->getClass($className); + if ($returnDerivedScannerClass) { + $classScanner = new DerivedClassScanner($classScanner, $this); + } + $returnClasses[] = $classScanner; + } + + return $returnClasses; + } + + /** + * @param string $class + * @return bool + */ + public function hasClass($class) + { + $this->scan(); + + if ($this->classToFileScanner === null) { + $this->createClassToFileScannerCache(); + } + + return (isset($this->classToFileScanner[$class])); + } + + /** + * @param string $class + * @param bool $returnDerivedScannerClass + * @return ClassScanner|DerivedClassScanner + * @throws Exception\InvalidArgumentException + */ + public function getClass($class, $returnDerivedScannerClass = false) + { + $this->scan(); + + if ($this->classToFileScanner === null) { + $this->createClassToFileScannerCache(); + } + + if (!isset($this->classToFileScanner[$class])) { + throw new Exception\InvalidArgumentException('Class not found.'); + } + + /** @var FileScanner $fs */ + $fs = $this->fileScanners[$this->classToFileScanner[$class]]; + $returnClass = $fs->getClass($class); + + if (($returnClass instanceof ClassScanner) && $returnDerivedScannerClass) { + return new DerivedClassScanner($returnClass, $this); + } + + return $returnClass; + } + + /** + * Create class to file scanner cache + * + * @return void + */ + protected function createClassToFileScannerCache() + { + if ($this->classToFileScanner !== null) { + return; + } + + $this->classToFileScanner = array(); + /** @var FileScanner $fileScanner */ + foreach ($this->fileScanners as $fsIndex => $fileScanner) { + $fsClasses = $fileScanner->getClassNames(); + foreach ($fsClasses as $fsClassName) { + $this->classToFileScanner[$fsClassName] = $fsIndex; + } + } + } + + /** + * Export + * + * @todo implement method + */ + public static function export() + { + // @todo + } + + /** + * __ToString + * + * @todo implement method + */ + public function __toString() + { + // @todo + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/DocBlockScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/DocBlockScanner.php new file mode 100644 index 0000000..2e594cb --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/DocBlockScanner.php @@ -0,0 +1,324 @@ +docComment = $docComment; + $this->nameInformation = $nameInformation; + } + + /** + * @return string + */ + public function getShortDescription() + { + $this->scan(); + + return $this->shortDescription; + } + + /** + * @return string + */ + public function getLongDescription() + { + $this->scan(); + + return $this->longDescription; + } + + /** + * @return array + */ + public function getTags() + { + $this->scan(); + + return $this->tags; + } + + /** + * @return array + */ + public function getAnnotations() + { + $this->scan(); + + return $this->annotations; + } + + /** + * @return void + */ + protected function scan() + { + if ($this->isScanned) { + return; + } + + $mode = 1; + + $tokens = $this->tokenize(); + $tagIndex = null; + reset($tokens); + + SCANNER_TOP: + $token = current($tokens); + + switch ($token[0]) { + case 'DOCBLOCK_NEWLINE': + if ($this->shortDescription != '' && $tagIndex === null) { + $mode = 2; + } else { + $this->longDescription .= $token[1]; + } + goto SCANNER_CONTINUE; + + case 'DOCBLOCK_WHITESPACE': + case 'DOCBLOCK_TEXT': + if ($tagIndex !== null) { + $this->tags[$tagIndex]['value'] .= ($this->tags[$tagIndex]['value'] == '') ? $token[1] : ' ' . $token[1]; + goto SCANNER_CONTINUE; + } elseif ($mode <= 2) { + if ($mode == 1) { + $this->shortDescription .= $token[1]; + } else { + $this->longDescription .= $token[1]; + } + goto SCANNER_CONTINUE; + } + case 'DOCBLOCK_TAG': + array_push($this->tags, array('name' => $token[1], + 'value' => '')); + end($this->tags); + $tagIndex = key($this->tags); + $mode = 3; + goto SCANNER_CONTINUE; + + case 'DOCBLOCK_COMMENTEND': + goto SCANNER_END; + + } + + SCANNER_CONTINUE: + if (next($tokens) === false) { + goto SCANNER_END; + } + goto SCANNER_TOP; + + SCANNER_END: + + $this->shortDescription = trim($this->shortDescription); + $this->longDescription = trim($this->longDescription); + $this->isScanned = true; + } + + /** + * @return array + */ + protected function tokenize() + { + static $CONTEXT_INSIDE_DOCBLOCK = 0x01; + static $CONTEXT_INSIDE_ASTERISK = 0x02; + + $context = 0x00; + $stream = $this->docComment; + $streamIndex = null; + $tokens = array(); + $tokenIndex = null; + $currentChar = null; + $currentWord = null; + $currentLine = null; + + $MACRO_STREAM_ADVANCE_CHAR = function ($positionsForward = 1) use (&$stream, &$streamIndex, &$currentChar, &$currentWord, &$currentLine) { + $positionsForward = ($positionsForward > 0) ? $positionsForward : 1; + $streamIndex = ($streamIndex === null) ? 0 : $streamIndex + $positionsForward; + if (!isset($stream[$streamIndex])) { + $currentChar = false; + + return false; + } + $currentChar = $stream[$streamIndex]; + $matches = array(); + $currentLine = (preg_match('#(.*?)\r?\n#', $stream, $matches, null, + $streamIndex) === 1) ? $matches[1] : substr($stream, $streamIndex); + if ($currentChar === ' ') { + $currentWord = (preg_match('#( +)#', $currentLine, $matches) === 1) ? $matches[1] : $currentLine; + } else { + $currentWord = (($matches = strpos($currentLine, ' ')) !== false) ? substr($currentLine, 0, $matches) : $currentLine; + } + + return $currentChar; + }; + $MACRO_STREAM_ADVANCE_WORD = function () use (&$currentWord, &$MACRO_STREAM_ADVANCE_CHAR) { + return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentWord)); + }; + $MACRO_STREAM_ADVANCE_LINE = function () use (&$currentLine, &$MACRO_STREAM_ADVANCE_CHAR) { + return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentLine)); + }; + $MACRO_TOKEN_ADVANCE = function () use (&$tokenIndex, &$tokens) { + $tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1; + $tokens[$tokenIndex] = array('DOCBLOCK_UNKNOWN', ''); + }; + $MACRO_TOKEN_SET_TYPE = function ($type) use (&$tokenIndex, &$tokens) { + $tokens[$tokenIndex][0] = $type; + }; + $MACRO_TOKEN_APPEND_CHAR = function () use (&$currentChar, &$tokens, &$tokenIndex) { + $tokens[$tokenIndex][1] .= $currentChar; + }; + $MACRO_TOKEN_APPEND_WORD = function () use (&$currentWord, &$tokens, &$tokenIndex) { + $tokens[$tokenIndex][1] .= $currentWord; + }; + $MACRO_TOKEN_APPEND_WORD_PARTIAL = function ($length) use (&$currentWord, &$tokens, &$tokenIndex) { + $tokens[$tokenIndex][1] .= substr($currentWord, 0, $length); + }; + $MACRO_TOKEN_APPEND_LINE = function () use (&$currentLine, &$tokens, &$tokenIndex) { + $tokens[$tokenIndex][1] .= $currentLine; + }; + + $MACRO_STREAM_ADVANCE_CHAR(); + $MACRO_TOKEN_ADVANCE(); + + TOKENIZER_TOP: + + if ($context === 0x00 && $currentChar === '/' && $currentWord === '/**') { + $MACRO_TOKEN_SET_TYPE('DOCBLOCK_COMMENTSTART'); + $MACRO_TOKEN_APPEND_WORD(); + $MACRO_TOKEN_ADVANCE(); + $context |= $CONTEXT_INSIDE_DOCBLOCK; + $context |= $CONTEXT_INSIDE_ASTERISK; + if ($MACRO_STREAM_ADVANCE_WORD() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($context & $CONTEXT_INSIDE_DOCBLOCK && $currentWord === '*/') { + $MACRO_TOKEN_SET_TYPE('DOCBLOCK_COMMENTEND'); + $MACRO_TOKEN_APPEND_WORD(); + $MACRO_TOKEN_ADVANCE(); + $context &= ~$CONTEXT_INSIDE_DOCBLOCK; + if ($MACRO_STREAM_ADVANCE_WORD() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($currentChar === ' ' || $currentChar === "\t") { + $MACRO_TOKEN_SET_TYPE(($context & $CONTEXT_INSIDE_ASTERISK) ? 'DOCBLOCK_WHITESPACE' : 'DOCBLOCK_WHITESPACE_INDENT'); + $MACRO_TOKEN_APPEND_WORD(); + $MACRO_TOKEN_ADVANCE(); + if ($MACRO_STREAM_ADVANCE_WORD() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($currentChar === '*') { + if (($context & $CONTEXT_INSIDE_DOCBLOCK) && ($context & $CONTEXT_INSIDE_ASTERISK)) { + $MACRO_TOKEN_SET_TYPE('DOCBLOCK_TEXT'); + } else { + $MACRO_TOKEN_SET_TYPE('DOCBLOCK_ASTERISK'); + $context |= $CONTEXT_INSIDE_ASTERISK; + } + $MACRO_TOKEN_APPEND_CHAR(); + $MACRO_TOKEN_ADVANCE(); + if ($MACRO_STREAM_ADVANCE_CHAR() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($currentChar === '@') { + $MACRO_TOKEN_SET_TYPE('DOCBLOCK_TAG'); + $MACRO_TOKEN_APPEND_WORD(); + $MACRO_TOKEN_ADVANCE(); + if ($MACRO_STREAM_ADVANCE_WORD() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + if ($currentChar === "\n") { + $MACRO_TOKEN_SET_TYPE('DOCBLOCK_NEWLINE'); + $MACRO_TOKEN_APPEND_CHAR(); + $MACRO_TOKEN_ADVANCE(); + $context &= ~$CONTEXT_INSIDE_ASTERISK; + if ($MACRO_STREAM_ADVANCE_CHAR() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + } + + $MACRO_TOKEN_SET_TYPE('DOCBLOCK_TEXT'); + $MACRO_TOKEN_APPEND_LINE(); + $MACRO_TOKEN_ADVANCE(); + if ($MACRO_STREAM_ADVANCE_LINE() === false) { + goto TOKENIZER_END; + } + goto TOKENIZER_TOP; + + TOKENIZER_END: + + array_pop($tokens); + + return $tokens; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/FileScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/FileScanner.php new file mode 100644 index 0000000..0c435e3 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/FileScanner.php @@ -0,0 +1,46 @@ +file = $file; + if (!file_exists($file)) { + throw new Exception\InvalidArgumentException(sprintf( + 'File "%s" not found', + $file + )); + } + parent::__construct(token_get_all(file_get_contents($file)), $annotationManager); + } + + /** + * @return null|string + */ + public function getFile() + { + return $this->file; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/FunctionScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/FunctionScanner.php new file mode 100644 index 0000000..a5a8a04 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/FunctionScanner.php @@ -0,0 +1,16 @@ +tokens = $methodTokens; + $this->nameInformation = $nameInformation; + } + + /** + * @param string $class + * @return MethodScanner + */ + public function setClass($class) + { + $this->class = (string) $class; + return $this; + } + + /** + * @param ClassScanner $scannerClass + * @return MethodScanner + */ + public function setScannerClass(ClassScanner $scannerClass) + { + $this->scannerClass = $scannerClass; + return $this; + } + + /** + * @return MethodScanner + */ + public function getClassScanner() + { + return $this->scannerClass; + } + + /** + * @return string + */ + public function getName() + { + $this->scan(); + + return $this->name; + } + + /** + * @return int + */ + public function getLineStart() + { + $this->scan(); + + return $this->lineStart; + } + + /** + * @return int + */ + public function getLineEnd() + { + $this->scan(); + + return $this->lineEnd; + } + + /** + * @return string + */ + public function getDocComment() + { + $this->scan(); + + return $this->docComment; + } + + /** + * @param AnnotationManager $annotationManager + * @return AnnotationScanner + */ + public function getAnnotations(AnnotationManager $annotationManager) + { + if (($docComment = $this->getDocComment()) == '') { + return false; + } + + return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation); + } + + /** + * @return bool + */ + public function isFinal() + { + $this->scan(); + + return $this->isFinal; + } + + /** + * @return bool + */ + public function isAbstract() + { + $this->scan(); + + return $this->isAbstract; + } + + /** + * @return bool + */ + public function isPublic() + { + $this->scan(); + + return $this->isPublic; + } + + /** + * @return bool + */ + public function isProtected() + { + $this->scan(); + + return $this->isProtected; + } + + /** + * @return bool + */ + public function isPrivate() + { + $this->scan(); + + return $this->isPrivate; + } + + /** + * @return bool + */ + public function isStatic() + { + $this->scan(); + + return $this->isStatic; + } + + /** + * @return int + */ + public function getNumberOfParameters() + { + return count($this->getParameters()); + } + + /** + * @param bool $returnScanner + * @return array + */ + public function getParameters($returnScanner = false) + { + $this->scan(); + + $return = array(); + + foreach ($this->infos as $info) { + if ($info['type'] != 'parameter') { + continue; + } + + if (!$returnScanner) { + $return[] = $info['name']; + } else { + $return[] = $this->getParameter($info['name']); + } + } + + return $return; + } + + /** + * @param int|string $parameterNameOrInfoIndex + * @return ParameterScanner + * @throws Exception\InvalidArgumentException + */ + public function getParameter($parameterNameOrInfoIndex) + { + $this->scan(); + + if (is_int($parameterNameOrInfoIndex)) { + $info = $this->infos[$parameterNameOrInfoIndex]; + if ($info['type'] != 'parameter') { + throw new Exception\InvalidArgumentException('Index of info offset is not about a parameter'); + } + } elseif (is_string($parameterNameOrInfoIndex)) { + foreach ($this->infos as $info) { + if ($info['type'] === 'parameter' && $info['name'] === $parameterNameOrInfoIndex) { + break; + } + unset($info); + } + if (!isset($info)) { + throw new Exception\InvalidArgumentException('Index of info offset is not about a parameter'); + } + } + + $p = new ParameterScanner( + array_slice($this->tokens, $info['tokenStart'], $info['tokenEnd'] - $info['tokenStart']), + $this->nameInformation + ); + $p->setDeclaringFunction($this->name); + $p->setDeclaringScannerFunction($this); + $p->setDeclaringClass($this->class); + $p->setDeclaringScannerClass($this->scannerClass); + $p->setPosition($info['position']); + + return $p; + } + + /** + * @return string + */ + public function getBody() + { + $this->scan(); + + return $this->body; + } + + public static function export() + { + // @todo + } + + public function __toString() + { + $this->scan(); + + return var_export($this, true); + } + + protected function scan() + { + if ($this->isScanned) { + return; + } + + if (!$this->tokens) { + throw new Exception\RuntimeException('No tokens were provided'); + } + + /** + * Variables & Setup + */ + + $tokens = &$this->tokens; // localize + $infos = &$this->infos; // localize + $tokenIndex = null; + $token = null; + $tokenType = null; + $tokenContent = null; + $tokenLine = null; + $infoIndex = 0; + $parentCount = 0; + + /* + * MACRO creation + */ + $MACRO_TOKEN_ADVANCE = function () use (&$tokens, &$tokenIndex, &$token, &$tokenType, &$tokenContent, &$tokenLine) { + static $lastTokenArray = null; + $tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1; + if (!isset($tokens[$tokenIndex])) { + $token = false; + $tokenContent = false; + $tokenType = false; + $tokenLine = false; + + return false; + } + $token = $tokens[$tokenIndex]; + if (is_string($token)) { + $tokenType = null; + $tokenContent = $token; + $tokenLine = $tokenLine + substr_count($lastTokenArray[1], + "\n"); // adjust token line by last known newline count + } else { + list($tokenType, $tokenContent, $tokenLine) = $token; + } + + return $tokenIndex; + }; + $MACRO_INFO_START = function () use (&$infoIndex, &$infos, &$tokenIndex, &$tokenLine) { + $infos[$infoIndex] = array( + 'type' => 'parameter', + 'tokenStart' => $tokenIndex, + 'tokenEnd' => null, + 'lineStart' => $tokenLine, + 'lineEnd' => $tokenLine, + 'name' => null, + 'position' => $infoIndex + 1, // position is +1 of infoIndex + ); + }; + $MACRO_INFO_ADVANCE = function () use (&$infoIndex, &$infos, &$tokenIndex, &$tokenLine) { + $infos[$infoIndex]['tokenEnd'] = $tokenIndex; + $infos[$infoIndex]['lineEnd'] = $tokenLine; + $infoIndex++; + + return $infoIndex; + }; + + /** + * START FINITE STATE MACHINE FOR SCANNING TOKENS + */ + + // Initialize token + $MACRO_TOKEN_ADVANCE(); + + SCANNER_TOP: + + $this->lineStart = ($this->lineStart) ? : $tokenLine; + + switch ($tokenType) { + case T_DOC_COMMENT: + $this->lineStart = null; + if ($this->docComment === null && $this->name === null) { + $this->docComment = $tokenContent; + } + goto SCANNER_CONTINUE_SIGNATURE; + + case T_FINAL: + $this->isFinal = true; + goto SCANNER_CONTINUE_SIGNATURE; + + case T_ABSTRACT: + $this->isAbstract = true; + goto SCANNER_CONTINUE_SIGNATURE; + + case T_PUBLIC: + // use defaults + goto SCANNER_CONTINUE_SIGNATURE; + + case T_PROTECTED: + $this->isProtected = true; + $this->isPublic = false; + goto SCANNER_CONTINUE_SIGNATURE; + + case T_PRIVATE: + $this->isPrivate = true; + $this->isPublic = false; + goto SCANNER_CONTINUE_SIGNATURE; + + case T_STATIC: + $this->isStatic = true; + goto SCANNER_CONTINUE_SIGNATURE; + + case T_VARIABLE: + case T_STRING: + + if ($tokenType === T_STRING && $parentCount === 0) { + $this->name = $tokenContent; + } + + if ($parentCount === 1) { + if (!isset($infos[$infoIndex])) { + $MACRO_INFO_START(); + } + if ($tokenType === T_VARIABLE) { + $infos[$infoIndex]['name'] = ltrim($tokenContent, '$'); + } + } + + goto SCANNER_CONTINUE_SIGNATURE; + + case null: + + switch ($tokenContent) { + case '&': + if (!isset($infos[$infoIndex])) { + $MACRO_INFO_START(); + } + goto SCANNER_CONTINUE_SIGNATURE; + case '(': + $parentCount++; + goto SCANNER_CONTINUE_SIGNATURE; + case ')': + $parentCount--; + if ($parentCount === 0) { + if ($infos) { + $MACRO_INFO_ADVANCE(); + } + $context = 'body'; + } + goto SCANNER_CONTINUE_BODY; + case ',': + if ($parentCount === 1) { + $MACRO_INFO_ADVANCE(); + } + goto SCANNER_CONTINUE_SIGNATURE; + } + } + + SCANNER_CONTINUE_SIGNATURE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_TOP; + + SCANNER_CONTINUE_BODY: + + $braceCount = 0; + while ($MACRO_TOKEN_ADVANCE() !== false) { + if ($tokenContent == '}') { + $braceCount--; + } + if ($braceCount > 0) { + $this->body .= $tokenContent; + } + if ($tokenContent == '{') { + $braceCount++; + } + $this->lineEnd = $tokenLine; + } + + SCANNER_END: + + $this->isScanned = true; + + return; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ParameterScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ParameterScanner.php new file mode 100644 index 0000000..97de25e --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ParameterScanner.php @@ -0,0 +1,353 @@ +tokens = $parameterTokens; + $this->nameInformation = $nameInformation; + } + + /** + * Set declaring class + * + * @param string $class + * @return void + */ + public function setDeclaringClass($class) + { + $this->declaringClass = (string) $class; + } + + /** + * Set declaring scanner class + * + * @param ClassScanner $scannerClass + * @return void + */ + public function setDeclaringScannerClass(ClassScanner $scannerClass) + { + $this->declaringScannerClass = $scannerClass; + } + + /** + * Set declaring function + * + * @param string $function + * @return void + */ + public function setDeclaringFunction($function) + { + $this->declaringFunction = $function; + } + + /** + * Set declaring scanner function + * + * @param MethodScanner $scannerFunction + * @return void + */ + public function setDeclaringScannerFunction(MethodScanner $scannerFunction) + { + $this->declaringScannerFunction = $scannerFunction; + } + + /** + * Set position + * + * @param int $position + * @return void + */ + public function setPosition($position) + { + $this->position = $position; + } + + /** + * Scan + * + * @return void + */ + protected function scan() + { + if ($this->isScanned) { + return; + } + + $tokens = &$this->tokens; + + reset($tokens); + + SCANNER_TOP: + + $token = current($tokens); + + if (is_string($token)) { + // check pass by ref + if ($token === '&') { + $this->isPassedByReference = true; + goto SCANNER_CONTINUE; + } + if ($token === '=') { + $this->isOptional = true; + $this->isDefaultValueAvailable = true; + goto SCANNER_CONTINUE; + } + } else { + if ($this->name === null && ($token[0] === T_STRING || $token[0] === T_NS_SEPARATOR)) { + $this->class .= $token[1]; + goto SCANNER_CONTINUE; + } + if ($token[0] === T_VARIABLE) { + $this->name = ltrim($token[1], '$'); + goto SCANNER_CONTINUE; + } + + } + + if ($this->name !== null) { + $this->defaultValue .= (is_string($token)) ? $token : $token[1]; + } + + SCANNER_CONTINUE: + + if (next($this->tokens) === false) { + goto SCANNER_END; + } + goto SCANNER_TOP; + + SCANNER_END: + + if ($this->class && $this->nameInformation) { + $this->class = $this->nameInformation->resolveName($this->class); + } + + $this->isScanned = true; + } + + /** + * Get declaring scanner class + * + * @return ClassScanner + */ + public function getDeclaringScannerClass() + { + return $this->declaringScannerClass; + } + + /** + * Get declaring class + * + * @return string + */ + public function getDeclaringClass() + { + return $this->declaringClass; + } + + /** + * Get declaring scanner function + * + * @return MethodScanner + */ + public function getDeclaringScannerFunction() + { + return $this->declaringScannerFunction; + } + + /** + * Get declaring function + * + * @return string + */ + public function getDeclaringFunction() + { + return $this->declaringFunction; + } + + /** + * Get default value + * + * @return string + */ + public function getDefaultValue() + { + $this->scan(); + + return $this->defaultValue; + } + + /** + * Get class + * + * @return string + */ + public function getClass() + { + $this->scan(); + + return $this->class; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + $this->scan(); + + return $this->name; + } + + /** + * Get position + * + * @return int + */ + public function getPosition() + { + $this->scan(); + + return $this->position; + } + + /** + * Check if is array + * + * @return bool + */ + public function isArray() + { + $this->scan(); + + return $this->isArray; + } + + /** + * Check if default value is available + * + * @return bool + */ + public function isDefaultValueAvailable() + { + $this->scan(); + + return $this->isDefaultValueAvailable; + } + + /** + * Check if is optional + * + * @return bool + */ + public function isOptional() + { + $this->scan(); + + return $this->isOptional; + } + + /** + * Check if is passed by reference + * + * @return bool + */ + public function isPassedByReference() + { + $this->scan(); + + return $this->isPassedByReference; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/PropertyScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/PropertyScanner.php new file mode 100644 index 0000000..0ba37f6 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/PropertyScanner.php @@ -0,0 +1,284 @@ +tokens = $propertyTokens; + $this->nameInformation = $nameInformation; + } + + /** + * @param string $class + */ + public function setClass($class) + { + $this->class = $class; + } + + /** + * @param ClassScanner $scannerClass + */ + public function setScannerClass(ClassScanner $scannerClass) + { + $this->scannerClass = $scannerClass; + } + + /** + * @return ClassScanner + */ + public function getClassScanner() + { + return $this->scannerClass; + } + + /** + * @return string + */ + public function getName() + { + $this->scan(); + return $this->name; + } + + /** + * @return bool + */ + public function isPublic() + { + $this->scan(); + return $this->isPublic; + } + + /** + * @return bool + */ + public function isPrivate() + { + $this->scan(); + return $this->isPrivate; + } + + /** + * @return bool + */ + public function isProtected() + { + $this->scan(); + return $this->isProtected; + } + + /** + * @return bool + */ + public function isStatic() + { + $this->scan(); + return $this->isStatic; + } + + /** + * @return string + */ + public function getValue() + { + $this->scan(); + return $this->value; + } + + /** + * @return string + */ + public function getDocComment() + { + $this->scan(); + return $this->docComment; + } + + /** + * @param Annotation\AnnotationManager $annotationManager + * @return AnnotationScanner + */ + public function getAnnotations(Annotation\AnnotationManager $annotationManager) + { + if (($docComment = $this->getDocComment()) == '') { + return false; + } + + return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation); + } + + /** + * @return string + */ + public function __toString() + { + $this->scan(); + return var_export($this, true); + } + + /** + * Scan tokens + * + * @throws \Zend\Code\Exception\RuntimeException + */ + protected function scan() + { + if ($this->isScanned) { + return; + } + + if (!$this->tokens) { + throw new Exception\RuntimeException('No tokens were provided'); + } + + /** + * Variables & Setup + */ + $tokens = &$this->tokens; + + reset($tokens); + + SCANNER_TOP: + + $token = current($tokens); + + if (!is_string($token)) { + list($tokenType, $tokenContent, $tokenLine) = $token; + + switch ($tokenType) { + case T_DOC_COMMENT: + if ($this->docComment === null && $this->name === null) { + $this->docComment = $tokenContent; + } + goto SCANNER_CONTINUE; + + case T_VARIABLE: + $this->name = ltrim($tokenContent, '$'); + goto SCANNER_CONTINUE; + + case T_PUBLIC: + // use defaults + goto SCANNER_CONTINUE; + + case T_PROTECTED: + $this->isProtected = true; + $this->isPublic = false; + goto SCANNER_CONTINUE; + + case T_PRIVATE: + $this->isPrivate = true; + $this->isPublic = false; + goto SCANNER_CONTINUE; + + case T_STATIC: + $this->isStatic = true; + goto SCANNER_CONTINUE; + + default: + if ($this->name !== null && trim($tokenContent) !== '') { + $this->value .= (is_string($token)) ? $token : $tokenContent; + if (substr($this->value, 0, 1) === '"' || substr($this->value, 0, 1) === "'") { + $this->value = substr($this->value, 1, -1); // Remove quotes + } + } + goto SCANNER_CONTINUE; + } + } + + SCANNER_CONTINUE: + + if (next($this->tokens) === false) { + goto SCANNER_END; + } + goto SCANNER_TOP; + + SCANNER_END: + + $this->isScanned = true; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ScannerInterface.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ScannerInterface.php new file mode 100644 index 0000000..4909ae2 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ScannerInterface.php @@ -0,0 +1,16 @@ +tokens = $tokens; + $this->annotationManager = $annotationManager; + } + + /** + * @return AnnotationManager + */ + public function getAnnotationManager() + { + return $this->annotationManager; + } + + /** + * Get doc comment + * + * @todo Assignment of $this->docComment should probably be done in scan() + * and then $this->getDocComment() just retrieves it. + * + * @return string + */ + public function getDocComment() + { + foreach ($this->tokens as $token) { + $type = $token[0]; + $value = $token[1]; + if (($type == T_OPEN_TAG) || ($type == T_WHITESPACE)) { + continue; + } elseif ($type == T_DOC_COMMENT) { + $this->docComment = $value; + + return $this->docComment; + } else { + // Only whitespace is allowed before file docblocks + return; + } + } + } + + /** + * @return array + */ + public function getNamespaces() + { + $this->scan(); + + $namespaces = array(); + foreach ($this->infos as $info) { + if ($info['type'] == 'namespace') { + $namespaces[] = $info['namespace']; + } + } + + return $namespaces; + } + + /** + * @param null|string $namespace + * @return array|null + */ + public function getUses($namespace = null) + { + $this->scan(); + + return $this->getUsesNoScan($namespace); + } + + /** + * @return array + */ + public function getIncludes() + { + $this->scan(); + // @todo Implement getIncludes() in TokenArrayScanner + } + + /** + * @return array + */ + public function getClassNames() + { + $this->scan(); + + $return = array(); + foreach ($this->infos as $info) { + if ($info['type'] != 'class') { + continue; + } + + $return[] = $info['name']; + } + + return $return; + } + + /** + * @return ClassScanner[] + */ + public function getClasses() + { + $this->scan(); + + $return = array(); + foreach ($this->infos as $info) { + if ($info['type'] != 'class') { + continue; + } + + $return[] = $this->getClass($info['name']); + } + + return $return; + } + + /** + * Return the class object from this scanner + * + * @param string|int $name + * @throws Exception\InvalidArgumentException + * @return ClassScanner + */ + public function getClass($name) + { + $this->scan(); + + if (is_int($name)) { + $info = $this->infos[$name]; + if ($info['type'] != 'class') { + throw new Exception\InvalidArgumentException('Index of info offset is not about a class'); + } + } elseif (is_string($name)) { + $classFound = false; + foreach ($this->infos as $info) { + if ($info['type'] === 'class' && $info['name'] === $name) { + $classFound = true; + break; + } + } + + if (!$classFound) { + return false; + } + } + + return new ClassScanner( + array_slice( + $this->tokens, + $info['tokenStart'], + ($info['tokenEnd'] - $info['tokenStart'] + 1) + ), // zero indexed array + new NameInformation($info['namespace'], $info['uses']) + ); + } + + /** + * @param string $className + * @return bool|null|NameInformation + */ + public function getClassNameInformation($className) + { + $this->scan(); + + $classFound = false; + foreach ($this->infos as $info) { + if ($info['type'] === 'class' && $info['name'] === $className) { + $classFound = true; + break; + } + } + + if (!$classFound) { + return false; + } + + if (!isset($info)) { + return null; + } + + return new NameInformation($info['namespace'], $info['uses']); + } + + /** + * @return array + */ + public function getFunctionNames() + { + $this->scan(); + $functionNames = array(); + foreach ($this->infos as $info) { + if ($info['type'] == 'function') { + $functionNames[] = $info['name']; + } + } + + return $functionNames; + } + + /** + * @return array + */ + public function getFunctions() + { + $this->scan(); + + $functions = array(); + foreach ($this->infos as $info) { + if ($info['type'] == 'function') { + // @todo $functions[] = new FunctionScanner($info['name']); + } + } + + return $functions; + } + + /** + * Export + * + * @param $tokens + */ + public static function export($tokens) + { + // @todo + } + + public function __toString() + { + // @todo + } + + /** + * Scan + * + * @todo: $this->docComment should be assigned for valid docblock during + * the scan instead of $this->getDocComment() (starting with + * T_DOC_COMMENT case) + * + * @throws Exception\RuntimeException + */ + protected function scan() + { + if ($this->isScanned) { + return; + } + + if (!$this->tokens) { + throw new Exception\RuntimeException('No tokens were provided'); + } + + /** + * Variables & Setup + */ + + $tokens = &$this->tokens; // localize + $infos = &$this->infos; // localize + $tokenIndex = null; + $token = null; + $tokenType = null; + $tokenContent = null; + $tokenLine = null; + $namespace = null; + $docCommentIndex = false; + $infoIndex = 0; + + /* + * MACRO creation + */ + $MACRO_TOKEN_ADVANCE = function () use (&$tokens, &$tokenIndex, &$token, &$tokenType, &$tokenContent, &$tokenLine) { + $tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1; + if (!isset($tokens[$tokenIndex])) { + $token = false; + $tokenContent = false; + $tokenType = false; + $tokenLine = false; + + return false; + } + if (is_string($tokens[$tokenIndex]) && $tokens[$tokenIndex] === '"') { + do { + $tokenIndex++; + } while (!(is_string($tokens[$tokenIndex]) && $tokens[$tokenIndex] === '"')); + } + $token = $tokens[$tokenIndex]; + if (is_array($token)) { + list($tokenType, $tokenContent, $tokenLine) = $token; + } else { + $tokenType = null; + $tokenContent = $token; + } + + return $tokenIndex; + }; + $MACRO_TOKEN_LOGICAL_START_INDEX = function () use (&$tokenIndex, &$docCommentIndex) { + return ($docCommentIndex === false) ? $tokenIndex : $docCommentIndex; + }; + $MACRO_DOC_COMMENT_START = function () use (&$tokenIndex, &$docCommentIndex) { + $docCommentIndex = $tokenIndex; + + return $docCommentIndex; + }; + $MACRO_DOC_COMMENT_VALIDATE = function () use (&$tokenType, &$docCommentIndex) { + static $validTrailingTokens = null; + if ($validTrailingTokens === null) { + $validTrailingTokens = array(T_WHITESPACE, T_FINAL, T_ABSTRACT, T_INTERFACE, T_CLASS, T_FUNCTION); + } + if ($docCommentIndex !== false && !in_array($tokenType, $validTrailingTokens)) { + $docCommentIndex = false; + } + + return $docCommentIndex; + }; + $MACRO_INFO_ADVANCE = function () use (&$infoIndex, &$infos, &$tokenIndex, &$tokenLine) { + $infos[$infoIndex]['tokenEnd'] = $tokenIndex; + $infos[$infoIndex]['lineEnd'] = $tokenLine; + $infoIndex++; + + return $infoIndex; + }; + + /** + * START FINITE STATE MACHINE FOR SCANNING TOKENS + */ + + // Initialize token + $MACRO_TOKEN_ADVANCE(); + + SCANNER_TOP: + + if ($token === false) { + goto SCANNER_END; + } + + // Validate current doc comment index + $MACRO_DOC_COMMENT_VALIDATE(); + + switch ($tokenType) { + + case T_DOC_COMMENT: + + $MACRO_DOC_COMMENT_START(); + goto SCANNER_CONTINUE; + + case T_NAMESPACE: + + $infos[$infoIndex] = array( + 'type' => 'namespace', + 'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(), + 'tokenEnd' => null, + 'lineStart' => $token[2], + 'lineEnd' => null, + 'namespace' => null, + ); + + // start processing with next token + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + + SCANNER_NAMESPACE_TOP: + + if ($tokenType === null && $tokenContent === ';' || $tokenContent === '{') { + goto SCANNER_NAMESPACE_END; + } + + if ($tokenType === T_WHITESPACE) { + goto SCANNER_NAMESPACE_CONTINUE; + } + + if ($tokenType === T_NS_SEPARATOR || $tokenType === T_STRING) { + $infos[$infoIndex]['namespace'] .= $tokenContent; + } + + SCANNER_NAMESPACE_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_NAMESPACE_TOP; + + SCANNER_NAMESPACE_END: + + $namespace = $infos[$infoIndex]['namespace']; + + $MACRO_INFO_ADVANCE(); + goto SCANNER_CONTINUE; + + case T_USE: + + $infos[$infoIndex] = array( + 'type' => 'use', + 'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(), + 'tokenEnd' => null, + 'lineStart' => $tokens[$tokenIndex][2], + 'lineEnd' => null, + 'namespace' => $namespace, + 'statements' => array(0 => array('use' => null, + 'as' => null)), + ); + + $useStatementIndex = 0; + $useAsContext = false; + + // start processing with next token + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + + SCANNER_USE_TOP: + + if ($tokenType === null) { + if ($tokenContent === ';') { + goto SCANNER_USE_END; + } elseif ($tokenContent === ',') { + $useAsContext = false; + $useStatementIndex++; + $infos[$infoIndex]['statements'][$useStatementIndex] = array('use' => null, + 'as' => null); + } + } + + // ANALYZE + if ($tokenType !== null) { + + if ($tokenType == T_AS) { + $useAsContext = true; + goto SCANNER_USE_CONTINUE; + } + + if ($tokenType == T_NS_SEPARATOR || $tokenType == T_STRING) { + if ($useAsContext == false) { + $infos[$infoIndex]['statements'][$useStatementIndex]['use'] .= $tokenContent; + } else { + $infos[$infoIndex]['statements'][$useStatementIndex]['as'] = $tokenContent; + } + } + + } + + SCANNER_USE_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_USE_TOP; + + SCANNER_USE_END: + + $MACRO_INFO_ADVANCE(); + goto SCANNER_CONTINUE; + + case T_INCLUDE: + case T_INCLUDE_ONCE: + case T_REQUIRE: + case T_REQUIRE_ONCE: + + // Static for performance + static $includeTypes = array( + T_INCLUDE => 'include', + T_INCLUDE_ONCE => 'include_once', + T_REQUIRE => 'require', + T_REQUIRE_ONCE => 'require_once' + ); + + $infos[$infoIndex] = array( + 'type' => 'include', + 'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(), + 'tokenEnd' => null, + 'lineStart' => $tokens[$tokenIndex][2], + 'lineEnd' => null, + 'includeType' => $includeTypes[$tokens[$tokenIndex][0]], + 'path' => '', + ); + + // start processing with next token + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + + SCANNER_INCLUDE_TOP: + + if ($tokenType === null && $tokenContent === ';') { + goto SCANNER_INCLUDE_END; + } + + $infos[$infoIndex]['path'] .= $tokenContent; + + SCANNER_INCLUDE_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_INCLUDE_TOP; + + SCANNER_INCLUDE_END: + + $MACRO_INFO_ADVANCE(); + goto SCANNER_CONTINUE; + + case T_FUNCTION: + case T_FINAL: + case T_ABSTRACT: + case T_CLASS: + case T_INTERFACE: + + $infos[$infoIndex] = array( + 'type' => ($tokenType === T_FUNCTION) ? 'function' : 'class', + 'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(), + 'tokenEnd' => null, + 'lineStart' => $tokens[$tokenIndex][2], + 'lineEnd' => null, + 'namespace' => $namespace, + 'uses' => $this->getUsesNoScan($namespace), + 'name' => null, + 'shortName' => null, + ); + + $classBraceCount = 0; + + // start processing with current token + + SCANNER_CLASS_TOP: + + // process the name + if ($infos[$infoIndex]['shortName'] == '' + && (($tokenType === T_CLASS || $tokenType === T_INTERFACE) && $infos[$infoIndex]['type'] === 'class' + || ($tokenType === T_FUNCTION && $infos[$infoIndex]['type'] === 'function')) + ) { + $infos[$infoIndex]['shortName'] = $tokens[$tokenIndex + 2][1]; + $infos[$infoIndex]['name'] = (($namespace != null) ? $namespace . '\\' : '') . $infos[$infoIndex]['shortName']; + } + + if ($tokenType === null) { + if ($tokenContent == '{') { + $classBraceCount++; + } + if ($tokenContent == '}') { + $classBraceCount--; + if ($classBraceCount === 0) { + goto SCANNER_CLASS_END; + } + } + } + + SCANNER_CLASS_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_CLASS_TOP; + + SCANNER_CLASS_END: + + $MACRO_INFO_ADVANCE(); + goto SCANNER_CONTINUE; + + } + + SCANNER_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_TOP; + + SCANNER_END: + + /** + * END FINITE STATE MACHINE FOR SCANNING TOKENS + */ + + $this->isScanned = true; + } + + /** + * Check for namespace + * + * @param string $namespace + * @return bool + */ + public function hasNamespace($namespace) + { + $this->scan(); + + foreach ($this->infos as $info) { + if ($info['type'] == 'namespace' && $info['namespace'] == $namespace) { + return true; + } + } + return false; + } + + /** + * @param string $namespace + * @return null|array + * @throws Exception\InvalidArgumentException + */ + protected function getUsesNoScan($namespace) + { + $namespaces = array(); + foreach ($this->infos as $info) { + if ($info['type'] == 'namespace') { + $namespaces[] = $info['namespace']; + } + } + + if ($namespace === null) { + $namespace = array_shift($namespaces); + } elseif (!is_string($namespace)) { + throw new Exception\InvalidArgumentException('Invalid namespace provided'); + } elseif (!in_array($namespace, $namespaces)) { + return null; + } + + $uses = array(); + foreach ($this->infos as $info) { + if ($info['type'] !== 'use') { + continue; + } + foreach ($info['statements'] as $statement) { + if ($info['namespace'] == $namespace) { + $uses[] = $statement; + } + } + } + + return $uses; + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/Util.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/Util.php new file mode 100644 index 0000000..0ed7fc5 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/Util.php @@ -0,0 +1,74 @@ +namespace && !$data->uses && strlen($value) > 0 && $value{0} != '\\') { + $value = $data->namespace . '\\' . $value; + + return; + } + + if (!$data->uses || strlen($value) <= 0 || $value{0} == '\\') { + $value = ltrim($value, '\\'); + + return; + } + + if ($data->namespace || $data->uses) { + $firstPart = $value; + if (($firstPartEnd = strpos($firstPart, '\\')) !== false) { + $firstPart = substr($firstPart, 0, $firstPartEnd); + } else { + $firstPartEnd = strlen($firstPart); + } + + if (array_key_exists($firstPart, $data->uses)) { + $value = substr_replace($value, $data->uses[$firstPart], 0, $firstPartEnd); + + return; + } + + if ($data->namespace) { + $value = $data->namespace . '\\' . $value; + + return; + } + } + } +} diff --git a/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ValueScanner.php b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ValueScanner.php new file mode 100644 index 0000000..a48cfd9 --- /dev/null +++ b/core/vendor/zendframework/zend-code/Zend/Code/Scanner/ValueScanner.php @@ -0,0 +1,15 @@ +=5.3.3", + "zendframework/zend-eventmanager": "self.version" + }, + "require-dev": { + "doctrine/common": ">=2.1" + }, + "suggest": { + "doctrine/common": "Doctrine\\Common >=2.1 for annotation features" + }, + "extra": { + "branch-alias": { + "dev-master": "2.2-dev", + "dev-develop": "2.3-dev" + } + } +} diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/AbstractListenerAggregate.php b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/AbstractListenerAggregate.php new file mode 100644 index 0000000..4d4a443 --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/AbstractListenerAggregate.php @@ -0,0 +1,34 @@ +listeners as $index => $callback) { + if ($events->detach($callback)) { + unset($this->listeners[$index]); + } + } + } +} diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/Event.php b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/Event.php new file mode 100644 index 0000000..31037b9 --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/Event.php @@ -0,0 +1,209 @@ +setName($name); + } + + if (null !== $target) { + $this->setTarget($target); + } + + if (null !== $params) { + $this->setParams($params); + } + } + + /** + * Get event name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Get the event target + * + * This may be either an object, or the name of a static method. + * + * @return string|object + */ + public function getTarget() + { + return $this->target; + } + + /** + * Set parameters + * + * Overwrites parameters + * + * @param array|ArrayAccess|object $params + * @return Event + * @throws Exception\InvalidArgumentException + */ + public function setParams($params) + { + if (!is_array($params) && !is_object($params)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Event parameters must be an array or object; received "%s"', gettype($params) + )); + } + + $this->params = $params; + return $this; + } + + /** + * Get all parameters + * + * @return array|object|ArrayAccess + */ + public function getParams() + { + return $this->params; + } + + /** + * Get an individual parameter + * + * If the parameter does not exist, the $default value will be returned. + * + * @param string|int $name + * @param mixed $default + * @return mixed + */ + public function getParam($name, $default = null) + { + // Check in params that are arrays or implement array access + if (is_array($this->params) || $this->params instanceof ArrayAccess) { + if (!isset($this->params[$name])) { + return $default; + } + + return $this->params[$name]; + } + + // Check in normal objects + if (!isset($this->params->{$name})) { + return $default; + } + return $this->params->{$name}; + } + + /** + * Set the event name + * + * @param string $name + * @return Event + */ + public function setName($name) + { + $this->name = (string) $name; + return $this; + } + + /** + * Set the event target/context + * + * @param null|string|object $target + * @return Event + */ + public function setTarget($target) + { + $this->target = $target; + return $this; + } + + /** + * Set an individual parameter to a value + * + * @param string|int $name + * @param mixed $value + * @return Event + */ + public function setParam($name, $value) + { + if (is_array($this->params) || $this->params instanceof ArrayAccess) { + // Arrays or objects implementing array access + $this->params[$name] = $value; + } else { + // Objects + $this->params->{$name} = $value; + } + return $this; + } + + /** + * Stop further event propagation + * + * @param bool $flag + * @return void + */ + public function stopPropagation($flag = true) + { + $this->stopPropagation = (bool) $flag; + } + + /** + * Is propagation stopped? + * + * @return bool + */ + public function propagationIsStopped() + { + return $this->stopPropagation; + } +} diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/EventInterface.php b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/EventInterface.php new file mode 100644 index 0000000..7974f6e --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/EventInterface.php @@ -0,0 +1,96 @@ +setIdentifiers($identifiers); + } + + /** + * Set the event class to utilize + * + * @param string $class + * @return EventManager + */ + public function setEventClass($class) + { + $this->eventClass = $class; + return $this; + } + + /** + * Set shared event manager + * + * @param SharedEventManagerInterface $sharedEventManager + * @return EventManager + */ + public function setSharedManager(SharedEventManagerInterface $sharedEventManager) + { + $this->sharedManager = $sharedEventManager; + StaticEventManager::setInstance($sharedEventManager); + return $this; + } + + /** + * Remove any shared event manager currently attached + * + * @return void + */ + public function unsetSharedManager() + { + $this->sharedManager = false; + } + + /** + * Get shared event manager + * + * If one is not defined, but we have a static instance in + * StaticEventManager, that one will be used and set in this instance. + * + * If none is available in the StaticEventManager, a boolean false is + * returned. + * + * @return false|SharedEventManagerInterface + */ + public function getSharedManager() + { + // "false" means "I do not want a shared manager; don't try and fetch one" + if (false === $this->sharedManager + || $this->sharedManager instanceof SharedEventManagerInterface + ) { + return $this->sharedManager; + } + + if (!StaticEventManager::hasInstance()) { + return false; + } + + $this->sharedManager = StaticEventManager::getInstance(); + return $this->sharedManager; + } + + /** + * Get the identifier(s) for this EventManager + * + * @return array + */ + public function getIdentifiers() + { + return $this->identifiers; + } + + /** + * Set the identifiers (overrides any currently set identifiers) + * + * @param string|int|array|Traversable $identifiers + * @return EventManager Provides a fluent interface + */ + public function setIdentifiers($identifiers) + { + if (is_array($identifiers) || $identifiers instanceof Traversable) { + $this->identifiers = array_unique((array) $identifiers); + } elseif ($identifiers !== null) { + $this->identifiers = array($identifiers); + } + return $this; + } + + /** + * Add some identifier(s) (appends to any currently set identifiers) + * + * @param string|int|array|Traversable $identifiers + * @return EventManager Provides a fluent interface + */ + public function addIdentifiers($identifiers) + { + if (is_array($identifiers) || $identifiers instanceof Traversable) { + $this->identifiers = array_unique(array_merge($this->identifiers, (array) $identifiers)); + } elseif ($identifiers !== null) { + $this->identifiers = array_unique(array_merge($this->identifiers, array($identifiers))); + } + return $this; + } + + /** + * Trigger all listeners for a given event + * + * Can emulate triggerUntil() if the last argument provided is a callback. + * + * @param string $event + * @param string|object $target Object calling emit, or symbol describing target (such as static method name) + * @param array|ArrayAccess $argv Array of arguments; typically, should be associative + * @param null|callable $callback + * @return ResponseCollection All listener return values + * @throws Exception\InvalidCallbackException + */ + public function trigger($event, $target = null, $argv = array(), $callback = null) + { + if ($event instanceof EventInterface) { + $e = $event; + $event = $e->getName(); + $callback = $target; + } elseif ($target instanceof EventInterface) { + $e = $target; + $e->setName($event); + $callback = $argv; + } elseif ($argv instanceof EventInterface) { + $e = $argv; + $e->setName($event); + $e->setTarget($target); + } else { + $e = new $this->eventClass(); + $e->setName($event); + $e->setTarget($target); + $e->setParams($argv); + } + + if ($callback && !is_callable($callback)) { + throw new Exception\InvalidCallbackException('Invalid callback provided'); + } + + // Initial value of stop propagation flag should be false + $e->stopPropagation(false); + + return $this->triggerListeners($event, $e, $callback); + } + + /** + * Trigger listeners until return value of one causes a callback to + * evaluate to true + * + * Triggers listeners until the provided callback evaluates the return + * value of one as true, or until all listeners have been executed. + * + * @param string $event + * @param string|object $target Object calling emit, or symbol describing target (such as static method name) + * @param array|ArrayAccess $argv Array of arguments; typically, should be associative + * @param callable $callback + * @return ResponseCollection + * @throws Exception\InvalidCallbackException if invalid callable provided + */ + public function triggerUntil($event, $target, $argv = null, $callback = null) + { + if ($event instanceof EventInterface) { + $e = $event; + $event = $e->getName(); + $callback = $target; + } elseif ($target instanceof EventInterface) { + $e = $target; + $e->setName($event); + $callback = $argv; + } elseif ($argv instanceof EventInterface) { + $e = $argv; + $e->setName($event); + $e->setTarget($target); + } else { + $e = new $this->eventClass(); + $e->setName($event); + $e->setTarget($target); + $e->setParams($argv); + } + + if (!is_callable($callback)) { + throw new Exception\InvalidCallbackException('Invalid callback provided'); + } + + // Initial value of stop propagation flag should be false + $e->stopPropagation(false); + + return $this->triggerListeners($event, $e, $callback); + } + + /** + * Attach a listener to an event + * + * The first argument is the event, and the next argument describes a + * callback that will respond to that event. A CallbackHandler instance + * describing the event listener combination will be returned. + * + * The last argument indicates a priority at which the event should be + * executed. By default, this value is 1; however, you may set it for any + * integer value. Higher values have higher priority (i.e., execute first). + * + * You can specify "*" for the event name. In such cases, the listener will + * be triggered for every event. + * + * @param string|array|ListenerAggregateInterface $event An event or array of event names. If a ListenerAggregateInterface, proxies to {@link attachAggregate()}. + * @param callable|int $callback If string $event provided, expects PHP callback; for a ListenerAggregateInterface $event, this will be the priority + * @param int $priority If provided, the priority at which to register the callable + * @return CallbackHandler|mixed CallbackHandler if attaching callable (to allow later unsubscribe); mixed if attaching aggregate + * @throws Exception\InvalidArgumentException + */ + public function attach($event, $callback = null, $priority = 1) + { + // Proxy ListenerAggregateInterface arguments to attachAggregate() + if ($event instanceof ListenerAggregateInterface) { + return $this->attachAggregate($event, $callback); + } + + // Null callback is invalid + if (null === $callback) { + throw new Exception\InvalidArgumentException(sprintf( + '%s: expects a callback; none provided', + __METHOD__ + )); + } + + // Array of events should be registered individually, and return an array of all listeners + if (is_array($event)) { + $listeners = array(); + foreach ($event as $name) { + $listeners[] = $this->attach($name, $callback, $priority); + } + return $listeners; + } + + // If we don't have a priority queue for the event yet, create one + if (empty($this->events[$event])) { + $this->events[$event] = new PriorityQueue(); + } + + // Create a callback handler, setting the event and priority in its metadata + $listener = new CallbackHandler($callback, array('event' => $event, 'priority' => $priority)); + + // Inject the callback handler into the queue + $this->events[$event]->insert($listener, $priority); + return $listener; + } + + /** + * Attach a listener aggregate + * + * Listener aggregates accept an EventManagerInterface instance, and call attach() + * one or more times, typically to attach to multiple events using local + * methods. + * + * @param ListenerAggregateInterface $aggregate + * @param int $priority If provided, a suggested priority for the aggregate to use + * @return mixed return value of {@link ListenerAggregateInterface::attach()} + */ + public function attachAggregate(ListenerAggregateInterface $aggregate, $priority = 1) + { + return $aggregate->attach($this, $priority); + } + + /** + * Unsubscribe a listener from an event + * + * @param CallbackHandler|ListenerAggregateInterface $listener + * @return bool Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found + * @throws Exception\InvalidArgumentException if invalid listener provided + */ + public function detach($listener) + { + if ($listener instanceof ListenerAggregateInterface) { + return $this->detachAggregate($listener); + } + + if (!$listener instanceof CallbackHandler) { + throw new Exception\InvalidArgumentException(sprintf( + '%s: expected a ListenerAggregateInterface or CallbackHandler; received "%s"', + __METHOD__, + (is_object($listener) ? get_class($listener) : gettype($listener)) + )); + } + + $event = $listener->getMetadatum('event'); + if (!$event || empty($this->events[$event])) { + return false; + } + $return = $this->events[$event]->remove($listener); + if (!$return) { + return false; + } + if (!count($this->events[$event])) { + unset($this->events[$event]); + } + return true; + } + + /** + * Detach a listener aggregate + * + * Listener aggregates accept an EventManagerInterface instance, and call detach() + * of all previously attached listeners. + * + * @param ListenerAggregateInterface $aggregate + * @return mixed return value of {@link ListenerAggregateInterface::detach()} + */ + public function detachAggregate(ListenerAggregateInterface $aggregate) + { + return $aggregate->detach($this); + } + + /** + * Retrieve all registered events + * + * @return array + */ + public function getEvents() + { + return array_keys($this->events); + } + + /** + * Retrieve all listeners for a given event + * + * @param string $event + * @return PriorityQueue + */ + public function getListeners($event) + { + if (!array_key_exists($event, $this->events)) { + return new PriorityQueue(); + } + return $this->events[$event]; + } + + /** + * Clear all listeners for a given event + * + * @param string $event + * @return void + */ + public function clearListeners($event) + { + if (!empty($this->events[$event])) { + unset($this->events[$event]); + } + } + + /** + * Prepare arguments + * + * Use this method if you want to be able to modify arguments from within a + * listener. It returns an ArrayObject of the arguments, which may then be + * passed to trigger() or triggerUntil(). + * + * @param array $args + * @return ArrayObject + */ + public function prepareArgs(array $args) + { + return new ArrayObject($args); + } + + /** + * Trigger listeners + * + * Actual functionality for triggering listeners, to which both trigger() and triggerUntil() + * delegate. + * + * @param string $event Event name + * @param EventInterface $e + * @param null|callable $callback + * @return ResponseCollection + */ + protected function triggerListeners($event, EventInterface $e, $callback = null) + { + $responses = new ResponseCollection; + $listeners = $this->getListeners($event); + + // Add shared/wildcard listeners to the list of listeners, + // but don't modify the listeners object + $sharedListeners = $this->getSharedListeners($event); + $sharedWildcardListeners = $this->getSharedListeners('*'); + $wildcardListeners = $this->getListeners('*'); + if (count($sharedListeners) || count($sharedWildcardListeners) || count($wildcardListeners)) { + $listeners = clone $listeners; + + // Shared listeners on this specific event + $this->insertListeners($listeners, $sharedListeners); + + // Shared wildcard listeners + $this->insertListeners($listeners, $sharedWildcardListeners); + + // Add wildcard listeners + $this->insertListeners($listeners, $wildcardListeners); + } + + foreach ($listeners as $listener) { + $listenerCallback = $listener->getCallback(); + + // Trigger the listener's callback, and push its result onto the + // response collection + $responses->push(call_user_func($listenerCallback, $e)); + + // If the event was asked to stop propagating, do so + if ($e->propagationIsStopped()) { + $responses->setStopped(true); + break; + } + + // If the result causes our validation callback to return true, + // stop propagation + if ($callback && call_user_func($callback, $responses->last())) { + $responses->setStopped(true); + break; + } + } + + return $responses; + } + + /** + * Get list of all listeners attached to the shared event manager for + * identifiers registered by this instance + * + * @param string $event + * @return array + */ + protected function getSharedListeners($event) + { + if (!$sharedManager = $this->getSharedManager()) { + return array(); + } + + $identifiers = $this->getIdentifiers(); + //Add wildcard id to the search, if not already added + if (!in_array('*', $identifiers)) { + $identifiers[] = '*'; + } + $sharedListeners = array(); + + foreach ($identifiers as $id) { + if (!$listeners = $sharedManager->getListeners($id, $event)) { + continue; + } + + if (!is_array($listeners) && !($listeners instanceof Traversable)) { + continue; + } + + foreach ($listeners as $listener) { + if (!$listener instanceof CallbackHandler) { + continue; + } + $sharedListeners[] = $listener; + } + } + + return $sharedListeners; + } + + /** + * Add listeners to the master queue of listeners + * + * Used to inject shared listeners and wildcard listeners. + * + * @param PriorityQueue $masterListeners + * @param PriorityQueue $listeners + * @return void + */ + protected function insertListeners($masterListeners, $listeners) + { + foreach ($listeners as $listener) { + $priority = $listener->getMetadatum('priority'); + if (null === $priority) { + $priority = 1; + } elseif (is_array($priority)) { + // If we have an array, likely using PriorityQueue. Grab first + // element of the array, as that's the actual priority. + $priority = array_shift($priority); + } + $masterListeners->insert($listener, $priority); + } + } +} diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/EventManagerAwareInterface.php b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/EventManagerAwareInterface.php new file mode 100644 index 0000000..16d8ba9 --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/EventManagerAwareInterface.php @@ -0,0 +1,24 @@ +setExtractFlags(self::EXTR_BOTH); + + // Iterate and remove any matches + $removed = false; + $items = array(); + $this->rewind(); + while (!$this->isEmpty()) { + $item = $this->extract(); + if ($item['data'] === $datum) { + $removed = true; + continue; + } + $items[] = $item; + } + + // Repopulate + foreach ($items as $item) { + $this->insert($item['data'], $item['priority']); + } + + $this->setExtractFlags(self::EXTR_DATA); + return $removed; + } + + /** + * Iterate the next filter in the chain + * + * Iterates and calls the next filter in the chain. + * + * @param mixed $context + * @param array $params + * @param FilterIterator $chain + * @return mixed + */ + public function next($context = null, array $params = array(), $chain = null) + { + if (empty($context) || $chain->isEmpty()) { + return; + } + + $next = $this->extract(); + if (!$next instanceof CallbackHandler) { + return; + } + + $return = call_user_func($next->getCallback(), $context, $params, $chain); + return $return; + } +} diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/FilterChain.php b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/FilterChain.php new file mode 100644 index 0000000..a270360 --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/FilterChain.php @@ -0,0 +1,120 @@ +filters = new Filter\FilterIterator(); + } + + /** + * Apply the filters + * + * Begins iteration of the filters. + * + * @param mixed $context Object under observation + * @param mixed $argv Associative array of arguments + * @return mixed + */ + public function run($context, array $argv = array()) + { + $chain = clone $this->getFilters(); + + if ($chain->isEmpty()) { + return; + } + + $next = $chain->extract(); + if (!$next instanceof CallbackHandler) { + return; + } + + return call_user_func($next->getCallback(), $context, $argv, $chain); + } + + /** + * Connect a filter to the chain + * + * @param callable $callback PHP Callback + * @param int $priority Priority in the queue at which to execute; defaults to 1 (higher numbers == higher priority) + * @return CallbackHandler (to allow later unsubscribe) + * @throws Exception\InvalidCallbackException + */ + public function attach($callback, $priority = 1) + { + if (empty($callback)) { + throw new Exception\InvalidCallbackException('No callback provided'); + } + $filter = new CallbackHandler($callback, array('priority' => $priority)); + $this->filters->insert($filter, $priority); + return $filter; + } + + /** + * Detach a filter from the chain + * + * @param CallbackHandler $filter + * @return bool Returns true if filter found and unsubscribed; returns false otherwise + */ + public function detach(CallbackHandler $filter) + { + return $this->filters->remove($filter); + } + + /** + * Retrieve all filters + * + * @return Filter\FilterIterator + */ + public function getFilters() + { + return $this->filters; + } + + /** + * Clear all filters + * + * @return void + */ + public function clearFilters() + { + $this->filters = new Filter\FilterIterator(); + } + + /** + * Return current responses + * + * Only available while the chain is still being iterated. Returns the + * current ResponseCollection. + * + * @return null|ResponseCollection + */ + public function getResponses() + { + return null; + } +} diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/GlobalEventManager.php b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/GlobalEventManager.php new file mode 100644 index 0000000..047dd18 --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/GlobalEventManager.php @@ -0,0 +1,135 @@ +trigger($event, $context, $argv); + } + + /** + * Trigger listeners until return value of one causes a callback to evaluate + * to true. + * + * @param string $event + * @param string|object $context + * @param array|object $argv + * @param callable $callback + * @return ResponseCollection + */ + public static function triggerUntil($event, $context, $argv, $callback) + { + return static::getEventCollection()->triggerUntil($event, $context, $argv, $callback); + } + + /** + * Attach a listener to an event + * + * @param string $event + * @param callable $callback + * @param int $priority + * @return CallbackHandler + */ + public static function attach($event, $callback, $priority = 1) + { + return static::getEventCollection()->attach($event, $callback, $priority); + } + + /** + * Detach a callback from a listener + * + * @param CallbackHandler $listener + * @return bool + */ + public static function detach(CallbackHandler $listener) + { + return static::getEventCollection()->detach($listener); + } + + /** + * Retrieve list of events this object manages + * + * @return array + */ + public static function getEvents() + { + return static::getEventCollection()->getEvents(); + } + + /** + * Retrieve all listeners for a given event + * + * @param string $event + * @return PriorityQueue|array + */ + public static function getListeners($event) + { + return static::getEventCollection()->getListeners($event); + } + + /** + * Clear all listeners for a given event + * + * @param string $event + * @return void + */ + public static function clearListeners($event) + { + static::getEventCollection()->clearListeners($event); + } +} diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/ListenerAggregateInterface.php b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/ListenerAggregateInterface.php new file mode 100644 index 0000000..4d10e71 --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/ListenerAggregateInterface.php @@ -0,0 +1,42 @@ +listeners as $index => $callback) { + if ($events->detach($callback)) { + unset($this->listeners[$index]); + } + } + } +} diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/ProvidesEvents.php b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/ProvidesEvents.php new file mode 100644 index 0000000..ea46333 --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/ProvidesEvents.php @@ -0,0 +1,63 @@ +eventIdentifier)) { + if ((is_string($this->eventIdentifier)) + || (is_array($this->eventIdentifier)) + || ($this->eventIdentifier instanceof Traversable) + ) { + $identifiers = array_unique(array_merge($identifiers, (array) $this->eventIdentifier)); + } elseif (is_object($this->eventIdentifier)) { + $identifiers[] = $this->eventIdentifier; + } + // silently ignore invalid eventIdentifier types + } + $events->setIdentifiers($identifiers); + $this->events = $events; + return $this; + } + + /** + * Retrieve the event manager + * + * Lazy-loads an EventManager instance if none registered. + * + * @return EventManagerInterface + */ + public function getEventManager() + { + if (!$this->events instanceof EventManagerInterface) { + $this->setEventManager(new EventManager()); + } + return $this->events; + } +} diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/README.md b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/README.md new file mode 100644 index 0000000..474b103 --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/README.md @@ -0,0 +1,15 @@ +EventManager Component from ZF2 +=============================== + +This is the EventManager component for ZF2. + +- File issues at https://github.com/zendframework/zf2/issues +- Create pull requests against https://github.com/zendframework/zf2 +- Documentation is at http://framework.zend.com/docs + +LICENSE +------- + +The files in this archive are released under the [Zend Framework +license](http://framework.zend.com/license), which is a 3-clause BSD license. + diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/ResponseCollection.php b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/ResponseCollection.php new file mode 100644 index 0000000..5131d1d --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/ResponseCollection.php @@ -0,0 +1,84 @@ +stopped; + } + + /** + * Mark the collection as stopped (or its opposite) + * + * @param bool $flag + * @return ResponseCollection + */ + public function setStopped($flag) + { + $this->stopped = (bool) $flag; + return $this; + } + + /** + * Convenient access to the first handler return value. + * + * @return mixed The first handler return value + */ + public function first() + { + return parent::bottom(); + } + + /** + * Convenient access to the last handler return value. + * + * If the collection is empty, returns null. Otherwise, returns value + * returned by last handler. + * + * @return mixed The last handler return value + */ + public function last() + { + if (count($this) === 0) { + return null; + } + return parent::top(); + } + + /** + * Check if any of the responses match the given value. + * + * @param mixed $value The value to look for among responses + * @return bool + */ + public function contains($value) + { + foreach ($this as $response) { + if ($response === $value) { + return true; + } + } + return false; + } +} diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/SharedEventAggregateAwareInterface.php b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/SharedEventAggregateAwareInterface.php new file mode 100644 index 0000000..69b2b79 --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/SharedEventAggregateAwareInterface.php @@ -0,0 +1,34 @@ + + * $sharedEventManager = new SharedEventManager(); + * $sharedEventManager->attach( + * array('My\Resource\AbstractResource', 'My\Resource\EntityResource'), + * 'getAll', + * function ($e) use ($cache) { + * if (!$id = $e->getParam('id', false)) { + * return; + * } + * if (!$data = $cache->load(get_class($resource) . '::getOne::' . $id )) { + * return; + * } + * return $data; + * } + * ); + * + * + * @param string|array $id Identifier(s) for event emitting component(s) + * @param string $event + * @param callable $callback PHP Callback + * @param int $priority Priority at which listener should execute + * @return CallbackHandler|array Either CallbackHandler or array of CallbackHandlers + */ + public function attach($id, $event, $callback, $priority = 1) + { + $ids = (array) $id; + $listeners = array(); + foreach ($ids as $id) { + if (!array_key_exists($id, $this->identifiers)) { + $this->identifiers[$id] = new EventManager($id); + } + $listeners[] = $this->identifiers[$id]->attach($event, $callback, $priority); + } + if (count($listeners) > 1) { + return $listeners; + } + return $listeners[0]; + } + + /** + * Attach a listener aggregate + * + * Listener aggregates accept an EventManagerInterface instance, and call attachShared() + * one or more times, typically to attach to multiple events using local + * methods. + * + * @param SharedListenerAggregateInterface $aggregate + * @param int $priority If provided, a suggested priority for the aggregate to use + * @return mixed return value of {@link ListenerAggregateInterface::attachShared()} + */ + public function attachAggregate(SharedListenerAggregateInterface $aggregate, $priority = 1) + { + return $aggregate->attachShared($this, $priority); + } + + /** + * Detach a listener from an event offered by a given resource + * + * @param string|int $id + * @param CallbackHandler $listener + * @return bool Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found + */ + public function detach($id, CallbackHandler $listener) + { + if (!array_key_exists($id, $this->identifiers)) { + return false; + } + return $this->identifiers[$id]->detach($listener); + } + + /** + * Detach a listener aggregate + * + * Listener aggregates accept an SharedEventManagerInterface instance, and call detachShared() + * of all previously attached listeners. + * + * @param SharedListenerAggregateInterface $aggregate + * @return mixed return value of {@link SharedListenerAggregateInterface::detachShared()} + */ + public function detachAggregate(SharedListenerAggregateInterface $aggregate) + { + return $aggregate->detachShared($this); + } + + /** + * Retrieve all registered events for a given resource + * + * @param string|int $id + * @return array + */ + public function getEvents($id) + { + if (!array_key_exists($id, $this->identifiers)) { + //Check if there are any id wildcards listeners + if ('*' != $id && array_key_exists('*', $this->identifiers)) { + return $this->identifiers['*']->getEvents(); + } + return false; + } + return $this->identifiers[$id]->getEvents(); + } + + /** + * Retrieve all listeners for a given identifier and event + * + * @param string|int $id + * @param string|int $event + * @return false|PriorityQueue + */ + public function getListeners($id, $event) + { + if (!array_key_exists($id, $this->identifiers)) { + return false; + } + return $this->identifiers[$id]->getListeners($event); + } + + /** + * Clear all listeners for a given identifier, optionally for a specific event + * + * @param string|int $id + * @param null|string $event + * @return bool + */ + public function clearListeners($id, $event = null) + { + if (!array_key_exists($id, $this->identifiers)) { + return false; + } + + if (null === $event) { + unset($this->identifiers[$id]); + return true; + } + + return $this->identifiers[$id]->clearListeners($event); + } +} diff --git a/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/SharedEventManagerAwareInterface.php b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/SharedEventManagerAwareInterface.php new file mode 100644 index 0000000..c982948 --- /dev/null +++ b/core/vendor/zendframework/zend-eventmanager/Zend/EventManager/SharedEventManagerAwareInterface.php @@ -0,0 +1,38 @@ +=5.3.3", + "zendframework/zend-stdlib": "self.version" + }, + "extra": { + "branch-alias": { + "dev-master": "2.2-dev", + "dev-develop": "2.3-dev" + } + } +}