Download the PHP package waponix/pocket without Composer

On this page you can find all versions of the php package waponix/pocket. 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 pocket

pocket (v2.2.0)

Is basically a service container.

Pocket is currently being developed in PHP 8, and will take advantage of it's new features as much as possible.

Installation

Introduction

Pocket considers all classes as service, you can pass any class name to pocket's get() method without doing any registration and it will try to load the object for you.

Note: you need to setup your own autoloading because pocket won't handle that for you, pocket also only works with PSR-4 autoloading

Example:

Pocket will also automatically load any arguments that are expected to be an instance of a class in the constructor.

Example:

In the example above, the argument $owner will be injected with an instance of class Person. In any case that class Person also has any argument that is excpected to be class instance, those will automatically be injected as well.

But what about other argument types?

For other arguments, pocket cannot automatically inject its values and will throw an exception, but this problem can be solved by using Attribute.

Using the Service Attribute

Pocket will try to load any object as long as it's arguments are loadable or are explicitly defined. Arguments that expects instance of a class are considered explicit because they can be autoloaded, but for other arguments like string, integer, etc. we will need to find a way how to define them, we will need to use the Service Attribute (Waponix\Pocket\Attribute\Service).

Attribute class is a new feature in PHP 8 which is a native way of adding Annotations in the code

Example:

Take note that to make this work we should make the key inside args: match the variable name in the constructor arguments ($name and $url), this way we are telling pocket where to exactly get the values for them.

It is also possible to override the value for an argument that expects a class instance, as long as it is a child of the expected class (e.g class John instance of class Person)

Parameters

The previous example shows how to define the argument value the directly in the code, but it is also possible to have a dataset of parameters and pocket will take the value from there.

First we need to set the parameters:

Then we can target these values in the Service Attribute:

In the new example we are replacing the values with a parameter id indicated by @, this will then tell pocket to get the values from the parameter based on the id

Notice that the id @post.method is equivalent to $parameters['post']['method']

Invoke Methods

Pocket also allows to invoke class methods and automatically injects dependencies.

Let's say you have a controller class that has method that represents an action:

you can invoke this method by doing the example below:

Factory

If somehow your requirement needs to use factories for creating objects, then you can do this by defining a factory in the Service Attribute of the target class.

Example:

and your factory class would look something like:

Service Group

Another helpful tool is the ability to group services, these can be achieved by defining a tag value in the Service Attribute.

Example:

Now John is will be grouped under the tag person and can be loadable by accessing the tag name #person:

Note: that the returned value will be an array or null if that tag is not used

You can also define multiple tags for a service by just passing an array of string into the tag argument:


All versions of pocket with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1.6
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 waponix/pocket contains the following files

Loading the files please wait ....