PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,7 @@
vendor
composer.lock
composer.phar
phpunit.xml
phpmd.xml
phpdox.xml
clover.xml

View File

@ -0,0 +1,45 @@
before_commands:
- "composer install --no-dev --prefer-source"
tools:
external_code_coverage:
timeout: 600
php_code_coverage:
enabled: true
php_code_sniffer:
enabled: true
config:
standard: PSR2
filter:
paths: ["src/*", "tests/*"]
php_cpd:
enabled: true
excluded_dirs: ["docs", "examples", "tests", "vendor"]
php_cs_fixer:
enabled: true
config:
level: all
filter:
paths: ["src/*", "tests/*"]
php_loc:
enabled: true
excluded_dirs: ["docs", "examples", "tests", "vendor"]
php_mess_detector:
enabled: true
config:
ruleset: phpmd.xml.dist
design_rules: { eval_expression: false }
filter:
paths: ["src/*"]
php_pdepend:
enabled: true
excluded_dirs: ["docs", "examples", "tests", "vendor"]
php_analyzer:
enabled: true
filter:
paths: ["src/*", "tests/*"]
php_hhvm:
enabled: true
filter:
paths: ["src/*", "tests/*"]
sensiolabs_security_checker: true

View File

@ -0,0 +1,11 @@
set -x
if [ "$TRAVIS_PHP_VERSION" = 'hhvm' ] || [ "$TRAVIS_PHP_VERSION" = 'hhvm-nightly' ] ; then
curl -sS https://getcomposer.org/installer > composer-installer.php
hhvm composer-installer.php
hhvm -v ResourceLimit.SocketDefaultTimeout=30 -v Http.SlowQueryThreshold=30000 composer.phar update --prefer-source
hhvm -v ResourceLimit.SocketDefaultTimeout=30 -v Http.SlowQueryThreshold=30000 composer.phar install --dev --prefer-source
else
composer self-update
composer update --prefer-source
composer install --dev --prefer-source
fi

View File

@ -0,0 +1,28 @@
language: php
php:
- 5.3.3
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
- hhvm-nightly
before_script:
- sh .travis.install.sh
script:
- ./vendor/bin/phpunit --disallow-test-output --report-useless-tests --coverage-clover ./clover.xml --group=Coverage
- ./vendor/bin/phpunit --disallow-test-output --report-useless-tests --strict --exclude-group=Performance,Coverage
- php -n ./vendor/bin/phpunit --group=Performance
- ./vendor/bin/phpcs --standard=PSR2 ./src/ ./tests/
matrix:
allow_failures:
- php: hhvm
- php: hhvm-nightly
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover ./clover.xml

View File

@ -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.

View File

@ -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.

View File

