Download the PHP package michaeljennings/refinery without Composer

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

Refinery Latest Stable Version Build Status

This project aims to add a layer of abstraction between your backend data store and the front end code. If you make an edit to the way your data is stored this can often end up in you needing to make a lot of front end changes. This project helps by formatting your data in one place so that if your back end changes, it won't effect the rest of your website.

Example

Below is a basic example of how to use refinery.

Navigation

Installation

Run composer require michaeljennings/refinery.

Or add the package to your composer.json.

Usage

To create a new refinery simply extend the Michaeljennings\Refinery\Refinery.

The refinery has one abstract method which is setTemplate. The setTemplate method is passed the item being refined and then you just need to return it in the format you want.

To pass data to the refinery, create a new instance of the class and then use the refine method.

You can pass the refinery either a single item or a multidimensional item.

Example Usage

As an example if I had a product and I wanted to make sure that its price always had two decimal figures I could do the following.

Multidimensional Refining

When you are working with database data, particularly relational data, it's common that you won't just be refining the main entity, you may have parent and child data that also needs to be refined.

This is best displayed with an example. Below we have a product that has many variants, and belongs to a category.

This parent and child data will usually be refined in the same way in every area it is used within your application, therefore it makes sense to move it into it's own class so that it can be reused.

To do that we use attachments.

Below we have a product refinery, that has category and variant attachments.

These attachments will only be brought with the item when the bring method is called when refining.

When you attempt to bring attachments it will look for methods on the refinery class with the specified attachment name.

For example if we were to do the following:

There would need to be a method called category on our product refinery.

The refinery will then attempt to pass the category property from the product to the category refinery.

Attachments can also be multidimensional. For example below we are bringing a product with it's category, and then we are bringing the category's meta data.

This will look for the category attachment on the product refinery, and then a meta attachment on the category refinery.

Advanced Refining

Using External Data

When refining you may need to access data that is not part of the main object.

For example, below we want to get the correct currency symbol for the country the user is in, however the country cannot be accessed from the product.

To get around this we use the with method to pass through the current country to the product refinery.

Then in the setTemplate method in the refinery we can access the country as shown below.

Custom Attachments

Occasionally you may want to set attachments that don't actually exist in the original data.

For example below we have added a largeVariant attachment to our product refinery.

By passing a closure to the second argument of the attach method we can choose what data we want to send to the refinery. The closure will be passed the current item being refined, which in this case is the product.

Raw Attachments

Refining can also be performed without a preset class, for instance if you want to refine a multidimensional array to a single array.

Below we have added an attachment which gets all of the sizes for a product and returns it as an array.


All versions of refinery with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.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 michaeljennings/refinery contains the following files

Loading the files please wait ....