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
2
votes
2 answers

Pimple ArgumentCountError: Too few arguments to function

I'm trying to understand dependency injection, and I in theory, I get it, but, I wanted to make an example just to help me. However, I'm getting the following error PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function…
Kearney Taaffe
  • 647
  • 8
  • 20
2
votes
3 answers

PHP How to prevent pimple DIC causing infinite loop on a circular dependency

In this example I have classA and classB that I am using with pimple container. They both have a dependency on each other. However when setting this up with pimple DIC, the below code causes an infinite loop... There must be a way of doing this in…
jon
  • 1,429
  • 1
  • 23
  • 40
2
votes
1 answer

Interface conflicts with PHP Pimple

I have a custom class that extends Pimple\Container. The idea was to wrap the, to my eyes, ugly methods for accessing defined services (see below): offsetGet($key) -> get($key) offsetSet($key, $val) -> set($key, $val) offsetExists($key) ->…
scruffycoder86
  • 527
  • 1
  • 5
  • 24
2
votes
1 answer

How to use Pimple C Extension

I have the Pimple C extension installed and in my phpinfo() i can see that the Pimple extension is active. I also have pimple/pimple in my composer.json and the php package is loaded. As far as i see they dont collide as i dont get any errors,…
ivoba
  • 5,780
  • 5
  • 48
  • 55
1
vote
2 answers

Passing out of scope data to a service container

I wish to create a new instance of SomeService which must be injected with some data which is not known when defining the service in Pimple. The following technically works, but surely cannot be the proper way to do so. How should this be…
user1032531
  • 24,767
  • 68
  • 217
  • 387
1
vote
0 answers

Injecting in the constructor when using pimple

Background. I am using Slim where an ID is either in the endpoint or parameters. Based on the ID, a factory creates the appropriate object to perform the needed action. I have a service which needs some data obtained in the request injected into…
user1032531
  • 24,767
  • 68
  • 217
  • 387
1
vote
1 answer

How do I best use an object factory inside another class using Pimple for Dependency Injection?

I am still trying to wrap my head around some of the aspects of the Dependency Injection design pattern using Pimple. I completely get the concept of using a constructor or setter function belonging to class Foo to establish it's dependency on class…
Fliggerty
  • 73
  • 7
1
vote
0 answers

Use Pimple as DI Container and mock with phpunit?

I'm crawling the web since a lot of time but I can't find any answer to my question. I started a new project, and I use Pimple to maanage DI. Of course I want to unit test my classes and I need a Mock for one. THe problem is that with classic DI…
1
vote
1 answer

Why would Pimple factory method return same instance?

I am using the factory method of Pimple, but it's returning same instance every time. $container = new \Pimple\Container(); echo '
';

$container['test'] = $container->factory(function( $c ) {
  $services = new \Pimple\Container();

  return…
Dave Stein
  • 8,653
  • 13
  • 56
  • 104
1
vote
2 answers

Class 'Pimple\Container' not found

I am trying to install Pimple in my project following https://github.com/silexphp/Pimple readme file. Error message I receive is: Fatal error: Class 'Pimple\Container' not found in E:\www\public\index.php on line 9 My composer.json file is: { …
Gregory
  • 43
  • 1
  • 5
1
vote
1 answer

Define dependencies for framework controllers with Pimple

So I have a controller which I have added its dependencies with Pimple like this: $this->container['Account'] = $this->container->factory(function ($c) { return new Account( $c['Menu_builder'] ); }); And when I go to the URL of any…
Donal.Lynch.Msc
  • 3,365
  • 12
  • 48
  • 78
1
vote
2 answers

How to integrate pimple in a custom mvc framework?

I have a basic mvc like framework, and I would like to use pimple for dependance injection, but I don't know how to use it inside the framework. This is my app structure. x-framework - config - app controller homeController.php …
1
vote
1 answer

PHP Lazy loading with Pimple Dependency Injection Container?

Recently I have started using Pimple (together with Silex). Depending on how Pimple is used it can either be a Service Locator or a Dependency Injection Container. I am aware of the reasons why a Service Locator pattern should be avoided.…
dadasign
  • 408
  • 4
  • 7
1
vote
3 answers

Assigning users to a proper league based on performance

I'm getting hung up on the logic needed in php to assign my users to a "league" based on their performance. Basically, once a month I will have a cron job run which will fetch a list of my users and their data averaged like so SELECT user_id,…
1
vote
1 answer

PHP pimple cross dependency

I have two classes which depending on each other: class A { public function __construct(B $b) { $this->b = $b; } } class B { public function __construct(A $a) { $this->a = $a; } } And I need to wrap them…