@ -0,0 +1,50 @@
# 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)
[![Code Coverage](https://scrutinizer-ci.com/g/Ocramius/ProxyManager/badges/coverage.png?s=ca3b9ceb9e36aeec0e57569cc8983394b7d2a59e)](https://scrutinizer-ci.com/g/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/)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/69fe5f97-b1c8-4ddd-93ce-900b8b788cf2/mini.png)](https://insight.sensiolabs.com/projects/69fe5f97-b1c8-4ddd-93ce-900b8b788cf2)
[![Dependency Status](https://www.versioneye.com/package/php--ocramius--proxy-manager/badge.png)](https://www.versioneye.com/package/php--ocramius--proxy-manager)
[![Reference Status](https://www.versioneye.com/php/ocramius:proxy-manager/reference_badge.svg)](https://www.versioneye.com/php/ocramius:proxy-manager/references)
[![HHVM Status](http://hhvm.h4cc.de/badge/ocramius/proxy-manager.png)](http://hhvm.h4cc.de/package/ocramius/proxy-manager)
[![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)
## Documentation
You can learn about the proxy pattern and how to use the **ProxyManager** on the [online documentation](http://ocramius.github.io/ProxyManager).
## Installation
The suggested installation method is via [composer](https://getcomposer.org/):
```sh
php composer.phar require ocramius/proxy-manager:1.0.*
```
## Proxy example
Here's how you build a lazy loadable object with ProxyManager using a *Virtual Proxy*
```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
}
);
$proxy->doFoo();
```
See the [online documentation](http://ocramius.github.io/ProxyManager) for more supported proxy types and examples.

View File

@ -0,0 +1,19 @@
This is a list of supported versions, with their expected release/support time-frames:
# 0.5.x
* Release date: 2013-12-01
* Bug fixes: till 2015-03-11
* Security fixes: till 2015-12-11
# 1.0.x
* Release date: 2014-12-12
* Bug fixes: till 2015-12-11
* Security fixes: till 2016-12-11
# 2.0.x
* Release date: TBA
* Bug fixes: TBA
* Security fixes: TBA

View File

@ -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.

View File

@ -0,0 +1,53 @@
{
"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",
"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.2.5,<3.0"
},
"require-dev": {
"ext-phar": "*",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "1.5.*"
},
"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"
}
},
"autoload-dev": {
"psr-0": {
"ProxyManagerTest\\": "tests",
"ProxyManagerTestAsset\\": "tests"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
}
}

View File

@ -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 scope localizer :
```php
<?php
use ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory as Factory;
require_once __DIR__ . '/vendor/autoload.php';
class Foo
{
public function doFoo()
{
echo "Foo!\n";
}
}
$factory = new Factory();
$proxy = $factory->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).

View File

@ -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
<?php
use ProxyManager\Factory\AccessInterceptorValueHolderFactory as Factory;
require_once __DIR__ . '/vendor/autoload.php';
class Foo
{
public function doFoo()
{
echo "Foo!\n";
}
}
$factory = new Factory();
$proxy = $factory->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).

View File

@ -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.

View File

@ -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 = unserialize(serialize($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).

View File

@ -0,0 +1,202 @@
# 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 __construct()
{
// just write your business logic
// don't worry about how heavy initialization of this will be!
}
public function doFoo() {
echo "OK!"
}
}
```
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).

View File

@ -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
wouldnt 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).

View File

@ -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).

View File

@ -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.

View File

@ -0,0 +1,38 @@
<?php
/**
* This example demonstrates how an access interceptor scope localizer
* (which is a specific type of smart reference) is safe to use to
* proxy fluent interfaces.
*/
require_once __DIR__ . '/../vendor/autoload.php';
use ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory;
class FluentCounter
{
public $counter = 0;
/** @return FluentCounter */
public function fluentMethod()
{
$this->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";

View File

@ -0,0 +1,46 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use ProxyManager\Factory\LazyLoadingGhostFactory;
class Foo
{
private $foo;
public function __construct()
{
sleep(5);
}
public function setFoo($foo)
{
$this->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));

View File

@ -0,0 +1,36 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use ProxyManager\Factory\RemoteObject\Adapter\XmlRpc;
use ProxyManager\Factory\RemoteObjectFactory;
use Zend\XmlRpc\Client;
if (! class_exists('Zend\XmlRpc\Client')) {
echo "This example needs Zend\\XmlRpc\\Client to run. \n In order to install it, "
. "please run following:\n\n"
. "\$ php composer.phar require zendframework/zend-xmlrpc:2.*\n\n";
exit(2);
}
class Foo
{
public function bar()
{
return 'bar local!';
}
}
$factory = new RemoteObjectFactory(
new XmlRpc(new Client('http://localhost:9876/remote-proxy/remote-proxy-server.php'))
);
$proxy = $factory->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);
}

View File

@ -0,0 +1,20 @@
<?php
use Zend\XmlRpc\Server;
require_once __DIR__ . '/../../vendor/autoload.php';
class Foo
{
public function bar()
{
return 'bar remote!';
}
}
$server = new Server();
$server->setClass(new Foo(), 'Foo');
$server->setReturnResponse(false);
$server->handle();

View File

@ -0,0 +1,23 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use ProxyManager\Factory\AccessInterceptorValueHolderFactory;
class Foo
{
public function doFoo()
{
echo "Foo!\n";
}
}
$factory = new AccessInterceptorValueHolderFactory();
$proxy = $factory->createProxy(
new Foo(),
array('doFoo' => function () { echo "pre-foo!\n"; }),
array('doFoo' => function () { echo "post-foo!\n"; })
);
$proxy->doFoo();

View File

@ -0,0 +1,39 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
class Foo
{
public function __construct()
{
sleep(5);
}
public function doFoo()
{
echo "Foo!";
}
}
$startTime = microtime(true);
$factory = new LazyLoadingValueHolderFactory();
for ($i = 0; $i < 1000; $i += 1) {
$proxy = $factory->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));

View File

@ -0,0 +1,197 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager - Tuning the ProxyManager for production</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, production" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content">
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<div class="bcms-clearfix"></div>
<h3 class="section-title">Access Interceptor Scope Localizer Proxy</h3>
<p>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.</p>
<p>It works exactly like the <a href="access-interceptor-value-holder-proxy.html">access interceptor value holder</a>, with some minor differences in behavior.</p>
<p>The working concept of an access interceptor scope localizer is to localize scope of a proxied object:</p>
<pre>
<code class="php">
class Example
{
protected $foo;
protected $bar;
protected $baz;
public function doFoo()
{
// ...
}
}
class ExampleProxy extends Example
{
public function __construct(Example $example)
{
$this->foo = &amp; $example->foo;
$this->bar = &amp; $example->bar;
$this->baz = &amp; $example->baz;
}
public function doFoo()
{
return parent::doFoo();
}
}
</code>
</pre>
<p>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.</p>
<p>The main advantage of this approach is that the proxy is now safe against fluent interfaces, which would break an <a href="access-interceptor-value-holder-proxy.html">access interceptor value holder</a> instead.</p>
<hr />
<h3>Differences with <a href="access-interceptor-value-holder-proxy.html">access interceptor value holder</a>:</h3>
<ul>
<li>It does <strong>NOT</strong> implement the <code>ProxyManager\Proxy\ValueHolderInterface</code>, since the proxy itself does not keep a reference to the original object being proxied</li>
<li>In all interceptor methods (see <a href="access-interceptor-value-holder-proxy.html">access interceptor value holder</a>), 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.</li>
</ul>
<hr />
<h3>Known limitations</h3>
<ul>
<li>It is <strong>NOT</strong> possible to intercept access to public properties</li>
<li>It is <strong>NOT</strong> possible to proxy interfaces, since this proxy relies on <code>parent::method()</code> calls. Interfaces obviously don't provide a parent method implementation.</li>
<li>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.</li>
<li>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</li>
<li>if a proxied object contains private properties, then an exception will be thrown if you use PHP <code>&lt; 5.4.0</code>.</li>
</ul>
<hr />
<h3>Example</h3>
<p>Here's an example of how you can create and use an access interceptor scope localizer :</p>
<pre>
<code class="php">
&lt;?php
use ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory as Factory;
require_once __DIR__ . '/vendor/autoload.php';
class Foo
{
public function doFoo()
{
echo "Foo!\n";
}
}
$factory = new Factory();
$proxy = $factory->createProxy(
new Foo(),
array('doFoo' => function () { echo "PreFoo!\n"; }),
array('doFoo' => function () { echo "PostFoo!\n"; })
);
$proxy->doFoo();
</code>
</pre>
<p>This send something like following to your output:</p>
<pre>
<code class="php">
PreFoo!
Foo!
PostFoo!
</code>
</pre>
<p>This is pretty much the same logic that you can find in <a href="access-interceptor-value-holder-proxy.html">access interceptor value holder</a>.</p>
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

View File

@ -0,0 +1,208 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager - Tuning the ProxyManager for production</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, production" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content">
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<div class="bcms-clearfix"></div>
<h3 class="section-title">Access Interceptor Value Holder Proxy</h3>
<p>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.</p>
<p>It wraps around a real instance of the object to be proxied, and can be useful for things like:</p>
<ul>
<li>caching execution of slow and heavy methods</li>
<li>log method calls</li>
<li>debugging</li>
<li>event triggering</li>
<li>handling of orthogonal logic, and <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming" target="_blank">AOP</a> in general</li>
</ul>
<hr />
<h3>Example</h3>
<p>Here's an example of how you can create and use an access interceptor value holder:</p>
<pre>
<code class="php">
&lt;?php
use ProxyManager\Factory\AccessInterceptorValueHolderFactory as Factory;
require_once __DIR__ . '/vendor/autoload.php';
class Foo
{
public function doFoo()
{
echo "Foo!\n";
}
}
$factory = new Factory();
$proxy = $factory->createProxy(
new Foo(),
array('doFoo' => function () { echo "PreFoo!\n"; }),
array('doFoo' => function () { echo "PostFoo!\n"; })
);
$proxy->doFoo();
</code>
</pre>
<p>This send something like following to your output:</p>
<pre>
<code class="php">
PreFoo!
Foo!
PostFoo!
</code>
</pre>
<hr />
<h3>Implementing pre- and post- access interceptors</h3>
<p>A proxy produced by the <code><a href="https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php" target="_blank">ProxyManager\Factory\AccessInterceptorValueHolderFactory</a></code> implements both the <code><a href="https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/ValueHolderInterface.php" target="_blank">ProxyManager\Proxy\ValueHolderInterface</a></code> and the <code><a href="https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/ValueHolderInterface.php" target="_blank">ProxyManager\Proxy\AccessInterceptorInterface</a></code>.</p>
<p>Therefore, you can set an access interceptor callback by calling:</p>
<pre>
<code class="php">
$proxy->setMethodPrefixInterceptor('methodName', function () { echo 'pre'; });
$proxy->setMethodSuffixInterceptor('methodName', function () { echo 'post'; });
</code>
</pre>
<p>You can also listen to public properties access by attaching interceptors to <code>__get</code>, <code>__set</code>, <code>__isset</code> and <code>__unset</code>.</p>
<p>A prefix interceptor (executed before method logic) should have following signature:</p>
<pre>
<code class="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, &amp; $returnEarly) {};
</code>
</pre>
A suffix interceptor (executed after method logic) should have following signature:
<pre>
<code class="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) {};
</code>
</pre>
<hr />
<h3>Tuning performance for production</h3>
<p>See <a href="production.html">Tuning ProxyManager for Production</a>.</p>
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

View File

@ -0,0 +1,139 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager - Contributing</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, contributing" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content">
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<div class="bcms-clearfix"></div>
<h3 class="section-title">Contributing</h3>
<ul>
<li>Coding standard for the project is <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md" target-"_blank">PSR-2</a></li>
<li>The project will follow strict <a href="http://www.slideshare.net/guilhermeblanco/object-calisthenics-applied-to-php" target-"_blank">object calisthenics</a></li>
<li>Any contribution must provide tests for additional introduced conditions</li>
<li>Any un-confirmed issue needs a failing test case before being accepted</li>
<li>Pull requests must be sent from a new hotfix/feature branch, not from master.</li>
</ul>
<hr />
<h3 class="section-title">Installation</h3>
<p>To install the project and run the tests, you need to clone it first:</p>
<pre>
<code class="sh">
$ git clone git://github.com/Ocramius/ProxyManager.git
</code>
</pre>
<p>You will then need to run a composer installation:</p>
<pre>
<code class="sh">
$ cd ProxyManager
$ curl -s https://getcomposer.org/installer | php
$ php composer.phar update
</code>
</pre>
<hr />
<h3 class="section-title">Testing</h3>
<p>The PHPUnit version to be used is the one installed as a dev- dependency via composer:</p>
<pre>
<code class="sh">
$ ./vendor/bin/phpunit
</code>
</pre>
<p>Accepted coverage for new contributions is 80%. Any contribution not satisfying this requirement won't be merged.</p>
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

View File

@ -0,0 +1,100 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content">
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<div class="bcms-clearfix"></div>
<h3 class="section-title">License</h3>
<p>Copyright (c) 2013 Marco Pivetta</p>
<p>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:</p>
<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
<p>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.</p>
<hr />
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

View File

@ -0,0 +1,113 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager - Credits</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, credits" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content">
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<div class="bcms-clearfix"></div>
<h3 class="section-title">Credits</h3>
<p>The idea was originated by a <a href="http://marco-pivetta.com/proxy-pattern-in-php/" target="_blank">talk about Proxies in PHP OOP</a> that I gave at the <a href="https://twitter.com/phpugffm" target="_blank">@phpugffm</a> in January 2013.</p>
<hr />
<h3>Contributors</h3>
<ul>
<li><a href="https://github.com/Ocramius" target="_blank">Marco Pivetta</a></li>
<li><a href="https://github.com/malukenho" target="_blank">Jefersson Nathan</a></li>
<li><a href="https://github.com/blanchonvincent" target="_blank">Blanchon Vincent</a></li>
<li><a href="https://github.com/staabm" target="_blank">Markus Staab</a></li>
<li><a href="https://github.com/gws" target="_blank">Gordon Stratton</a></li>
<li><a href="https://github.com/prolic" target="_blank">Prolic</a></li>
<li><a href="https://github.com/guilro" target="_blank">Guillaume Royer</a></li>
<li><a href="https://github.com/reiz" target="_blank">Robert Reiz</a></li>
<li><a href="https://github.com/leedavis81" target="_blank">Lee Davis</a></li>
<li><a href="https://github.com/flip111" target="_blank">flip111</a></li>
<li><a href="https://github.com/krymen" target="_blank">Krzysztof Menzyk</a></li>
<li><a href="https://github.com/Xerkus" target="_blank">Aleksey Khudyakov</a></li>
<li><a href="https://github.com/asm89" target="_blank">Alexander</a></li>
<li><a href="https://github.com/raulfraile" target="_blank">Raul Fraile</a></li>
</ul>
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

View File

@ -0,0 +1,203 @@
html { font-family: sans-serif; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; }
body { margin: 0; }
article, aside, details, figcaption, figure, footer, header, hgroup, main, nav, section, summary { display: block; }
audio, canvas, progress, video { display: inline-block; vertical-align: baseline; }
audio:not([controls]) { display: none; height: 0; }
[hidden], template { display: none; }
a { background: transparent; }
a:active, a:hover { outline: 0; }
abbr[title] { border-bottom: 1px dotted; }
b, strong { font-weight: bold; }
dfn { font-style: italic; }
h1 { font-size: 2em; margin: 0.67em 0; }
mark { background: #ff0; color: #000; }
small { font-size: 80%; }
sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; }
sup { top: -0.5em; }
sub { bottom: -0.25em; }
img { border: 0; }
svg:not(:root) { overflow: hidden; }
figure { margin: 1em 40px; }
hr { -moz-box-sizing: content-box; box-sizing: content-box; height: 0; }
pre { overflow: auto; }
code, kbd, pre, samp { font-family: monospace, monospace; font-size: 1em; }
button, input, optgroup, select, textarea { color: inherit; font: inherit; margin: 0; }
button { overflow: visible; }
button, select { text-transform: none; }
button, html input[type="button"], input[type="reset"], input[type="submit"] { -webkit-appearance: button; cursor: pointer; }
button[disabled], html input[disabled] { cursor: default; }
button::-moz-focus-inner, input::-moz-focus-inner { border: 0; padding: 0; }
input { line-height: normal; }
input[type="checkbox"], input[type="radio"] { box-sizing: border-box; padding: 0; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { height: auto; }
input[type="search"] { -webkit-appearance: textfield; -moz-box-sizing: content-box; -webkit-box-sizing: content-box; box-sizing: content-box; }
input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }
fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em; }
legend { border: 0; padding: 0; }
textarea { overflow: auto; }
optgroup { font-weight: bold; }
table { border-collapse: collapse; border-spacing: 0; }
td, th { padding: 0; }
h1, h2, h3, h4, h5, h6, p, ul, ol, li { margin: 0; padding: 0; line-height: normal; }
a { color: #31811D; text-decoration: none; }
a:hover { color: #2F611C; text-decoration: none; }
strong { font-weight: 600; }
h3 { margin-bottom: 1em; color: #17324f; font-weight: 400; font-size: 3em; }
h4 { margin-bottom: 1em; font-weight: 400; font-size: 1.375em; }
p { margin-bottom: 1.5em; font-size: 1.125em; }
hr { margin: 2.5em 0; padding: 0; width: 100%; height: 3px; border: 0; background: #e6eaef; }
pre code { padding: 20px; border: 1px solid #EBEBEB; background: #F5F5F5; color: #08468a; font-weight: 200; font-size: .875em; }
code { background: transparent; color: #08468a; font-size: .875em; }
form { margin: 0; }
label { display: block; color: #18324f; font-weight: 400; font-size: 1.5em; margin-bottom: 2em; }
legend { position: static; margin: 0; padding: 0; font-weight: normal; }
legend span { position: absolute; top: 0; right: 0; left: 0; display: block; padding: 7px 0; border-bottom: 1px solid #e0dede; color: #ed4a21; font-size: 18px; line-height: 1em; }
/* Menu Sidebar*/
.button-block { padding-top: 15px; }
.button-block .btn-1 { margin-right: 6px; }
.btn, .spy-nav a { position: relative; display: inline-block; margin: 0; padding: 0 20px; height: 57px; border: 0; vertical-align: top; text-align: center; text-transform: uppercase; font-weight: 400; font-size: 1.125em; transitionP: all .2s; line-height: 57px; }
.btn.btn-action, .spy-nav a.btn-action { background: #ee2d4d; color: #fff; }
.btn.btn-action:hover, .spy-nav a.btn-action:hover { background: #bf0f2d; }
.btn.btn-default, .spy-nav a { background: #31811D; color: #fff; }
.btn.btn-default:hover, .spy-nav a:hover { background: #2F611C; color: #fff; }
.btn.btn-text, .spy-nav a.btn-text { color: #18324f; font-weight: 600; }
.btn.btn-full, .spy-nav a { display: block; }
@media only screen and (max-width: 480px) {
.site-header{ position: fixed !important; top: 0; z-index: 999999}
.page-title-wrapper{ margin-top: 70px;}
.main-wrapper iframe{ width: 42% !important; float: left; margin-left: 8%;}
.content iframe{width: 100%; height: 100%;}
}
.btn-top { position: relative; display: inline-block; float: right; margin: 20px 0 0; padding: 0 30px 0 50px; height: 57px; border: 2px solid ##31811D; color: #31811D; vertical-align: top; text-align: center; text-transform: uppercase; font-weight: 600; font-size: 1.125em; line-height: 53px; transition: all .2s; }
.btn-top:before { background-position: 0 -140px; width: 52px; height: 52px; position: absolute; top: 0; left: 0; content: ''; }
@media only screen and (min-resolution: 2dppx), (-webkit-min-device-pixel-ratio: 2) { .btn-top:before { background-position: 0 -140px; background-size: 152px auto; width: 52px; height: 52px; } }
.btn-top:hover { border-color: #2F611C; color: #2F611C; }
@media only screen and (max-width: 768px) { .btn-top { float: none; margin-top: 0; margin-bottom: 30px; white-space: nowrap; } }
@media only screen and (max-width: 480px) { .btn-top { font-size: 0.9em; line-height: 46px; height: 48px; padding-right: 22px; padding-left: 47px; } }
.btn-download { float: right; padding-left: 50px; }
.btn-download:before { background-position: -18px -116px; width: 16px; height: 16px; position: absolute; top: 50%; left: 20px; margin-top: -7px; content: ''; }
@media only screen and (min-resolution: 2dppx), (-webkit-min-device-pixel-ratio: 2) { .btn-download:before { background-position: -18px -116px; background-size: 152px auto; width: 16px; height: 16px; } }
.btn-done { float: right; padding-left: 50px; }
.btn-done:before { background-position: 0 -116px; width: 18px; height: 14px; position: absolute; top: 50%; margin-top: -7px; left: 20px; content: ''; }
@media only screen and (min-resolution: 2dppx), (-webkit-min-device-pixel-ratio: 2) { .btn-done:before { background-position: 0 -116px; background-size: 152px auto; width: 18px; height: 13.5px; margin-top: -6.75px; } }
.btn-cancel { float: right; }
*, *:before, *:after { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; min-width: 280px; }
@media only screen and (min-width: 64.063em) and (max-width: 90em) { html { min-width: 960px; } }
body { font-size: 16px; font-family: 'Source Sans Pro', sans-serif; min-width: 290px; }
@media only screen and (max-width: 480px) { body.page-home { background-image: none; } }
img { max-width: 100%; height: auto !important; }
input { -webkit-appearance: none; -webkit-border-radius: 0; border-radius: 0; }
main { overflow: hidden; }
.clearfix:after { content: ""; display: table; clear: both; }
.container { width: 60em; margin-left: auto; margin-right: auto; }
.container:after { content: " "; display: block; clear: both; }
@media only screen and (max-width: 1024px) { .container { margin-left: 15px; margin-right: 15px; width: auto; } }
.content ul { padding-left: 19px; list-style-type: square; margin-top: 15px; }
/* Menu top */
.main-nav { float: right; }
.fixed-wrapper .main-nav { display: none; }
.active .main-nav { display: block; }
.main-nav > ul { list-style: none; }
.main-nav > ul > li { float: left; }
.main-nav > ul > li > a { display: block; padding: 22px 30px; color: #fff; text-decoration: none; text-transform: uppercase; font-weight: 600; font-size: 1.375em; line-height: 29px; transition: all .2s; }
.main-nav > ul > li > a:hover { color: #bfe5f1; background-color: #2F611C; }
.main-nav > ul > li > a.active { background-color: #2F611C; color: #fff; }
.main-nav > ul > li > a.opened { background-color: #18324f; }
@media only screen and (max-width: 600px) { .main-nav { font-size: 0.86em; }
.main-nav > ul > li > a { padding-left: 18px; padding-right: 18px; } }
@media only screen and (max-width: 480px) { .main-nav > ul > li > a { font-size: 0.95em; padding: 22px 6px; } }
.site-header { position: relative; width: 100%; background: #31811D; }
.site-header h1 { float: left; margin: 15px 0; }
.site-header h1 a { display: block; }
.site-header h1 img { display: block; max-height: 42px; }
@media only screen and (max-width: 480px) { .site-header h1 img { max-height: 42px; } }
.page-title-wrapper { position: relative; padding: 26px 0 55px; text-align: center; }
.page-title-wrapper .page-title { margin-top: 44px; color: #17324f; font-weight: 400; font-size: 3.75em; }
.page-title-wrapper .linguistics { padding: 0 2em 13px; border-bottom: 1px solid #D4DBE3; color: #18324f; text-transform: uppercase; font-weight: 400; font-size: 1.25em; }
@media only screen and (max-width: 768px) { .page-title-wrapper { font-size: 0.8em; } }
@media only screen and (max-width: 480px) { .page-title-wrapper { font-size: 0.65em; } }
.site-footer { margin-top: 20px; padding-top: 50px; padding-bottom: 50px; background: #18324f; color: #7c8ea3; text-align: center; }
.site-footer .container { position: relative; }
.site-footer + .bcms-clearfix:after { content: ""; }
.about + .site-footer .main { padding-top: 150px; }
.footer-logos ul li{ list-style: none; display: inline-block;}
.footer-logos ul li a{ padding-left: 10px; padding-right: 10px}
.site-footer a{ color: white !important;}
.site-footer p { text-align: left; display: block; margin-bottom: 1.5em; font-size: 1.125em; }
@media only screen and (max-width: 1024px) { .site-footer p { margin-left: 0; } }
@media only screen and (max-width: 768px) { .site-footer p { text-align: center; margin-left: auto; } }
@media only screen and (max-width: 600px) { .site-footer { font-size: 0.9em; } }
.main-logo { display: block; float: left; margin: 30px 0; }
.fixed-wrapper .main-logo { display: none; }
.main-logo img { display: block; }
.main-logo figure { position: relative; margin: 0; max-width: 56px; }
.main-logo figcaption { position: absolute; width: 160px; top: 20px; left: 68px; }
.active .main-logo { display: block; margin: 0; }
.active .main-logo figure { max-width: 42px; }
.active .main-logo figcaption { width: 120px; top: 15px; left: 55px; }
@media only screen and (max-width: 480px) { .main-logo figcaption { display: none; } }
.container { width: 60em; margin-left: auto; margin-right: auto; }
.container:after { content: " "; display: block; clear: both; }
@media only screen and (max-width: 1024px) { .container { margin-left: 15px; margin-right: 15px; width: auto; } }
.component-demo { position: relative; padding: 1px 0 0; background: #e6eaef; }
.component-demo:before { background-image: url("../img/enf.png"); }
@media only screen and (max-width: 480px) { .component-demo { padding: 40px 0 0; } }
.component-info .container { position: relative; }
.component-info .sidebar { width: 220px; float: left; margin-top: 75px; }
.component-info .sidebar .component-meta { margin-top: 10px; font-size: 1.125em; }
.component-info .sidebar .component-meta span { white-space: nowrap; margin-bottom: 10px; padding-left: 25px; color: #18324f; }
.component-info .sidebar.sticky { position: fixed; margin-top: 38px; }
.component-info .content { width: 64.58333333%; float: right; margin-top: 60px; margin-bottom: 75px; }
.component-info .content h3 { margin-bottom: .75em; font-size: 2.75em; }
.component-info .content p { margin-bottom: 1.75em; line-height: 1.45; }
@media only screen and (max-width: 480px) { .component-info .content .section-title { font-size: 2.1em; } }
@media only screen and (max-width: 768px) { .component-info .sidebar { float: none; margin-left: auto; margin-right: auto; }
.component-info .sidebar .component-meta { margin-top: 30px; text-align: center; }
.component-info .sidebar.sticky { position: relative; margin-top: 75px; }
.component-info .content { float: none; width: 100%; } }
@media only screen and (max-width: 480px) { .component-info .content { margin-bottom: 0; } }
.spy-nav { margin-bottom: 10px; }
.spy-nav ul { list-style: none; }
.spy-nav a { padding-top: 9px; padding-bottom: 10px; height: auto; border-bottom: 1px solid #4B8B20; text-align: left; text-transform: none; font-size: 1.375em; line-height: normal; }
.spy-nav .active a { border-bottom-color: #fff; background: #fff; color: #17324f; }
@media only screen and (max-width: 768px) { /*.spy-nav { display: none; } */}
.main-wrapper { margin: 44px auto 44px; max-width: 600px; }
.main-wrapper label { display: block; margin-bottom: .75em; color: #3f4e5e; font-size: 1.25em; }
.main-wrapper .text-field { padding: 0 15px; width: 100%; height: 40px; border: 1px solid #CBD3DD; font-size: 1.125em; }
.main-wrapper ::-webkit-input-placeholder { color: #CBD3DD; font-style: italic; font-size: 18px; }
.main-wrapper :-moz-placeholder { color: #CBD3DD; font-style: italic; font-size: 18px; }
.main-wrapper ::-moz-placeholder { color: #CBD3DD; font-style: italic; font-size: 18px; }
.main-wrapper :-ms-input-placeholder { color: #CBD3DD; font-style: italic; font-size: 18px; }
.page-icon-wrapper:before, .page-icon-wrapper .logo-asp:before, .page-icon-wrapper .logo-hibernate:before, .page-icon-wrapper .logo-angularjs:before, .page-icon-wrapper .logo-requirejs:before, .page-icon-wrapper .logo-reward:before, .component-demo:before {background-repeat: no-repeat; background-size: 100%; width: 92px; height: 108px; position: absolute; left: 50%; margin-left: -46px; top: 0; bottom: auto; margin-top: -28px; content: ''; }
.container { width: 60em; margin-left: auto; margin-right: auto; }
.container:after { content: " "; display: block; clear: both; }
@media only screen and (max-width: 1024px) { .container { margin-left: 15px; margin-right: 15px; width: auto; } }
.bcms-clearfix:after {content: ""; visibility: hidden; display: block; height: 0; clear: both; }

View File

@ -0,0 +1,97 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content">
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<div class="bcms-clearfix"></div>
<h3 class="section-title">Installation</h3>
<p>The suggested installation method is via <a href="https://getcomposer.org/" target="_blank">composer</a>.</p>
<pre><code class="sh">php composer.phar require ocramius/proxy-manager:1.0.*</code></pre>
<hr />
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

View File

@ -0,0 +1,314 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager - Ghost object</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, ghost object" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content">
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<div class="bcms-clearfix"></div>
<h3 class="section-title">Lazy Loading Ghost Object Proxies</h3>
<p>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.</p>
<hr />
<h3 class="section-title">Lazy loading with the Ghost Object</h3>
<p>In pseudo-code, in userland, <a href="http://www.martinfowler.com/eaaCatalog/lazyLoad.html" target="_blank">lazy loading</a> in a ghost object looks like following:</p>
<pre>
<code class="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;
}
}
}
</code>
</pre>
<p>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.</p>
<hr />
<h3 class="section-title">When do I use a ghost object?</h3>
<p>You usually need a ghost object in cases where following applies</p>
<ul>
<li>you are building a small data-mapper and want to lazily load data across associations in your object graph</li>
<li>you want to initialize objects representing rows in a large dataset</li>
<li>you want to compare instances of lazily initialized objects without the risk of comparing a proxy with a real subject</li>
<li>you are aware of the internal state of the object and are confident in working with its internals via reflection or direct property access</li>
</ul>
<hr />
<h3 class="section-title">Usage examples</h3>
<p><a href="https://github.com/Ocramius/ProxyManager" target="_blank">ProxyManager</a> provides a factory that creates lazy loading ghost objects. To use it, follow these steps:</p>
<p>First of all, define your object's logic without taking care of lazy loading:</p>
<pre>
<code class="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; }
}
</code>
</pre>
<p>Then use the proxy manager to create a ghost object of it. You will be responsible of setting its state during lazy loading:</p>
<pre>
<code class="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);
</code>
</pre>
<p>You can now simply use your object as before:</p>
<pre>
<code class="php">
// this will just work as before
echo $proxy->getName() . ' ' . $proxy->getSurname(); // Agent Smith
</code>
</pre>
<hr />
<h3 class="section-title">Lazy Initialization</h3>
<p>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:</p>
<pre>
<code class="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, &amp; $initializer) {};
</code>
</pre>
<p>The initializer closure should usually be coded like following:</p>
<pre>
<code class="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
};
</code>
</pre>
<p>The <code>ProxyManager\Factory\LazyLoadingGhostFactory</code> produces proxies that implement both the <code>ProxyManager\Proxy\GhostObjectInterface</code> and the <code>ProxyManager\Proxy\LazyLoadingInterface</code>.</p>
<p>At any point in time, you can set a new initializer for the proxy:</p>
<pre>
<code class="php">
$proxy->setProxyInitializer($initializer);
</code>
</pre>
<p>In your initializer, you <strong>MUST</strong> turn off any further initialization:</p>
<pre>
<code class="php">
$proxy->setProxyInitializer(null);
</code>
</pre>
<p>or</p>
<pre>
<code class="php">
$initializer = null; // if you use the initializer passed by reference to the closure
</code>
</pre>
<hr />
<h3 class="section-title">Triggering Initialization</h3>
<p>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:</p>
<pre>
<code class="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 = unserialize(serialize($proxy));
</code>
</pre>
<p>Remember to call <code>$proxy->setProxyInitializer(null);</code> to disable initialization of your proxy, or it will happen more than once.</p>
<hr />
<h3 class="section-title">Proxying interfaces</h3>
<p>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 <code>wrappedObject</code> implements more methods. This will anyway save some memory since the proxy won't contain any properties.</p>
<p>Tuning performance for production</p>
<p>See <a href="production.html">Tuning ProxyManager for Production.</a></p>
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -0,0 +1,295 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content"><div class="page-title-wrapper">
<div class="container">
<img src="https://github.com/Ocramius/ProxyManager/raw/master/proxy-manager.png">
<h2 class="page-title">Proxy Manager</h2>
</div>
</div>
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<h3>Proxy Manager</h3>
<p>This library aims at providing abstraction for generating various kinds of <a href="http://ocramius.github.io/presentations/proxy-pattern-in-php/" target="_blank">proxy classes</a>.</p>
<p>If you want to learn more about proxy pattern watch this video:</p>
<iframe width="640" height="390" src="//www.youtube.com/embed/Ka8wlV8M6Vg" frameborder="0" allowfullscreen></iframe>
<hr />
<div class="bcms-clearfix"></div>
<h3 class="section-title">Installation</h3>
<p>The suggested installation method is via <a href="https://getcomposer.org/" target="_blank">composer</a>.</p>
<pre><code class="sh">php composer.phar require ocramius/proxy-manager:1.0.*</code></pre>
<hr />
<h3 class="section-title" id="virtualproxy">Lazy Loading Value Holders (Virtual Proxy)</h3>
<p>ProxyManager can generate
<a href="http://www.martinfowler.com/eaaCatalog/lazyLoad.html" target="_blank">lazy loading value holders</a>,
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.</p>
<pre>
<code class="php">
$factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory();
$proxy = $factory->createProxy(
'MyApp\HeavyComplexObject',
function (&amp; $wrappedObject, $proxy, $method, $parameters, &amp; $initializer) {
$wrappedObject = new HeavyComplexObject(); // instantiation logic here
$initializer = null; // turning off further lazy initialization
return true;
}
);
$proxy->doFoo();
</code>
</pre>
<p>See the <a href="virtual-proxy.html">complete documentation about lazy loading value holders</a>.</p>
<hr />
<h3 class="section-title">Access Interceptor Value Holder</h3>
<p>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.</p>
<pre>
<code class="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"
</code>
</pre>
<p>See the <a href="access-interceptor-value-holder-proxy.html">complete documentation about access interceptor value holders</a>.</p>
<hr />
<h3 class="section-title">Access Interceptor Scope Localizer</h3>
<p>An access interceptor scope localizer works exactly like an access interceptor
value holder, but it is safe to use to proxy fluent interfaces.</p>
<p>See the <a href="access-interceptor-scope-localizer-proxy.html">complete documentation about access interceptor scope localizer</a>.</p>
<hr />
<h3 class="section-title">Null Objects</h3>
<p>A Null Object proxy implements the null object pattern.</p>
<p>This kind of proxy allows you to have fallback logic in case loading of the wrapped value failed.</p>
<pre>
<code class="php">
$factory = new \ProxyManager\Factory\NullObjectFactory();
$proxy = $factory->createProxy('My\EntityObject');
$proxy->getName(); // empty return
</code>
</pre>
<p>A Null Object Proxy can be created from an object, a class name or an interface name:</p>
<pre>
<code class="php">
$factory = new \ProxyManager\Factory\NullObjectFactory();
$proxy = $factory->createProxy('My\EntityObjectInterface');
$proxy->getName(); // empty return
$proxy = $factory->createProxy($entity); // created from object
$proxy->getName(); // empty return
</code>
</pre>
<p>See the <a href="null-object.html">complete documentation about null object proxy</a>.</p>
<hr />
<h3 class="section-title">Ghost Objects</h3>
<p>Similar to value holder, a ghost object is usually created to handle lazy loading.</p>
<p>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.</p>
<p>ProxyManager can generate
<a href="http://www.martinfowler.com/eaaCatalog/lazyLoad.html" target="_blank">lazy loading ghost objects</a>,
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.</p>
<p>Additionally, the overhead introduced by ghost objects is very low when
compared to the memory and performance overhead caused by virtual proxies.</p>
<pre>
<code class="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();
</code>
</pre>
<p>See the <a href="ghost-object.html">complete documentation about lazy loading ghost objects</a>.</p>
<hr />
<h3 class="section-title">Remote Object</h3>
<p>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.</p>
<p>This example uses the XML-RPC client of Zend Framework 2:</p>
<pre>
<code class="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());
</code>
</pre>
<p>See the <a href="remote-object.html">complete documentation about remote objects</a>.</p>
<hr />
<h3 class="section-title">Contributing</h3>
<p>Please read the <a href="contributing.html">CONTRIBUTING</a> contents if you wish to help out!</p>
<hr />
<h3 class="section-title">Credits</h3>
<p>The idea was originated by a <a href="http://marco-pivetta.com/proxy-pattern-in-php/" target="_blank">talk about Proxies in PHP OOP</a> that I gave at the <a href="https://twitter.com/phpugffm" target="_blank">@phpugffm</a> in January 2013.</p>
<div class="bcms-clearfix"></div>
</div>
</div>
</div>
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

View File

@ -0,0 +1,185 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager - Null object</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, null object" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content">
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<div class="bcms-clearfix"></div>
<h3 class="section-title">Null Object Proxy</h3>
<p>A Null Object proxy is a <a href="http://en.wikipedia.org/wiki/Null_Object_pattern" target="_blank">null object pattern</a> implementation. The proxy factory creates a new object with defined neutral behavior based on an other object, class name or interface.</p>
<hr />
<h3 class="section-title">What is null object proxy ?</h3>
<p>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 wouldnt do anything, therefore offloading client code from doing repetitive checks for ugly null values when the operation is executed.</p>
<hr />
<h3 class="section-title">Usage examples</h3>
<pre>
<code class="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;
}
}
</code>
</pre>
<p>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 :</p>
<pre>
<code class="php">
$factory = new \ProxyManager\Factory\NullObjectFactory();
$nullUser = $factory->createProxy('Entity\User');
var_dump($nullUser->getName()); // empty return
</code>
</pre>
<p>You can now return a valid entity :</p>
<pre>
<code class="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;
}
}
</code>
</pre>
<hr />
<h3 class="section-title">Proxying interfaces</h3>
<p>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.</p>
<p>Tuning performance for production</p>
<p>See <a href="production.html">Tuning ProxyManager for Production.</a></p>
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

View File

@ -0,0 +1,114 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager - Tuning the ProxyManager for production</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, production" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content">
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<div class="bcms-clearfix"></div>
<h3 class="section-title">Tuning the ProxyManager for production</h3>
<p>By default, all proxy factories generate the required proxy classes at runtime.</p>
<p>Proxy generation causes I/O operations and uses a lot of reflection, so be sure to have generated all of your proxies <strong>before deploying your code on a live system</strong>, or you may experience poor performance.</p>
<p>You can configure ProxyManager so that it will try autoloading the proxies first. Generating them "bulk" is not yet implemented:</p>
<pre>
<code class="php">
$config = new \ProxyManager\Configuration();
$config->setProxiesTargetDir(__DIR__ . '/my/generated/classes/cache/dir');
// then register the autoloader
spl_autoload_register($config->getProxyAutoloader());
</code>
</pre>
<p>Generating a classmap with all your proxy classes in it will also work perfectly.</p>
<p>Please note that all the currently implemented <code>ProxyManager\Factory\*</code> classes accept a <code>ProxyManager\Configuration</code> object as optional constructor parameter. This allows for fine-tuning of ProxyManager according to your needs.</p>
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

View File

@ -0,0 +1,203 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager - Remote object</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, remote object" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content">
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<div class="bcms-clearfix"></div>
<h3 class="section-title">Remote Object Proxy</h3>
<p>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.</p>
<hr />
<h3 class="section-title">What is remote object proxy ?</h3>
<p>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.</p>
<hr />
<h3 class="section-title">Adapters</h3>
<p>ZendFramework's RPC components (XmlRpc, JsonRpc &amp; Soap) can be used easily with the remote object. You will need to require the one you need via composer, though:</p>
<pre>
<code class="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.*
</code>
</pre>
<p>ProxyManager comes with 3 adapters:</p>
<ul>
<li><code>ProxyManager\Factory\RemoteObject\Adapter\XmlRpc</code></li>
<li><code>ProxyManager\Factory\RemoteObject\Adapter\JsonRpc</code></li>
<li><code>ProxyManager\Factory\RemoteObject\Adapter\Soap</code></li>
</ul>
<hr />
<h3 class="section-title">Usage examples</h3>
<p>RPC server side code (<code>xmlrpc.php</code> in your local webroot):</p>
<pre>
<code class="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();
</code>
</pre>
<p>Client side code (proxy) :</p>
<pre>
<code class="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"
</code>
</pre>
<hr />
<h3 class="section-title">Implementing custom adapters</h3>
<p>Your adapters must implement <code>ProxyManager\Factory\RemoteObject\AdapterInterface</code> :</p>
<pre>
<code class="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());
}
</code>
</pre>
<p>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</p>
<p>Tuning performance for production</p>
<p>See <a href="production.html">Tuning ProxyManager for Production.</a></p>
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

View File

@ -0,0 +1,305 @@
<!DOCTYPE html>
<html class="no-js" id="top">
<head>
<title>ProxyManager - Virtual Proxy</title>
<meta name="description" content="A proxyManager write in php" />
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, virtual proxy" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
<nav class="main-nav" role="navigation">
<ul>
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
<div class="bcms-clearfix"></div>
</li>
</ul>
</nav>
</div>
</header>
<main role="main">
<section class="component-content">
<div class="component-demo" id="live-demo">
<div class="container">
<div class="main-wrapper" style="text-align: right">
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
</div>
<div class="bcms-clearfix bcms-clearfix"></div>
</div>
</div>
<div class="component-info">
<div class="container">
<aside class="sidebar">
<nav class="spy-nav">
<ul>
<li><a href="index.html">Intro</a></li>
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
<li><a href="null-object.html">Null Objects</a></li>
<li><a href="ghost-object.html">Ghost Objects</a></li>
<li><a href="remote-object.html">Remote Object</a></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="credits.html">Credits</a></li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</nav>
<div class="bcms-clearfix bcms-clearfix"></div>
<a class="btn btn-action btn-full download-component"
href="download.html">Download</a>
<div class="bcms-clearfix"></div>
</aside>
<div class="content">
<div class="bcms-clearfix"></div>
<h3 class="section-title">Lazy Loading Value Holder Proxy</h3>
<p>A lazy loading value holder proxy is a virtual proxy that wraps and lazily initializes a "real" instance of the proxied class.</p>
<hr />
<h3 class="section-title">What is lazy loading?</h3>
<p>In pseudo-code, in userland, <a href="http://www.martinfowler.com/eaaCatalog/lazyLoad.html" target="_blank">lazy loading</a> looks like following:</p>
<pre>
<code class="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();
}
}
}
</code>
</pre>
<p>This code is problematic, and adds a lot of complexity that makes your unit tests' code even worse.</p>
<p>Also, this kind of usage often ends up in coupling your code with a particular <a href="http://martinfowler.com/articles/injection.html" target="_blank">Dependency Injection Container</a> 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 <a href="http://ocramius.github.io/blog/zf2-and-symfony-service-proxies-with-doctrine-proxies/" target="_blank">in this article</a>.</p>
<p>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.</p>
<hr />
<h3 class="section-title">When do I use a lazy value holder?</h3>
<p>You usually need a lazy value holder in cases where following applies</p>
<ul>
<li>your object takes a lot of time and memory to be initialized (with all dependencies)</li>
<li>your object is not always used, and the instantiation overhead can be avoided</li>
</ul>
<hr />
<h3 class="section-title">Usage examples</h3>
<p>ProxyManager provides a factory that eases instantiation of lazy loading value holders. To use it, follow these steps:</p>
<p>First of all, define your object's logic without taking care of lazy loading:</p>
<pre>
<code class="php">
namespace MyApp;
class HeavyComplexObject
{
public function __construct()
{
// just write your business logic
// don't worry about how heavy initialization of this will be!
}
public function doFoo() {
echo "OK!"
}
}
</code>
</pre>
<p>Then use the proxy manager to create a lazy version of the object (as a proxy):</p>
<pre>
<code class="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);
</code>
</pre>
<p>You can now simply use your object as before:</p>
<pre>
<code class="php">
// this will just work as before
$proxy->doFoo(); // OK!
</code>
</pre>
<hr />
<h3 class="section-title">Lazy Initialization</h3>
<p>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:</p>
<pre>
<code class="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) {};
</code>
</pre>
<p>The initializer closure should usually be coded like following:</p>
<pre>
<code class="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
};
</code>
</pre>
<p>The <code>ProxyManager\Factory\LazyLoadingValueHolderFactory</code> produces proxies that implement both the <code>ProxyManager\Proxy\ValueHolderInterface</code> and the <code>ProxyManager\Proxy\LazyLoadingInterface</code>.</p>
<p>At any point in time, you can set a new initializer for the proxy:</p>
<pre><code class="php">$proxy->setProxyInitializer($initializer);</code></pre>
<p>In your initializer, you currently <strong>MUST</strong> turn off any further initialization:</p>
<pre><code class="php">$proxy->setProxyInitializer(null);</code></pre>
<p>or</p>
<pre><code class="php">$initializer = null; // if you use the initializer by reference</code></pre>
<hr />
<h3 class="section-title">Triggering Initialization</h3>
<p>A lazy loading proxy is initialized whenever you access any property or method of it. Any of the following interactions would trigger lazy initialization:</p>
<pre>
<code class="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));
</code>
</pre>
<p>Remember to call <code>$proxy->setProxyInitializer(null);</code> to disable initialization of your proxy, or it will happen more than once.</p>
<hr />
<h3 class="section-title">Proxying interfaces</h3>
<p>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.</p>
<p>Tuning performance for production</p>
<p>See <a href="production.html">Tuning ProxyManager for Production.</a></p>
</main>
<footer class="site-footer" role="contentinfo">
<div class="container">
<div class="footer-logos">
<ul>
<li><a href="index.html">Intro</a> | </li>
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
<li><a href="null-object.html">Null Objects</a> | </li>
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
<li><a href="remote-object.html">Remote Object</a> | </li>
<li><a href="contributing.html">Contributing</a> | </li>
<li><a href="credits.html">Credits</a> | </li>
<li><a href="copyright.html">Copyright</a></li>
</ul>
</div>
</div>
<div class="bcms-clearfix"></div>
</footer>
<div class="bcms-clearfix"></div>
</body>
</html>

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0;URL=html-docs/">
<title></title>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdox xmlns="http://phpdox.de/config" silent="false">
<project
name="ProxyManager"
source="src"
workdir="build/phpdox"
>
<collector publiconly="false">
<include mask="*.php" />
</collector>
<generator output="build">
<build engine="html" enabled="true" output="api"/>
</generator>
</project>
</phpdox>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ruleset
name="ProxyManager rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
>
<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/unusedcode.xml"/>
<rule ref="rulesets/design.xml">
<!-- eval is needed to generate runtime classes -->
<exclude name="EvalExpression"/>
</rule>
<rule ref="rulesets/naming.xml"/>
</ruleset>

View File

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<phpunit
bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false"
syntaxCheck="true"
>
<testsuite name="ProxyManager tests">
<directory>./tests/ProxyManagerTest</directory>
</testsuite>
<testsuite name="ProxyManager language integration tests">
<directory suffix=".phpt">./tests/language-feature-scripts</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -0,0 +1,346 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
and is licensed under the MIT license.
-->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="378.25879"
height="241.71141"
id="svg9092"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="logo_DEF.svg">
<title
id="title5929">Logo - Ocramius Proxy Manager</title>
<defs
id="defs9094">
<linearGradient
id="linearGradient3798">
<stop
id="stop3800"
offset="0"
style="stop-color:#545454;stop-opacity:0;" />
<stop
id="stop3802"
offset="1"
style="stop-color:#585858;stop-opacity:1;" />
</linearGradient>
<linearGradient
id="linearGradient3788">
<stop
style="stop-color:#585858;stop-opacity:1;"
offset="0"
id="stop3790" />
<stop
style="stop-color:#585858;stop-opacity:0;"
offset="1"
id="stop3792" />
</linearGradient>
<marker
inkscape:stockid="DotL"
orient="auto"
refY="0"
refX="0"
id="DotL"
style="overflow:visible">
<path
id="path3987"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt"
transform="matrix(0.8,0,0,0.8,5.92,0.8)"
inkscape:connector-curvature="0" />
</marker>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath3920">
<path
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m -21.125,46.0625 c -1.315071,0 -2.375,1.059929 -2.375,2.375 l 0,262.09375 c 0,1.31507 1.059929,2.375 2.375,2.375 l 292.15625,0 c 1.31507,0 2.375,-1.05993 2.375,-2.375 l 0,-262.09375 c 0,-1.315071 -1.05993,-2.375 -2.375,-2.375 l -292.15625,0 z m 111.28125,68.34375 68.625,0 33.9375,58.75 -33.9375,60.15625 -68.625,0 L 55.8125,173.875 90.15625,114.40625 z"
id="path3922"
inkscape:connector-curvature="0" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath3924">
<path
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m -21.125,46.0625 c -1.315071,0 -2.375,1.059929 -2.375,2.375 l 0,262.09375 c 0,1.31507 1.059929,2.375 2.375,2.375 l 292.15625,0 c 1.31507,0 2.375,-1.05993 2.375,-2.375 l 0,-262.09375 c 0,-1.315071 -1.05993,-2.375 -2.375,-2.375 l -292.15625,0 z m 111.28125,68.34375 68.625,0 33.9375,58.75 -33.9375,60.15625 -68.625,0 L 55.8125,173.875 90.15625,114.40625 z"
id="path3926"
inkscape:connector-curvature="0" />
</clipPath>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.53214715"
inkscape:cx="-234.17911"
inkscape:cy="-96.916153"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:snap-bbox="true"
inkscape:bbox-nodes="true"
inkscape:bbox-paths="true"
inkscape:snap-bbox-edge-midpoints="true"
inkscape:snap-bbox-midpoints="true"
inkscape:object-paths="true"
inkscape:object-nodes="true"
inkscape:snap-smooth-nodes="true"
inkscape:snap-midpoints="true"
inkscape:snap-intersection-paths="true"
inkscape:snap-object-midpoints="true"
inkscape:snap-center="true"
inkscape:window-width="1366"
inkscape:window-height="746"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:snap-global="true"
showguides="true"
inkscape:guide-bbox="true"
inkscape:snap-page="false"
inkscape:snap-grids="false"
inkscape:snap-to-guides="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0" />
<metadata
id="metadata9097">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>Logo - Ocramius Proxy Manager</dc:title>
<dc:date>November 2013</dc:date>
<dc:creator>
<cc:Agent>
<dc:title>Maestro Pivetta</dc:title>
</cc:Agent>
</dc:creator>
<dc:rights>
<cc:Agent>
<dc:title>MIT</dc:title>
</cc:Agent>
</dc:rights>
<dc:publisher>
<cc:Agent>
<dc:title>Marco Pivetta</dc:title>
</cc:Agent>
</dc:publisher>
<dc:coverage>Logo</dc:coverage>
<dc:subject>
<rdf:Bag />
</dc:subject>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:groupmode="layer"
id="layer4"
inkscape:label="Layer"
transform="translate(-18.781538,-53.01103)" />
<g
inkscape:groupmode="layer"
id="layer3"
inkscape:label="low"
style="display:inline"
transform="translate(-18.781538,-53.01103)">
<path
style="fill:none;stroke:#787878;stroke-width:14.46100044;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 222.81682,230.67946 -98.45761,-56.81264 0,0 -98.347172,56.81265"
id="path3882"
inkscape:connector-curvature="0"
clip-path="url(#clipPath3924)" />
<path
style="fill:none;stroke:#787878;stroke-width:14.46100044;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 124.35921,173.86682 0.0552,-113.62529"
id="path3785"
inkscape:connector-curvature="0"
clip-path="url(#clipPath3920)" />
</g>
<g
inkscape:label="base"
inkscape:groupmode="layer"
id="layer1"
style="display:inline"
transform="translate(-18.781538,-53.01103)">
<path
style="fill:#1a1a1a;fill-opacity:1;stroke:#1e1e1e;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:0;stroke-dasharray:none"
d="m 193.11566,173.86682 59.40231,0"
id="path12544"
inkscape:connector-curvature="0" />
<path
sodipodi:type="star"
style="fill:none;stroke:#787878;stroke-width:35;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="path9100"
sodipodi:sides="6"
sodipodi:cx="225.71429"
sodipodi:cy="372.36218"
sodipodi:r1="275.01392"
sodipodi:r2="238.16904"
sodipodi:arg1="-0.52359878"
sodipodi:arg2="0"
inkscape:flatsided="true"
inkscape:rounded="0"
inkscape:randomized="0"
d="m 463.88333,234.85522 0,275.01392 L 225.7143,647.3761 -12.454743,509.86914 -12.454744,234.85523 225.71429,97.348267 z"
transform="matrix(0.41316197,0,0,0.41316197,31.157864,20.020928)"
clip-path="none" />
<path
inkscape:connector-curvature="0"
id="path12548"
d="m 154.2419,173.86682 59.40231,0"
style="fill:#1a1a1a;fill-opacity:1;stroke:#1e1e1e;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:0;stroke-dasharray:none" />
<g
id="g5895">
<path
id="path9626"
sodipodi:type="star"
style="fill:none;stroke:#de8c33;stroke-width:57.93455887;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:40"
sodipodi:sides="6"
sodipodi:cx="225.71429"
sodipodi:cy="372.36218"
sodipodi:r1="275.01392"
sodipodi:r2="238.16904"
sodipodi:arg1="-0.52359878"
sodipodi:arg2="0"
inkscape:flatsided="true"
inkscape:rounded="0"
inkscape:randomized="0"
d="m 463.88333,234.85522 0,275.01392 L 225.7143,647.3761 -12.454743,509.86914 -12.454744,234.85523 225.71429,97.348267 z"
transform="matrix(0.21616793,0.12480461,-0.12480461,0.21616793,122.14997,65.203872)" />
<g
style="stroke:#de8c33;stroke-width:4.13199997;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="g3786">
<path
inkscape:connector-curvature="0"
style="fill:none;stroke:#de8c33;stroke-width:4.13199997;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:78.84750349"
d="M 158.79266,233.31601 124.46965,173.86682"
id="path9636" />
<path
style="fill:none;stroke:#de8c33;stroke-width:4.13199997;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:78.84750349"
d="m 124.35921,173.86682 34.43344,-59.44919"
id="path3884"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#de8c33;stroke-width:4.13199997;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:78.84750349"
d="m 55.823635,173.86682 68.701185,0.0956"
id="path3886"
inkscape:connector-curvature="0" />
</g>
</g>
<g
id="g5920"
style="fill:#3c3c3c;fill-opacity:1;stroke:#3c3c3c;stroke-width:8;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none">
<path
d="m 163.10781,173.47926 c 0,2.16916 -1.75845,3.92761 -3.9276,3.92761 -2.16916,0 -3.92761,-1.75845 -3.92761,-3.92761 0,-2.16915 1.75845,-3.9276 3.92761,-3.9276 2.16915,0 3.9276,1.75845 3.9276,3.9276 z"
sodipodi:ry="3.9276054"
sodipodi:rx="3.9276054"
sodipodi:cy="173.47926"
sodipodi:cx="159.18021"
id="path5902"
style="fill:#3c3c3c;fill-opacity:1;stroke:#3c3c3c;stroke-width:8;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
sodipodi:type="arc" />
<path
transform="translate(21.523427,0.38755669)"
sodipodi:type="arc"
style="fill:#3c3c3c;fill-opacity:1;stroke:#3c3c3c;stroke-width:8;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path5904"
sodipodi:cx="159.18021"
sodipodi:cy="173.47926"
sodipodi:rx="3.9276054"
sodipodi:ry="3.9276054"
d="m 163.10781,173.47926 c 0,2.16916 -1.75845,3.92761 -3.9276,3.92761 -2.16916,0 -3.92761,-1.75845 -3.92761,-3.92761 0,-2.16915 1.75845,-3.9276 3.92761,-3.9276 2.16915,0 3.9276,1.75845 3.9276,3.9276 z" />
<path
d="m 163.10781,173.47926 c 0,2.16916 -1.75845,3.92761 -3.9276,3.92761 -2.16916,0 -3.92761,-1.75845 -3.92761,-3.92761 0,-2.16915 1.75845,-3.9276 3.92761,-3.9276 2.16915,0 3.9276,1.75845 3.9276,3.9276 z"
sodipodi:ry="3.9276054"
sodipodi:rx="3.9276054"
sodipodi:cy="173.47926"
sodipodi:cx="159.18021"
id="path5906"
style="fill:#3c3c3c;fill-opacity:1;stroke:#3c3c3c;stroke-width:8;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
sodipodi:type="arc"
transform="translate(43.326071,0.38755669)" />
<path
transform="translate(64.819008,1.9726929e-6)"
sodipodi:type="arc"
style="fill:#3c3c3c;fill-opacity:1;stroke:#3c3c3c;stroke-width:8;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path5908"
sodipodi:cx="159.18021"
sodipodi:cy="173.47926"
sodipodi:rx="3.9276054"
sodipodi:ry="3.9276054"
d="m 163.10781,173.47926 c 0,2.16916 -1.75845,3.92761 -3.9276,3.92761 -2.16916,0 -3.92761,-1.75845 -3.92761,-3.92761 0,-2.16915 1.75845,-3.9276 3.92761,-3.9276 2.16915,0 3.9276,1.75845 3.9276,3.9276 z" />
<path
d="m 163.10781,173.47926 c 0,2.16916 -1.75845,3.92761 -3.9276,3.92761 -2.16916,0 -3.92761,-1.75845 -3.92761,-3.92761 0,-2.16915 1.75845,-3.9276 3.92761,-3.9276 2.16915,0 3.9276,1.75845 3.9276,3.9276 z"
sodipodi:ry="3.9276054"
sodipodi:rx="3.9276054"
sodipodi:cy="173.47926"
sodipodi:cx="159.18021"
id="path5910"
style="fill:#3c3c3c;fill-opacity:1;stroke:#3c3c3c;stroke-width:8;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
sodipodi:type="arc"
transform="translate(86.425344,1.9726929e-6)" />
</g>
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="ext cube"
style="display:inline"
transform="translate(-18.781538,-53.01103)">
<g
id="g5891"
style="stroke:#3c3c3c;stroke-opacity:1">
<path
transform="matrix(0.21616793,0.12480461,-0.12480461,0.21616793,318.8443,65.203877)"
d="m 463.88333,234.85522 0,275.01392 L 225.7143,647.3761 -12.454743,509.86914 -12.454744,234.85523 225.71429,97.348267 z"
inkscape:randomized="0"
inkscape:rounded="0"
inkscape:flatsided="true"
sodipodi:arg2="0"
sodipodi:arg1="-0.52359878"
sodipodi:r2="238.16904"
sodipodi:r1="275.01392"
sodipodi:cy="372.36218"
sodipodi:cx="225.71429"
sodipodi:sides="6"
id="path9660"
style="fill:none;stroke:#3c3c3c;stroke-width:57.93323135;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
sodipodi:type="star" />
<path
id="path9662"
style="fill:none;stroke:#3c3c3c;stroke-width:4.13161993;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 252.51797,173.86682 68.64601,0 34.323,-59.44919 m 10e-6,118.89838 -34.32301,-59.44919"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,69 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Autoloader;
use ProxyManager\FileLocator\FileLocatorInterface;
use ProxyManager\Inflector\ClassNameInflectorInterface;
/**
* {@inheritDoc}
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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;
}
}

View File

@ -0,0 +1,37 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Autoloader;
/**
* Basic autoloader utilities required to work with proxy files
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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);
}

View File

@ -0,0 +1,241 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager;
use ProxyManager\Autoloader\Autoloader;
use ProxyManager\Autoloader\AutoloaderInterface;
use ProxyManager\FileLocator\FileLocator;
use ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy;
use ProxyManager\GeneratorStrategy\GeneratorStrategyInterface;
use ProxyManager\Inflector\ClassNameInflector;
use ProxyManager\Inflector\ClassNameInflectorInterface;
use ProxyManager\Signature\ClassSignatureGenerator;
use ProxyManager\Signature\ClassSignatureGeneratorInterface;
use ProxyManager\Signature\SignatureChecker;
use ProxyManager\Signature\SignatureCheckerInterface;
use ProxyManager\Signature\SignatureGenerator;
use ProxyManager\Signature\SignatureGeneratorInterface;
/**
* Base configuration class for the proxy manager - serves as micro disposable DIC/facade
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
class Configuration
{
const DEFAULT_PROXY_NAMESPACE = 'ProxyManagerGeneratedProxy';
/**
* @var string|null
*/
protected $proxiesTargetDir;
/**
* @var string
*/
protected $proxiesNamespace = self::DEFAULT_PROXY_NAMESPACE;
/**
* @var GeneratorStrategyInterface|null
*/
protected $generatorStrategy;
/**
* @var callable|null
*/
protected $proxyAutoloader;
/**
* @var ClassNameInflectorInterface|null
*/
protected $classNameInflector;
/**
* @var SignatureGeneratorInterface|null
*/
protected $signatureGenerator;
/**
* @var SignatureCheckerInterface|null
*/
protected $signatureChecker;
/**
* @var ClassSignatureGeneratorInterface|null
*/
protected $classSignatureGenerator;
/**
* @deprecated deprecated since version 0.5
* @codeCoverageIgnore
*/
public function setAutoGenerateProxies()
{
}
/**
* @return bool
*
* @deprecated deprecated since version 0.5
* @codeCoverageIgnore
*/
public function doesAutoGenerateProxies()
{
return true;
}
/**
* @param AutoloaderInterface $proxyAutoloader
*/
public function setProxyAutoloader(AutoloaderInterface $proxyAutoloader)
{
$this->proxyAutoloader = $proxyAutoloader;
}
/**
* @return AutoloaderInterface
*/
public function getProxyAutoloader()
{
return $this->proxyAutoloader
?: $this->proxyAutoloader = new Autoloader(
new FileLocator($this->getProxiesTargetDir()),
$this->getClassNameInflector()
);
}
/**
* @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 string
*/
public function getProxiesTargetDir()
{
return $this->proxiesTargetDir ?: $this->proxiesTargetDir = sys_get_temp_dir();
}
/**
* @param GeneratorStrategyInterface $generatorStrategy
*/
public function setGeneratorStrategy(GeneratorStrategyInterface $generatorStrategy)
{
$this->generatorStrategy = $generatorStrategy;
}
/**
* @return GeneratorStrategyInterface
*/
public function getGeneratorStrategy()
{
return $this->generatorStrategy
?: $this->generatorStrategy = new FileWriterGeneratorStrategy(
new FileLocator($this->getProxiesTargetDir())
);
}
/**
* @param ClassNameInflectorInterface $classNameInflector
*/
public function setClassNameInflector(ClassNameInflectorInterface $classNameInflector)
{
$this->classNameInflector = $classNameInflector;
}
/**
* @return ClassNameInflectorInterface
*/
public function getClassNameInflector()
{
return $this->classNameInflector
?: $this->classNameInflector = new ClassNameInflector($this->getProxiesNamespace());
}
/**
* @param SignatureGeneratorInterface $signatureGenerator
*/
public function setSignatureGenerator(SignatureGeneratorInterface $signatureGenerator)
{
$this->signatureGenerator = $signatureGenerator;
}
/**
* @return SignatureGeneratorInterface
*/
public function getSignatureGenerator()
{
return $this->signatureGenerator ?: $this->signatureGenerator = new SignatureGenerator();
}
/**
* @param SignatureCheckerInterface $signatureChecker
*/
public function setSignatureChecker(SignatureCheckerInterface $signatureChecker)
{
$this->signatureChecker = $signatureChecker;
}
/**
* @return SignatureCheckerInterface
*/
public function getSignatureChecker()
{
return $this->signatureChecker
?: $this->signatureChecker = new SignatureChecker($this->getSignatureGenerator());
}
/**
* @param ClassSignatureGeneratorInterface $classSignatureGenerator
*/
public function setClassSignatureGenerator(ClassSignatureGeneratorInterface $classSignatureGenerator)
{
$this->classSignatureGenerator = $classSignatureGenerator;
}
/**
* @return ClassSignatureGeneratorInterface
*/
public function getClassSignatureGenerator()
{
return $this->classSignatureGenerator
?: new ClassSignatureGenerator($this->getSignatureGenerator());
}
}

View File

@ -0,0 +1,42 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Exception;
use BadMethodCallException;
/**
* Exception for forcefully disabled methods
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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));
}
}

View File

@ -0,0 +1,29 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Exception;
/**
* Base exception class for the proxy manager
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface ExceptionInterface
{
}

View File

@ -0,0 +1,69 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Exception;
use InvalidArgumentException;
use ReflectionClass;
use ReflectionMethod;
use UnexpectedValueException;
/**
* Exception for non writable files
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
class FileNotWritableException extends UnexpectedValueException implements ExceptionInterface
{
/**
* @param string $fromPath
* @param string $toPath
*
* @return self
*/
public static function fromInvalidMoveOperation($fromPath, $toPath)
{
return new self(sprintf(
'Could not move file "%s" to location "%s": '
. 'either the source file is not readable, or the destination is not writable',
$fromPath,
$toPath
));
}
/**
* @param string $path
*
* @return self
*/
public static function fromNonWritableLocation($path)
{
$messages = array();
if (($destination = realpath($path)) && ! is_file($destination)) {
$messages[] = 'exists and is not a file';
}
if (! is_writable($destination)) {
$messages[] = 'is not writable';
}
return new self(sprintf('Could not write to path "%s": %s', $path, implode(', ', $messages)));
}
}

View File

@ -0,0 +1,79 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Exception;
use InvalidArgumentException;
use ReflectionClass;
use ReflectionMethod;
/**
* Exception for invalid proxied classes
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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()));
}
/**
* @param ReflectionClass $reflection
*
* @return self
*/
public static function finalClassNotSupported(ReflectionClass $reflection)
{
return new self(sprintf('Provided class "%s" is final and cannot be proxied', $reflection->getName()));
}
/**
* @param ReflectionClass $reflection
*
* @return self
*/
public static function abstractProtectedMethodsNotSupported(ReflectionClass $reflection)
{
return new self(sprintf(
'Provided class "%s" has following protected abstract methods, and therefore cannot be proxied:' . "\n%s",
$reflection->getName(),
implode(
"\n",
array_map(
function (ReflectionMethod $reflectionMethod) {
return $reflectionMethod->getDeclaringClass()->getName() . '::' . $reflectionMethod->getName();
},
array_filter(
$reflection->getMethods(),
function (ReflectionMethod $method) {
return $method->isAbstract() && $method->isProtected();
}
)
)
)
));
}
}

View File

@ -0,0 +1,40 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Exception;
use InvalidArgumentException;
/**
* Exception for invalid directories
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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));
}
}

View File

@ -0,0 +1,47 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Exception;
use LogicException;
use ReflectionProperty;
/**
* Exception for invalid proxied classes
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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()
)
);
}
}

View File

@ -0,0 +1,112 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory;
use ProxyManager\Configuration;
use ProxyManager\Generator\ClassGenerator;
use ProxyManager\Version;
use ReflectionClass;
/**
* Base factory common logic
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
abstract class AbstractBaseFactory
{
/**
* @var \ProxyManager\Configuration
*/
protected $configuration;
/**
* Cached checked class names
*
* @var string[]
*/
private $checkedClasses = array();
/**
* @param \ProxyManager\Configuration $configuration
*/
public function __construct(Configuration $configuration = null)
{
$this->configuration = $configuration ?: new Configuration();
}
/**
* Generate a proxy from a class name
* @param string $className
* @return string proxy class name
*/
protected function generateProxy($className)
{
if (isset($this->checkedClasses[$className])) {
return $this->checkedClasses[$className];
}
$proxyParameters = array(
'className' => $className,
'factory' => get_class($this),
'proxyManagerVersion' => Version::VERSION
);
$proxyClassName = $this
->configuration
->getClassNameInflector()
->getProxyClassName($className, $proxyParameters);
if (! class_exists($proxyClassName)) {
$this->generateProxyClass($proxyClassName, $className, $proxyParameters);
}
$this
->configuration
->getSignatureChecker()
->checkSignature(new ReflectionClass($proxyClassName), $proxyParameters);
return $this->checkedClasses[$className] = $proxyClassName;
}
/**
* @return \ProxyManager\ProxyGenerator\ProxyGeneratorInterface
*/
abstract protected function getGenerator();
/**
* Generates the provided `$proxyClassName` from the given `$className` and `$proxyParameters`
* @param string $proxyClassName
* @param string $className
* @param array $proxyParameters
*
* @return void
*/
private function generateProxyClass($proxyClassName, $className, array $proxyParameters)
{
$className = $this->configuration->getClassNameInflector()->getUserClassName($className);
$phpClass = new ClassGenerator($proxyClassName);
$this->getGenerator()->generate(new ReflectionClass($className), $phpClass);
$phpClass = $this->configuration->getClassSignatureGenerator()->addSignature($phpClass, $proxyParameters);
$this->configuration->getGeneratorStrategy()->generate($phpClass);
$this->configuration->getProxyAutoloader()->__invoke($proxyClassName);
}
}

View File

@ -0,0 +1,46 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory;
use Closure;
/**
* Base factory common logic
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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);
}
}

View File

@ -0,0 +1,59 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory;
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator;
/**
* Factory responsible of producing proxy objects
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
class AccessInterceptorScopeLocalizerFactory extends AbstractBaseFactory
{
/**
* @var \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator|null
*/
private $generator;
/**
* @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();
}
}

View File

@ -0,0 +1,59 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory;
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator;
/**
* Factory responsible of producing proxy objects
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
class AccessInterceptorValueHolderFactory extends AbstractBaseFactory
{
/**
* @var \ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator|null
*/
private $generator;
/**
* @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())
{
$proxyClassName = $this->generateProxy(get_class($instance));
return new $proxyClassName($instance, $prefixInterceptors, $suffixInterceptors);
}
/**
* {@inheritDoc}
*/
protected function getGenerator()
{
return $this->generator ?: $this->generator = new AccessInterceptorValueHolderGenerator();
}
}

View File

@ -0,0 +1,45 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory;
use ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator;
/**
* Factory responsible of producing ghost instances
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*
* @method \ProxyManager\Proxy\GhostObjectInterface createProxy($className, \Closure $initializer)
*/
class LazyLoadingGhostFactory extends AbstractLazyFactory
{
/**
* @var \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator|null
*/
private $generator;
/**
* {@inheritDoc}
*/
protected function getGenerator()
{
return $this->generator ?: $this->generator = new LazyLoadingGhostGenerator();
}
}

View File

@ -0,0 +1,45 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory;
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
/**
* Factory responsible of producing virtual proxy instances
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*
* @method \ProxyManager\Proxy\VirtualProxyInterface createProxy($className, \Closure $initializer)
*/
class LazyLoadingValueHolderFactory extends AbstractLazyFactory
{
/**
* @var \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator|null
*/
private $generator;
/**
* {@inheritDoc}
*/
protected function getGenerator()
{
return $this->generator ?: $this->generator = new LazyLoadingValueHolderGenerator();
}
}

View File

@ -0,0 +1,56 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory;
use ProxyManager\ProxyGenerator\NullObjectGenerator;
/**
* Factory responsible of producing proxy objects
*
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
* @license MIT
*/
class NullObjectFactory extends AbstractBaseFactory
{
/**
* @var \ProxyManager\ProxyGenerator\NullObjectGenerator|null
*/
private $generator;
/**
* @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();
}
}

View File

@ -0,0 +1,81 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory\RemoteObject\Adapter;
use ProxyManager\Factory\RemoteObject\AdapterInterface;
use Zend\Server\Client;
/**
* Remote Object base adapter
*
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
* @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);
}

View File

@ -0,0 +1,36 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory\RemoteObject\Adapter;
/**
* Remote Object JSON RPC adapter
*
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
* @license MIT
*/
class JsonRpc extends BaseAdapter
{
/**
* {@inheritDoc}
*/
protected function getServiceName($wrappedClass, $method)
{
return $wrappedClass . '.' . $method;
}
}

View File

@ -0,0 +1,36 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory\RemoteObject\Adapter;
/**
* Remote Object SOAP adapter
*
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
* @license MIT
*/
class Soap extends BaseAdapter
{
/**
* {@inheritDoc}
*/
protected function getServiceName($wrappedClass, $method)
{
return (string) $method;
}
}

View File

@ -0,0 +1,36 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory\RemoteObject\Adapter;
/**
* Remote Object XML RPC adapter
*
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
* @license MIT
*/
class XmlRpc extends BaseAdapter
{
/**
* {@inheritDoc}
*/
protected function getServiceName($wrappedClass, $method)
{
return $wrappedClass . '.' . $method;
}
}

View File

@ -0,0 +1,37 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory\RemoteObject;
/**
* Remote Object adapter interface
*
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
* @license MIT
*/
interface AdapterInterface
{
/**
* Call remote object
*
* @param string $wrappedClass
* @param string $method
* @param array $params
*/
public function call($wrappedClass, $method, array $params = array());
}

View File

@ -0,0 +1,76 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Factory;
use ProxyManager\Configuration;
use ProxyManager\Factory\RemoteObject\AdapterInterface;
use ProxyManager\ProxyGenerator\RemoteObjectGenerator;
/**
* Factory responsible of producing remote proxy objects
*
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
* @license MIT
*/
class RemoteObjectFactory extends AbstractBaseFactory
{
/**
* @var AdapterInterface
*/
protected $adapter;
/**
* @var \ProxyManager\ProxyGenerator\RemoteObjectGenerator|null
*/
private $generator;
/**
* {@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();
}
}

View File

@ -0,0 +1,57 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\FileLocator;
use ProxyManager\Exception\InvalidProxyDirectoryException;
/**
* {@inheritDoc}
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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';
}
}

View File

@ -0,0 +1,37 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\FileLocator;
/**
* Basic autoloader utilities required to work with proxy files
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface FileLocatorInterface
{
/**
* Retrieves the file name for the given proxy
*
* @param string $className
*
* @return string
*/
public function getProxyFileName($className);
}

View File

@ -0,0 +1,54 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Generator;
use Zend\Code\Generator\ClassGenerator as ZendClassGenerator;
/**
* Class generator that ensures that interfaces/classes that are implemented/extended are FQCNs
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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);
}
}

View File

@ -0,0 +1,52 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Generator;
use ReflectionClass;
/**
* Method generator for magic methods
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
class MagicMethodGenerator extends MethodGenerator
{
/**
* @param ReflectionClass $originalClass
* @param string $name
* @param array $parameters
*/
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());
}
}
}

View File

@ -0,0 +1,161 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Generator;
use Zend\Code\Generator\DocBlockGenerator;
use Zend\Code\Generator\MethodGenerator as ZendMethodGenerator;
use Zend\Code\Reflection\MethodReflection;
/**
* Method generator that fixes minor quirks in ZF2's method generator
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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' : ''));
}
}

View File

@ -0,0 +1,149 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Generator;
use ReflectionException;
use Zend\Code\Generator\ParameterGenerator as ZendParameterGenerator;
use Zend\Code\Generator\ValueGenerator;
use Zend\Code\Reflection\ParameterReflection;
/**
* Parameter generator that ensures that the parameter type is a FQCN when it is a class
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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 = self::extractParameterType($reflectionParameter);
if (null !== $type) {
$param->setType($type);
}
self::setOptionalParameter($param, $reflectionParameter);
$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 '';
}
$defaultValue = $this->defaultValue instanceof ValueGenerator
? $this->defaultValue
: new ValueGenerator($this->defaultValue);
$defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE);
return ' = ' . $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, '\\') . ' ';
}
/**
* Set the default value for a parameter (if it is optional)
*
* @param ZendParameterGenerator $parameterGenerator
* @param ParameterReflection $reflectionParameter
*/
private static function setOptionalParameter(
ZendParameterGenerator $parameterGenerator,
ParameterReflection $reflectionParameter
) {
if ($reflectionParameter->isOptional()) {
try {
$parameterGenerator->setDefaultValue($reflectionParameter->getDefaultValue());
} catch (ReflectionException $e) {
$parameterGenerator->setDefaultValue(null);
}
}
}
}

View File

@ -0,0 +1,53 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Generator\Util;
use ReflectionClass;
use Zend\Code\Generator\ClassGenerator;
use Zend\Code\Generator\MethodGenerator;
/**
* Util class to help to generate code
*
* @author Jefersson Nathan <malukenho@phpse.net>
* @license MIT
*/
final class ClassGeneratorUtils
{
/**
* @param ReflectionClass $originalClass
* @param ClassGenerator $classGenerator
* @param MethodGenerator $generatedMethod
*
* @return void|false
*/
public static function addMethodIfNotFinal(
ReflectionClass $originalClass,
ClassGenerator $classGenerator,
MethodGenerator $generatedMethod
) {
$methodName = $generatedMethod->getName();
if ($originalClass->hasMethod($methodName) && $originalClass->getMethod($methodName)->isFinal()) {
return false;
}
$classGenerator->addMethodFromGenerator($generatedMethod);
}
}

View File

@ -0,0 +1,53 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Generator\Util;
/**
* Utility class capable of generating unique
* valid class/property/method identifiers
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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
)
);
}
}

View File

@ -0,0 +1,38 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\GeneratorStrategy;
use Zend\Code\Generator\ClassGenerator;
/**
* Generator strategy that generates the class body
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
class BaseGeneratorStrategy implements GeneratorStrategyInterface
{
/**
* {@inheritDoc}
*/
public function generate(ClassGenerator $classGenerator)
{
return $classGenerator->generate();
}
}

View File

@ -0,0 +1,69 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\GeneratorStrategy;
use Zend\Code\Generator\ClassGenerator;
/**
* Generator strategy that produces the code and evaluates it at runtime
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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, "<?php\n" . $code);
require $fileName;
unlink($fileName);
return $code;
// @codeCoverageIgnoreEnd
}
eval($code);
return $code;
}
}

View File

@ -0,0 +1,105 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\GeneratorStrategy;
use ProxyManager\Exception\FileNotWritableException;
use ProxyManager\FileLocator\FileLocatorInterface;
use Zend\Code\Generator\ClassGenerator;
/**
* Generator strategy that writes the generated classes to disk while generating them
*
* {@inheritDoc}
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
class FileWriterGeneratorStrategy implements GeneratorStrategyInterface
{
/**
* @var \ProxyManager\FileLocator\FileLocatorInterface
*/
protected $fileLocator;
/**
* @var callable
*/
private $emptyErrorHandler;
/**
* @param \ProxyManager\FileLocator\FileLocatorInterface $fileLocator
*/
public function __construct(FileLocatorInterface $fileLocator)
{
$this->fileLocator = $fileLocator;
$this->emptyErrorHandler = function () {
};
}
/**
* 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);
set_error_handler($this->emptyErrorHandler);
try {
$this->writeFile("<?php\n\n" . $generatedCode, $fileName);
} catch (FileNotWritableException $fileNotWritable) {
restore_error_handler();
throw $fileNotWritable;
}
restore_error_handler();
return $generatedCode;
}
/**
* Writes the source file in such a way that race conditions are avoided when the same file is written
* multiple times in a short time period
*
* @param string $source
* @param string $location
*
* @throws FileNotWritableException
*/
private function writeFile($source, $location)
{
$tmpFileName = $location . '.' . uniqid('', true);
if (! file_put_contents($tmpFileName, $source)) {
throw FileNotWritableException::fromNonWritableLocation($tmpFileName);
}
if (! rename($tmpFileName, $location)) {
unlink($tmpFileName);
throw FileNotWritableException::fromInvalidMoveOperation($tmpFileName, $location);
}
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\GeneratorStrategy;
use Zend\Code\Generator\ClassGenerator;
/**
* Generator strategy interface - defines basic behavior of class generators
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface GeneratorStrategyInterface
{
/**
* Generate the provided class
*
* @param ClassGenerator $classGenerator
*
* @return string the class body
*/
public function generate(ClassGenerator $classGenerator);
}

View File

@ -0,0 +1,98 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Inflector;
use ProxyManager\Inflector\Util\ParameterHasher;
/**
* {@inheritDoc}
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
final class ClassNameInflector implements ClassNameInflectorInterface
{
/**
* @var string
*/
protected $proxyNamespace;
/**
* @var int
*/
private $proxyMarkerLength;
/**
* @var string
*/
private $proxyMarker;
/**
* @var \ProxyManager\Inflector\Util\ParameterHasher
*/
private $parameterHasher;
/**
* @param string $proxyNamespace
*/
public function __construct($proxyNamespace)
{
$this->proxyNamespace = (string) $proxyNamespace;
$this->proxyMarker = '\\' . static::PROXY_MARKER . '\\';
$this->proxyMarkerLength = strlen($this->proxyMarker);
$this->parameterHasher = new ParameterHasher();
}
/**
* {@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)
. '\\Generated' . $this->parameterHasher->hashParameters($options);
}
/**
* {@inheritDoc}
*/
public function isProxyClassName($className)
{
return false !== strrpos($className, $this->proxyMarker);
}
}

View File

@ -0,0 +1,61 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Inflector;
/**
* Interface for a proxy- to user-class and user- to proxy-class name inflector
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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 string
*/
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);
}

View File

@ -0,0 +1,41 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Inflector\Util;
/**
* Encodes parameters into a class-name safe string
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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 base64_encode(serialize($parameters));
}
}

View File

@ -0,0 +1,40 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Inflector\Util;
/**
* Converts given parameters into a likely unique hash
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
class ParameterHasher
{
/**
* Converts the given parameters into a likely-unique hash
*
* @param array $parameters
*
* @return string
*/
public function hashParameters(array $parameters)
{
return md5(serialize($parameters));
}
}

View File

@ -0,0 +1,64 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Proxy;
/**
* Access interceptor object marker
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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:
*
* <code>
* $prefixInterceptor = function ($proxy, $instance, $method, $params, & $returnEarly) {};
* </code>
*
* @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:
*
* <code>
* $suffixInterceptor = function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) {};
* </code>
*
* @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);
}

View File

@ -0,0 +1,31 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Proxy\Exception;
use RuntimeException;
/**
* Remote object exception
*
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
* @license MIT
*/
class RemoteObjectException extends RuntimeException
{
}

View File

@ -0,0 +1,29 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Proxy;
/**
* Fallback value holder object marker
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface FallbackValueHolderInterface extends ProxyInterface
{
}

View File

@ -0,0 +1,29 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Proxy;
/**
* Ghost object marker
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface GhostObjectInterface extends LazyLoadingInterface
{
}

View File

@ -0,0 +1,64 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Proxy;
/**
* Lazy loading object identifier
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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:
*
* <code>
* $initializer = function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) {};
* </code>
*
* @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();
}

View File

@ -0,0 +1,29 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Proxy;
/**
* Null object marker
*
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
* @license MIT
*/
interface NullObjectInterface extends ProxyInterface
{
}

View File

@ -0,0 +1,29 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Proxy;
/**
* Base proxy marker
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface ProxyInterface
{
}

View File

@ -0,0 +1,29 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Proxy;
/**
* Remote object marker
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface RemoteObjectInterface extends ProxyInterface
{
}

View File

@ -0,0 +1,29 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Proxy;
/**
* Smart reference object marker
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface SmartReferenceInterface extends ProxyInterface
{
}

View File

@ -0,0 +1,33 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Proxy;
/**
* Value holder marker
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface ValueHolderInterface extends ProxyInterface
{
/**
* @return object|null the wrapped value
*/
public function getWrappedValueHolderValue();
}

View File

@ -0,0 +1,29 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\Proxy;
/**
* Virtual Proxy - a lazy initializing object wrapping around the proxied subject
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface VirtualProxyInterface extends LazyLoadingInterface, ValueHolderInterface
{
}

View File

@ -0,0 +1,50 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator;
use ProxyManager\Generator\MagicMethodGenerator;
use ReflectionClass;
use ReflectionProperty;
/**
* Magic `__wakeup` for lazy loading value holder objects
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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) . ");" : '');
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator;
use ProxyManager\Generator\MethodGenerator;
use ProxyManager\Generator\ParameterGenerator;
use Zend\Code\Generator\PropertyGenerator;
/**
* Implementation for {@see \ProxyManager\Proxy\AccessInterceptorInterface::setMethodPrefixInterceptor}
* for access interceptor objects
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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;');
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator;
use ProxyManager\Generator\MethodGenerator;
use ProxyManager\Generator\ParameterGenerator;
use Zend\Code\Generator\PropertyGenerator;
/**
* Implementation for {@see \ProxyManager\Proxy\AccessInterceptorInterface::setMethodSuffixInterceptor}
* for access interceptor objects
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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;');
}
}

View File

@ -0,0 +1,43 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator;
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
use Zend\Code\Generator\PropertyGenerator;
/**
* Property that contains the interceptor for operations to be executed before method execution
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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');
}
}

View File

@ -0,0 +1,43 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/
namespace ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator;
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
use Zend\Code\Generator\PropertyGenerator;
/**
* Property that contains the interceptor for operations to be executed after method execution
*
* @author Marco Pivetta <ocramius@gmail.com>
* @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');
}
}

Some files were not shown because too many files have changed in this diff Show More