Download the PHP package headio/phalcon-service-layer without Composer

On this page you can find all versions of the php package headio/phalcon-service-layer. 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 phalcon-service-layer

Phalcon service layer

A simple repository service implementation for Phalcon 5 projects

Build Status Coverage Status

Introduction

This library provides a layered architecture promising easier unit and integration testing.

The service layer handles business logic, mediating between the application layer (controller or handler) and the domain, interacting with a single repository or multiple repositories. All repositories extend an abstract query repository, providing a collection-like interface, with well-defined query methods. Hence all queries are isolated in the repository layer.

Phalcon ORM implements the active record pattern, therefore the responsiblity of persistence remains with the active record, in contrast to the repository service pattern / data mapper (Doctrine), where repositories manage the entity lifecycle.

If you have been reading between the lines, you have probably gathered this is a hybrid solution offering: testability, reuseability and prevention of logic leaking into the application layer. The trade-off is you need to write, test and maintain some extra boiler-plate code.

Naturally, you can avoid this paradigm by integrating a data mapper (Doctrine, Atlas ORM etc.) with Phalcon. Nevertheless, for those enjoying the performance of Phalcon ORM, this library may be of interest.

Dependencies

Installation

Composer

Open a terminal window and run:

Usage

Assuming the following project structure, let's create the layers to handle removing a record from storage as a simple usage example.

Registering a service provider

Create a new Foo service dependency inside the service provider directory /src/Provider/.

Alternatively, create the dependency on a per-module basis.

Controller/Handler

Now the service is in place, the controller can interact with the service layer by injecting the service into the controller via the OnConstruct method.

Service layer

The service layer interacts with one repository (or multiple repositories) to process the business logic. In the example below, the service calls the delete method (implementation skipped for simplicity) to remove a model instance by primary key and return to the list view.

Repository

All repositories must extend the abstract query repository and implement one abstract method.

The Foo repository can implement additional interfaces, e.g. FooInterface, providing further concrete methods for the service layer.

The abstract query repository implements the following repository interface:

In addition, a relationship trait is provided to simplify handling model relationships.

Query caching

Query caching is handled utilizing Phalcon's event manager. To get started first include the CacheableTrait in your repository; the EventsAwareInterface is implemented inside the cacheable trait.

Then create a service provider for your service layer, or a repository if you want to omit the service layer and work with repositories directly. The example below utilizes Phalcon's service provider interface.

Cache event listener

The event listener provides two methods to handle caching, see below.

To trigger a cache event, see the following concrete examples from the cacheable trait.

Pagination

This library provides a cursor-based paginator adapter; see _stub directory inside the test directory for usage.

The model

All models must extend the abstract Model class, which implements the following model interface:

Validation

Validation can be implemented in the service layer or the model classes.

Testing

To see the tests, run:

License

Phalcon service layer is open-source and licensed under MIT License.


All versions of phalcon-service-layer with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.0 <8.0.99
ext-mbstring Version *
ext-phalcon Version >=5.1.4
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 headio/phalcon-service-layer contains the following files

Loading the files please wait ....