Download the PHP package two-bros/repository-pattern without Composer

On this page you can find all versions of the php package two-bros/repository-pattern. 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 repository-pattern

Installation & Setup Build Status

Composer

You can install this package via Composer by running the command: composer require "two_bros/repository-pattern:~1.0".

Or by adding the package to your composer.json

Then install it via composer install or composer update

Basic Usage

The purpose of the repository pattern is to separate ORM choice from the application, so that you can switch out your data layer without the need for touching the majority of your application. This is a solid first step towards that goal, although there are still some things that need to be done to make this completely separated from the ORM. One of the things that need to be done is to not return any Eloquent specific objects from the repository.

You will need to have each of your repositories extend TwoBros\RepositoryPattern\Repositories\LaravelAbstractRepository.

This repository will provide the methods below to support your basic needs for most normal data needs. This means that each model should have a repository paired with it, so that you can keep the layer between your application and the actual data. As your data needs within a specific domain evolve, you would add that functionality to the domain specific repository that you created. Each repository should have its own interface created as well, to ensure that any domain specific functionality is built under contract. This will make sure that if you need to change ORMs, then you will know exactly what functionality you will need to replicate.

create( array $attributes )

Will create a model from an array of attributes, and return the created model.

update( integer $id, array $attributes )

Will update a model using an id to locate and with an array of attributes, and return the updated model. 

destroy( integer $id )

Will destroy a model using an id to locate the model, and will return a 1 for the count of successfully deleted 
models.

all( array $columns = ['*'] )

Will return an Eloquent collection object with the columns requested, or all columns by default.

getById( integer $id, array $columns = ['*'], array $with = [] )

Will return a model with the columns requested and adding any relations requested. All columns are returned by default,
and no relations.

getByPage( integer $page = 1, integer $limit = 10, array $with = [] )

Will return a StdClass object that can be used in a Laravel Pagination object. It takes the page number, per page 
limit, and an array of relations that you want to include. The page defaults to 1 with 10 items per page, and no 
added relations. The return object will have an items array that includes an Eloquent collection object, and a 
totalItems property that will contain the count of total items in the database.

getFirstBy( string $key, string $value, array $with = [] )

Will return the first model from the database that contains the value for the selected column, and including any 
relations you decide to load. 

getManyBy( string $key, string $value, array $with = [] )

Will return an Eloquent collection object from the database that contains the value for the selected column, and including any 
relations you decide to load. 

has( string $relation, array $with = [] )

Will return an Eloquent collection object that has a specific relationship, and loading the array of relations provided.

make( array $with = [] )

Will return a model object with the array of relations loaded. This is more of an intermediary to an actual data return, 
and is used by any of the other methods that include loaded relations.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


All versions of repository-pattern with dependencies

PHP Build Version
Package Version
No informations.
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 two-bros/repository-pattern contains the following files

Loading the files please wait ...