PK ^GMdk phpdox.xml.distnu W+A
PK ^GMpu .travis.ymlnu W+A language: php
php:
- 5.3.3
- 5.3
- 5.4
- 5.5
matrix:
allow_failures:
- php: 5.3.3
before_script:
- composer self-update
- composer update --prefer-source
script:
- ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml
- time php -n ./vendor/bin/athletic -p ./tests/LazyMapPerformance/ -b ./tests/Bootstrap.php -f GroupedFormatter
- ./vendor/bin/phpcs --standard=PSR2 ./src/ ./tests/
after_script:
- php vendor/bin/coveralls -v
PK ^GM^IO) ) build/.gitignorenu W+A *
!logs
!.gitignore
!coverage-checker.phpPK ^GM1d\ \ README.mdnu W+A # Lazy Map
This small library aims at providing a very simple and efficient map of lazy-instantiating objects.
[![Build Status](https://travis-ci.org/Ocramius/LazyMap.png?branch=master)](https://travis-ci.org/Ocramius/LazyMap)
[![Coverage Status](https://coveralls.io/repos/Ocramius/LazyMap/badge.png?branch=master)](https://coveralls.io/r/Ocramius/LazyMap)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/Ocramius/LazyMap/badges/quality-score.png?s=7b727f09ad4fe0ff092312a85eec8999e2e3e120)](https://scrutinizer-ci.com/g/Ocramius/LazyMap/)
[![Total Downloads](https://poser.pugx.org/ocramius/lazy-map/downloads.png)](https://packagist.org/packages/ocramius/lazy-map)
[![Latest Stable Version](https://poser.pugx.org/ocramius/lazy-map/v/stable.png)](https://packagist.org/packages/ocramius/lazy-map)
[![Latest Unstable Version](https://poser.pugx.org/ocramius/lazy-map/v/unstable.png)](https://packagist.org/packages/ocramius/lazy-map)
[![Dependency Status](https://www.versioneye.com/php/ocramius:lazy-map/dev-master/badge.png)](https://www.versioneye.com/php/ocramius:lazy-map/dev-master)
## Installation
The suggested installation method is via [composer](https://getcomposer.org/):
```sh
php composer.phar require ocramius/lazy-map:1.0.*
```
## Usage
The current implementation is very simple and allows to define a map of "services" through a
`LazyMap\CallbackMap`:
```php
$map = new \LazyMap\CallbackLazyMap(function ($name) {
$object = new \stdClass();
$object->name = $name;
return $object;
});
var_dump($map->foo);
var_dump($map->bar);
var_dump($map->{'something special'});
```
## Purpose
The idea behind the library is to avoid un-efficient lazy-loading operations like following:
```php
private function getSomething($name)
{
if (isset($this->initialized[$name])) {
return $this->initialized[$name];
}
return $this->initialized[$name] = new Something($name);
}
```
This reduces overhead greatly when you'd otherwise call `getSomething()` thousands of times.
That's especially useful when mapping a lot of different services and iterating over them
over and over again.
PK ^GMFx1 1 CONTRIBUTING.mdnu W+A # 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/LazyMap.git
```
You will then need to run a composer installation:
```sh
$ cd LazyMap
$ 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.
PK ^GMSLD D
.gitignorenu W+A vendor
composer.lock
composer.phar
phpunit.xml
phpmd.xml
phpdox.xml
PK ^GM}= = $ examples/simple-instantiator-map.phpnu W+A name = $name;
return $object;
});
// the map instantiates objects lazily
var_dump($map->foo);
var_dump($map->bar);
var_dump($map->baz);
// same properties return the same object (shared instance)
var_dump($map->foo === $map->foo);
// different properties contain different instances
var_dump($map->foo === $map->bar);
var_dump($map->bar === $map->baz);
var_dump($map->baz === $map->foo);PK ^GMxau` ` src/LazyMap/AbstractLazyMap.phpnu W+A
*/
abstract class AbstractLazyMap
{
/**
* Magic PHP getter {@link http://www.php.net/manual/en/language.oop5.overloading.php#object.get}
*
* @param string $name
*
* @return mixed reference
*/
public function & __get($name)
{
$this->$name = $this->instantiate($name);
// assignment and return is not possible since PHP will segfault (bug report will come)
return $this->$name;
}
/**
* Instantiate a particular key by the given name
*
* @param string $name
*
* @return mixed
*/
abstract protected function instantiate($name);
}
PK ^GM}fm m src/LazyMap/CallbackLazyMap.phpnu W+A
*/
class CallbackLazyMap extends AbstractLazyMap
{
/**
* @param callable $callback
*/
public function __construct($callback)
{
$this->{__CLASS__ . "\0callback"} = $callback;
}
/**
* {@inheritDoc}
*/
protected function instantiate($name)
{
$callback = $this->{__CLASS__ . "\0callback"};
return $callback($name);
}
}
PK ^GMoV[ [ phpunit.xml.distnu W+A
./tests/LazyMapTest
./src
PK ^GM;{ &