Download the PHP package jesusslim/pinject without Composer

On this page you can find all versions of the php package jesusslim/pinject. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pinject

pinject

Inject in PHP !

usage

[English] Chinese

Install

pinject in packagist:https://packagist.org/packages/jesusslim/pinject

Install:

composer require jesusslim/pinject

If your composer not allowed dev-master,add this config

"minimum-stability": "dev"

into your composer.json.

Injector

The InjectorInterface decalare some function for Inject,like

map //map a concrete or class or object or closure to the inject container
get //get things your mapped
produce //produce concrete

The Injector class implements InjectorInterface.Make your own class which needs to use inject extends the Injector class.Then use the functions:

//map a data or object
$injector->mapData('test',12345);
$injector->mapData(Student::class,new Student('Slim'));

//map a class
$injector->mapSingleton(StudentInterface::class,GoodStudent::class);

//produce
//if the key is found in mapped data,objects,it will return the things we mapped.
//if the key is found in mapped classes,it will check if this class is been produced,if it's been produced,it return the concrete that produced before,else return a new concrete of this class.
//if this key not found in any map,it will try to reflect this class unless we use the function mustReg() to make sure all the things can be produced should be mapped first.
$injector->produce(StudentInterface::class);

//call an function
//it will fill the paramters of this function with the concrete produced by pinject.
$injector->call(function(Student $std){
    ...
});

//call an function in class
//it will call a function in class.it will try to find the class from pinject if it has been produced or reflect it.and fill the paramters with concrete produced by pinject.
$injector->callInClass($class_name,$action,$out_params);

Chains

We can use Chains to do some chaining operations.

Example:

$chains = new Chains($app);
//here $app is an Injector
$chains->chain(RequestHandler::class)
->chain(function($data,$next){
    $r = Auth::checkToken($data['token']);
    if($r !== true){
        dump("Token wrong");
    }else{
        $next($data);
    }
})
->chain(Student::class)
->chain(function($data){
    dump($data);
})
->action('handle')
->run();
//or use runWith($your_last_chain_func);

We can chain a Closure or a class into the chains.If it's a class,it will call the method named 'handle'.Every Closure or method for handle,should have two paramters:the data passing by in the chains,and the next handler.And at last of each chain,we shoule call the next handler if it's success.

Another way to use chains:

Another way to use chains is that use runWild instead of run/runWith,and it's more like the useage of Martini/Injector in golang.

Example:

$chains = new \Inject\Chains($app);
$app->mapData('any_param_here','Example');
$the_given_params_for_handlers = [
    'seems_wild' => 'OK'
];
$rtn = $chains->chain(function($any_param_here,$seems_wild){
    var_dump($any_param_here.' is '.$seems_wild);
})->chain(function(){
    return "END";
})->data($the_given_params_for_handlers)
->runWild();
var_dump($rtn);

As we see here,the difference between runWild and run/runWith is that,runWild support any kind of handlers,and any handler return anything will break the loop and return the result.


All versions of pinject with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jesusslim/pinject contains the following files

Loading the files please wait ....