Download the PHP package baghayi/http-verb-extraction without Composer

On this page you can find all versions of the php package baghayi/http-verb-extraction. 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 http-verb-extraction

Http Verb Extraction

Introduction

In a nutshell, what this module does, is extracting each http verbs (as I call them), such as create (for posting on collection), delete, fetchAll, deleteList, ... to their own classes.

Well, It's been awhile I've been hacking around apigility and recently I chose to use it on a project we've started. The thing I don't like about it and which this module is kind of trying to address it is that in Resource classes we have lots of methods, each belongs to a http method (http verb) for either a collection or entity. Methods like create, delete, fetchAll, ... .

What it seems to me is like a controller with lots of actions in it. Which is in contrary to what I believe in, that is one action per controller. The issue as you might have already gussed by now arises here. That I'm not definitely going to invoke more than one action at a time. But the objects those methods depend on has to be passed to the respective class so that it can get to work whenever it has to.

To be clear, the issue I am facing is that, I have to pass lots of objects to the class so that some of them may be called by some of the methods in it. Which as it sounds it is violating Single Responsibility principle as well. That the respective class has may jobs to do.

To be fair, I need to mention that I've seen some people pass the class a mapper object which is one object only. But to me, it feels like delegating the problem to someone else, another object, and does not seem like getting rid of the problem at all.

By creating this module, I'am aiming for solving this issue.

Unfortunately I'm not completly familiar with apigility's internals so that I could not come up with a better solution. I mean there are some stuff that I do not like about this module and could be solved but it would need to change apigility as well which is not what I want for now. They may be solved in a better ways with apigility's current status, but I am not familiar with.

I will mention those issues but for now it's enought talking (writing). Lets see what we've got here.

Installation

First you need to either download this module manually, using git or by composer. It is recommended to use composer, but the choice is yours.

If your are using composer, it will download the module to vendor/ directory by default. If you are downloading manually, or cloning it using git, then you need to place it under vendor/ directory as composer does.

Then you need to add HttpVerbExtraction to your config/application.config.php file under 'modules' key.

Now you are ready to go.

Usage

In order to use this module, you need to take these steps:

For instance: if your API module name is DemoApi then its resource class location should be DemoApi\V1\Rest\Demo\DemoResource.php for rest resources. This class in apigility extends ZF\Rest\AbstractResourceListener by default. You need to change it to HttpVerbExtraction\Rest\AbstractResourceListener.

As you can see, in the module config file, you need to create an array with key of http-verb-extraction which contains another array.

The nested array's key has to be the Resources controller name, which could be found in the api module's config file of your resources.

In our example, our DemoApi's controller name should be something like this: DemoApi\\V1\\Rest\\Demo\\Controller for rest resources.

As you can see the nested array consists of elements such as create, delete, deleteList, ... for each http verb, and their values have to be the name of a service that was previously created.

You can also remove verbs that you do not use or need.

Traits

In this module, there are about 5 traits at your disposal. Which could be used in the classes that are created for http verbs.

All these traits have only one method in them, to do the one task that they are supposed to do.

But you do not necessarily need to use these traits. You can get the values provided by these traists, directly in your verbs classes.

Verb classes that implements HttpVerbExtraction\DispatchableInterface.php interface, will get ResourceEvent as argument in its dispatch method. All of the values provided by traits could be retrieved directly by the event passed in your class.

If you are not sure how to get the specified values as traits does, you can look up traits source code as they are pretty straightforward to understand.

Not to mention that, methods defined in the traits require event object to be passed to them so that they can do what they are supposed to do.

Services

Initializer

There is only one initializer for now and that is used in the Abstract class which resource classes extends, to provide HttpVerbExtraction\Rest\DispatchVerb object in it so that it can attach events such as create, fetch, ... to its dispatch method.

Issues

1- One thing that I think needs to be taken care of is ResourceClass and its factory class themselves. As they are not being delt with by developers any more, I think they could be moved or removed to be hidden from developers (Apigility users). They do not need to be presented to the developers.

They might have been a better way of solving this issue, but unfortunately I'm not aware of, at the moment.

2- http-verb-extraction array key that I have introduced could be merged with zf-rest key in the config file, but I did not want to introduce anything new in it by myself (as outsider, not member of apigility main developers). Even though it does the job, but could have a proper home.

Thank you :)


All versions of http-verb-extraction with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.23
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 baghayi/http-verb-extraction contains the following files

Loading the files please wait ...