Questions tagged [pimple]

Pimple is a small Dependency Injection Container for PHP 5.3 that consists of just one file and one class (about 50 lines of code).

Pimple is, according to its website, a small Dependency Injection Container for PHP 5.3 that consists of just one file and one class (about 50 lines of code).

Pimple is created by the same author of the Symfony framework.

46 questions
9
votes
1 answer

Passing static classes via Dependancy Injection

How is it possible to pass a static class to an object via Dependency Injection? For example Carbon uses static methods: $tomorrow = Carbon::now()->addDay(); I have services that depend on Carbon, and currently I'm using the library in the…
BugHunterUK
  • 8,346
  • 16
  • 65
  • 121
7
votes
3 answers

Pimple DI share deprecated. Now what?

In Pimple 1.0 I used to be able to share class instances like this: $app['some_service'] = $app->share(function () { return new Service(); }); This now seems to be deprecated and I am unable to find what is the new way of doing this.
Adam
  • 3,415
  • 4
  • 30
  • 49
6
votes
1 answer

Pimple source code: Why to store object id and object itself in different arrays?

Looking at the Pimple source code I found that it is storing objects and their ids in two different arrays: class Container implements \ArrayAccess { private $values = array(); ... private $keys = array(); } And then: public function…
Kanstantsin K.
  • 512
  • 4
  • 17
5
votes
2 answers

Modifying Pimple/Slim container

I would like to be able to modify an array on a Pimple container, however, because the services are frozen by Pimple this seems to be impossible. I have tried the extend() method on the container, however, due to my array not being an object I am…
James Kipling
  • 121
  • 10
5
votes
2 answers

PHPStorm Auto-complete Array Keys (dynamically inserted)

I'm using Pimple dependency injector, and every time I use a dependency from the container, I can't help but to double check the spelling of the key used to get the dependency: $ioc = new Pimple(); // 1. Define some object $ioc["some-key"] =…
4
votes
1 answer

PHP Dependency Injection Container With Factory

I'm working with silexphp/Pimple Dependency Injection Containers (DIC) and am unsure how to handle what would be a classic Factory pattern. Example: A parent class Animal.php has two child classes called DogAnimal.php and CatAnimal.php. The number…
webish
  • 701
  • 2
  • 9
  • 17
4
votes
1 answer

Silex service - $app parameter or "use ($app)" statement?

If I define a service in Silex application, I can either expect the main container (Application) to be passed as a parameter or can take it from the current scope using "use ($app)" statement. The official documentation at…
astax
  • 1,769
  • 1
  • 14
  • 23
4
votes
1 answer

Pimple and dynamic constructor injection

I have a question regarding Pimple and dynamic constructor injection. Say I have an MVC framework and I want to do something like image uploading. The semi-DI way of doing it would be like this: class ImageUploadController { public function…
AgmLauncher
  • 7,070
  • 8
  • 41
  • 67
3
votes
1 answer

Propery way to use Slim's dependency container

According to http://www.slimframework.com/docs/tutorial/first-app.html, the slim object is first created, and then the container is gotten and services are added to it. $app = new \Slim\App(["settings" => $config]); $container =…
user1032531
  • 24,767
  • 68
  • 217
  • 387
3
votes
4 answers

PhpStorm auto-complete support for unknown object properties managed by Pimple?

I have the following code in an application powered by Silex: $uknownObj->unkownRef $uknownObj being a dependency injection container. I know that unkownRef is of instance MyCoolObj. Now how can I tell IntelliJ / PhpStorm to actually help me with…
Toskan
  • 13,911
  • 14
  • 95
  • 185
3
votes
2 answers

Laravel IoC outside Laravel

I am using this repo as the basis for a new CLI PHP project using Eloquent as the ORM. When you create the new Eloquent capsule you have the option to setAsGlobal which makes the DB capsule accessible from anywhere in the code. Does that mean…
user101289
  • 9,888
  • 15
  • 81
  • 148
3
votes
2 answers

Pass parameters to Pimple->container->factory

So I basically want to do this: $this->container['Menu_builder'] = $this->container->factory(function ($c) { return new Menu_builder($parameter_1, $parameter_2); }); Where $parameter_1 and $parameter_2 are passed in from the call, like…
Donal.Lynch.Msc
  • 3,365
  • 12
  • 48
  • 78
3
votes
1 answer

Configure boostrap file for PHPUnit in Yii

If I'm using this YiiPimple for dependency injection, then how to configure bootstrap file for phpunit? Below given bootstrap file…
Vinu Sebastian
  • 568
  • 3
  • 16
3
votes
1 answer

understanding pimple php source code

Pimple is a simple dependency injection container in php used in silex framework. I was going through the source code here. In the documentation the function offsetGet returns the same instance of the class that is attached to the dependency…
Shikhar Subedi
  • 606
  • 1
  • 9
  • 26
3
votes
1 answer

Best practice for sharing 3rd party dependency in Silex application?

I am just starting a new Silex project. I am using the Cartalyst Sentry Authentication package and I wish to inject into my controller Service Controllers. Here is my attempt at using Silex's built in dependency container which extends Pimple. I…
Hines Bourne
  • 600
  • 1
  • 7
  • 20
1
2 3 4