Download the PHP package programmingarehard/resource-bundle without Composer

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

ResourceBundle

The ResourceBundle is an opinionated Symfony bundle to aid in developing REST APIs. It makes some architectural decisions for you, allowing you to focus more on the domain of your application. It uses as little magic as possible to make it easier to understand, debug, and extend.


Prerequisites

The ResourceBundle relies on the FOSRestBundle to handle content negotiation and RESTful decoding of request bodies. After installing the bundle, you must configure it before proceeding to use the ResourceBundle. Here is a sample configuration to get started.

Note: The ResourceBundle does not handle any sort of authentication. It is meant to be used in conjunction with something like the FOSOAuthServerBundle.

Bundle Usage

Resources

The ResourceBundle is centered around resources. The bundle requires resources(entities) to implement the very simple ResourceInterface. The examples assume you're using Doctrine but the bundle is ORM agnostic. First, let's create a simple resource.

Resource Repositories

Once we have a resource, it's time to create a repository for the resource by implementing the ResourceRepositoryInterface. If using Doctrine, just extend the bundled BaseResourceRepository.

Register it with the container.

Remember to update the mapping file.

Resource Managers

Just like Doctrine, persisting and deleting resources is not done by repositories. With the ResourceBundle, this is done through a ResourceManagerInterface implementation. If using Doctrine, you can use the bundled ResourceManager. Internally it uses Doctrine's ManagerRegistry to get the correct object manager for the resource.

Resource Forms

The bundle makes use of Symfony's form component to map incoming data to resources. Time to create a form for our Task.

By default, the bundle attempts to find a resource's form by looking for a form with the name of the resource's class that has been lowercased and underscored. Ie. The bundle would expect to find a form by the name of todo_list for a MyApp/CoreBundle/Entity/TodoList resource.

Let's register the form with the container.

Form Handlers

Now that we have a resource, repository, and form it's time to create an implementation of a FormHandlerInterface. Form handlers are only executed if a request was issued and the form was valid. The bundle comes with a SaveResourceFormHandler. It extracts the data(the resource from the form) and saves it through a ResourceManagerInterface. Let's register a resource form handler in the container.

Form Processors

We need to use our new handler in a form processor.

Form processors use a form handler if the form is valid and an error extractor for when it is invalid. If you do not like the default form error extractor, you can create your own by implementing the FormErrorExtractorInterface.

Resource Controllers

The glue that brings all these pieces together is the abstract ResourceController. Let's create a concrete TaskController.

Note: The $resourceClass is used by the ResourceController to find the relevant form, naming events, and serializing resources.

Tip: You might want to create your own base ResourceController and implement ::getFormProcessor() and ::getResourceManager() as they will probably be the same across each of your resource controllers.

Because the ResourceController uses symfony's security component to check basic REST permissions, we need to implement a security voter. You can customize this to suit your application's needs. For now, we're going to allow everything.

Don't forget to register it.

Resource Routing

Once we have our TaskController and our security voter set up, we can then RESTfully route to actions.

I highly recommend you take a peek at the ResourceController to see what's happening under the hood.

By default, the ResourceBundle uses Symfony's serializer component to serialize resources for responses. However, I recommend using the JMSSerializerBundle for more flexibility.

Events

The bundle's components are developed in a manner to make it easy to add functionality. One important piece of functionality is the ability to dispatch events. Events can be dispatched by wrapping certain components in decorators. The bundle comes with three.

Eventful Resource Manager

You can use this decorator to dispatch events during manager interactions.

By using this decorator, the following events will be dispatched:

It uses the ResourceEventDispatcher to dispatch these events. It uses the same class transformer as the ResourceController does when finding a resource's form. It lowercases and underscores a resource's class to use in the event name. Feel free to use the resource event dispatcher in your own code(like in your event listeners).

Eventful Form Handler

You can decorate your form handlers to dispatch pre and post handle events.

Using this decorator will dispatch the following events for the task's form handler:

Eventful Form Processor

You can also decorate form processors to dispatch certain events throughout the form processing.

Using this decorator will dispatch the following events for the tasks's form.

To summarize, by taking advantage of these decorators you will have access to the following events:

Don't forget to use them in your ResourceControllers though!

Bundle Configuration Reference

This is the default bundle configuration.

The class_tranformer is responsible for turning a resource's fully qualified class name into a name it uses when finding a resource's form and dispatching events. It must implement TransformerInterface.

The form_error_extractor is responsbile for getting errors from a form. It must implement FormErrorExtractorInterface

Special Notes

There are a few things to keep in mind when using this bundle.

IndexAction

You might have noticed that there is no indexAction in the ResourceController. This is because the bundle can't reasonably guess all of the required parameters needed to come up with a generic enough solution. For example, most likely you will only want to display the current user's resources rather than everything in a resource repository. You may also want advanced url structures, ie. /api/people/24/tasks. The indexAction method signature we need to accommodate that person id wildcard. Consequently, pagination and filtering are left up to you.

ResourceEvents::PRE_VIEW

This event is dispatched in the create, show, and update actions in the ResourceController. Depending on how you display related resources, you may want to ignore these events. You can use a serializer to display a resource's related resources. These resources would be fetched by calling getters on the resources themselves. Consequently, there is no place to dispatch the ResourceEvents::PRE_VIEW events for the related resources and still keep the bundle ORM agnostic. One option is to pull in the BazingaHateoasBundle and configure links for related resources. This way you can be sure that individual resources are only ever displayed directly by the ResourceController.


All versions of resource-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.2
symfony/framework-bundle Version ~2.1
symfony/form Version ~2.1
symfony/security-bundle Version ~2.1
friendsofsymfony/rest-bundle Version ~1.3
doctrine/inflector Version ~1.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 programmingarehard/resource-bundle contains the following files

Loading the files please wait ....