Skip to content

Instantly share code, notes, and snippets.

@lsjroberts
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsjroberts/9067557 to your computer and use it in GitHub Desktop.
Save lsjroberts/9067557 to your computer and use it in GitHub Desktop.
Pimple Test
<?php
require "vendor/autoload.php";
$app = new Pimple;
$app['test'] = 'boo';
$app['foo.bar'] = function($app) {
return 'bar';
};
$app['foo.baz'] = $app->share(function() {
return 'baz';
});
$app['foo'] = $app->raw('foo.bar');
// Should output:
// string(3) "bar"
var_dump($app['foo']);
$app['qux'] = $app->share(function($app) {
return ['qux', $app['foo']];
});
// If you call 'qux' here it will instantiate the shared service here and so
// it will not use the extended 'foo' service.
// var_dump($app['qux']);
$app['foo'] = $app->share($app->extend('foo', function($foo, $app) {
return 'extended';
}));
// Should output:
// array(2) {
// [0] =>
// string(3) "qux"
// [1] =>
// string(8) "extended"
// }
var_dump($app['qux']);
{
"require": {
"pimple/pimple": "1.1.1"
}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "8e36d6ce6cb2f4ec25c994e60626e5c0",
"packages": [
{
"name": "pimple/pimple",
"version": "v1.1.1",
"source": {
"type": "git",
"url": "https://github.com/fabpot/Pimple.git",
"reference": "2019c145fe393923f3441b23f29bbdfaa5c58c4d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fabpot/Pimple/zipball/2019c145fe393923f3441b23f29bbdfaa5c58c4d",
"reference": "2019c145fe393923f3441b23f29bbdfaa5c58c4d",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-0": {
"Pimple": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
}
],
"description": "Pimple is a simple Dependency Injection Container for PHP 5.3",
"homepage": "http://pimple.sensiolabs.org",
"keywords": [
"container",
"dependency injection"
],
"time": "2013-11-22 08:30:29"
}
],
"packages-dev": [
],
"aliases": [
],
"minimum-stability": "stable",
"stability-flags": [
],
"platform": [
],
"platform-dev": [
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment