lib/DependencyInjector.php
public function injectIntoConstructor( $classToBuildName, array $toInject=[] ){
        $ref = new \ReflectionClass($classToBuildName);
        try{
            $constr = $ref->getConstructor();
        }catch( ReflectionException  $e ){
            return null;
        }

        $numToSkip = count($toInject);
        foreach ($constr->getParameters() as $p) {
            if( $numToSkip > 0 ){
                $numToSkip--;
                continue;
            }
            $classToInjectName = $p->getClass()->name;
            if( $classToInjectName === "Pimple\\Container" ){
                $toInject[] = $this->container;
            }else{
                $toInject[] = $this->container[ $classToInjectName ];
            }
        }
        return new $classToBuildName( ... $toInject );
    }
public function injectIntoConstructor( $classToBuildName, array $toInject=[] ){
        $ref = new \ReflectionClass($classToBuildName);
        try{
            $constr = $ref->getConstructor();
        }catch( ReflectionException  $e ){
            return null;
        }

        $numToSkip = count($toInject);
        foreach ($constr->getParameters() as $p) {
            if( $numToSkip > 0 ){
                $numToSkip--;
                continue;
            }
            $classToInjectName = $p->getClass()->name;
            if( $classToInjectName === "Pimple\\Container" ){
                $toInject[] = $this->container;
            }else{
                $toInject[] = $this->container[ $classToInjectName ];
            }
        }
        return new $classToBuildName( ... $toInject );
    }
public function injectIntoConstructor ( $ classToBuildName , array $ toInject = [ ] ) { $ ref = new \ ReflectionClass ( $ classToBuildName ) ; try { $ constr = $ ref -> getConstructor ( ) ; } catch ( ReflectionException $ e ) { return null ; } $ numToSkip = count ( $ toInject ) ; foreach ( $ constr -> getParameters ( ) as $ p ) { if ( $ numToSkip > 0 ) { $ numToSkip -- ; continue ; } $ classToInjectName = $ p -> getClass ( ) -> name ; if ( $ classToInjectName === "Pimple\\Container" ) { $ toInject [ ] = $ this -> container ; } else { $ toInject [ ] = $ this -> container [ $ classToInjectName ] ; } } return new $ classToBuildName ( ... $ toInject ) ; }
Inject dependencies from, or including, the Pimple container, into a a given class's constructor
Optionally providing a number of arguments to the constructor to prepend.

@param string $classToBuildName
@param array $toInject
@return bool Whether the method was found
Inject dependencies from or including the Pimple container into a a given class s constructor Optionally providing a number of arguments to the constructor to prepend .