Download the PHP package aaronjan/housekeeper without Composer

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

Housekeeper

Latest Stable Version License

Housekeeper - Laravel

After nearly six months developing, testing and polishing, the first stable version of Housekeeper 2 is finally released!

Housekeeper aims to be the coolest, handiest Repository Pattern implementation, any useful suggestion and PR are welcomed.

Increasing unit test code coverage is a work in progress (lots of works), but there is a set of integration tests running locally that covered most code.

Introduction

Housekeeper is a flexable and powerful Repository Pattern implemention for Laravel. In addition to the basic Repository Pattern and elegant syntax, Housekeeper has features like Injection system, Auto-Booting Method that will let you creating endless possibilities. The goal of Housekeeper is free you from the redundant and boring DAL stuff, coding more intuitively.

Sections

Repository Pattern and Housekeeper

The Repository Pattern is a software design pattern. In a nutshell, it means to encapsulate your data interaction code as methods that belong to different classes (Base on data domain), we call this type of class as Repository. When your business logic layer needs to accessing data such as an article entry in the database, it should ask to the Article Repository instead of writing inline query that deal with database directly.

OK, but ... I already got Eloquent, why not just using that?

Of course you can! But there're people who's not a fan of the Active Record, it just doesn't feel right for them, for these people, the Repository Pattern makes more sense. Besides, you can write method that is more expressive on your repository class, like getActivatedUsers(), and you can write tests for them very easily.

More importantly, Housekeeper is a better version of Repository Pattern (In some ways), you could read more about it below.

Housekeeper loves Eloquent. Most query APIs are the same as the Eloquent's, so you can use them without the needing to learn anything, and the returns are like Eloquent's too.

Installation

Requirement

PHP >= 5.5 and Laravel >= 5.1

Install Via Composer

or add these to your composer.json file:

then execute console command:

After Composer finish running, add the HousekeeperServiceProvider to the providers in config/app.php:

Make a configuration file for Housekeeper could allow you to tweak things:

It's done! Now you can make a repository:

TL;DR

If you have outstanding insight, this section will tell you how to use Housekeeper in the simplest words.

Take a example:

That's it, take a look at the Abilities' code for more usages, Have fun!

Features

Extend-less & Flows

The Repository Pattern is usually used with the Decorator Pattern. For instance, you have a repository class to interacting with data source directly, later you decide to add cache logic on top of that, so instead of changing the repository class its self, you could create a new class that extending it, and the whole thing may looks like this:

The Repository class is the bottom layer, CachedRepository class is another layer that base on the former, so one layer just do one thing (SRP: Single Responsibility Principle).

That is a good approach. But Housekeeper wants to solving the problem with less code by using Flows.

Flows are three stages in every method execution, they're: Before, After and Reset. Every method in a Housekeeper Repository should be wrapped so it can go through these Flows. Here is an example:

Why there are two methods that had similar names? Well, the getByName method is basically a configuration and an API hint for the core method _getByName, it wrapped the core method by calling the simpleWrap with an Callable which is [$this, '_getByName'], It says what this method does is reading data (Action::READ), the whole reading logic is in the _getByName method.

You don't have to worry about method arguments, Housekeeper will takes care of that. In fact, you don't even need to write [$this, '_getByName'], since it's a convention in Housekeeper (An underscore before your method name):

Let's back to the cache logic topic. In Housekeeper, if you wrapped your method like above, than to adding cache process, all you need to do is writing a single line of code like this:

Now all your method returns will be cached automatically, just like that.

Is it cool?

Injection & Booting

Here a sequence diagram of method execution in Housekeeper (Core Flow is the actual method logic):

method execution in Housekeeper

Housekeeper allows you to inject logic (called Injection) into any Flow, in every Flow, the Injections that belong to the Flow will be executed. Injection is just like Middleware but with 3 types: Before, After and Reset (matching 3 different injectable Flows). Here is an example:

The handle method in Injection takes a Flow object, depends on what Flow you injected into, the methods of the Flow object could be different, for instance, Before Flow provides setReturnValue method, you could call it by pass a value to it, then Housekeeper will use this value as the return and skip the actual method.

You can inject Injection by using the these methods: injectIntoBefore, injectIntoAfter and injectIntoReset.

Here is flowchart of the Before Flow execution:

method execution in Housekeeper

Housekeeper also will calling every method in the Repository class that name start with boot (before calling the boot method) when Repository instance been creating, some of the out-of-the-box Abilities in Housekeeper are took advantage of this, like in Adjustable trait:

Wrapping layer

Let's assume someone wrote code like these:

In this example, the applyWheres method has been used twice, one is in the Controller, the other is in the Repository, could the first one affecting the _getArticlesByAuthorId method? No. It will only affecting the _getArticlesBySameAuthor method, and be more precisely, it's affecting this line:

Every wrapped method in Housekeeper has their own Scope, means they have their own Eloquent Model (Or Builder), thus they will not taking any affect to each other. If you calling applyWheres or ApplyOrderBy outside the repository, they would only affecting the first wrapped method you called.

Another Choice For Wrapping

Having two methods could be annoying, you can write an Anonymous Function, before the simpleWrap takes a Callable:

API


whereAre(array $wheres)

Add an array of where clauses to the query.

Arguments

Example


applyWheres(array $wheres)

Alias for the whereAre method.

Arguments


orderBy($column, $direction = 'asc')

Add an "order by" clause to the query.

Arguments

Example


applyOrderBy($column, $direction = 'asc')

Alias for the orderBy method.

Arguments


offset($value)

Set the "offset" value of the query.

Arguments

Example


limit($value)

Set the "limit" value of the query.

Arguments

Example


exists($id, $column = null)

Determine if the record exists using its primary key.

Arguments

Examples

You could use this method with custom query conditions too:


count($columns = '*')

Retrieve the "count" result of the query.

Arguments


find($id, $columns = array('*'))

Find a model by its primary key.

Arguments

Examples


findMany($ids, $columns = array('*'))

Find a collection of models by their primary key.

Arguments


update($id, array $attributes)

Update a record in the database.

Arguments

Examples


create(array $attributes)

Create a model with $attributes.

Arguments


delete($id)

Delete a record from the database by its primary key.

Arguments


first($columns = ['*'])

Execute the query and retrieve the first result.

Arguments


all($columns = ['*'])

Execute the query as a "select" statement.

Arguments


paginate($limit = null, $columns = ['*'], $pageName = 'page', $page = null)

Paginate the given query.

Arguments


getByField($field, $value = null, $columns = ['*'])

Retrieve models by a simple equality query.

Arguments


with($relations)

Set the relationships that should be eager loaded, like Eloquent.

Examples


Adjustable

For more complex queries, you could put them in a Criteria class that is more semantic and reuse them anywhere you want, for that, using the Adjustable ability.

Examples

Then in your controller:

API


applyCriteria(\Housekeeper\Abilities\Adjustable\Contracts\Criteria $criteria)

Apply this Criteria only once.

Arguments


rememberCriteria(\Housekeeper\Abilities\Adjustable\Contracts\Criteria $criteria)

Remember this Criteria, it will be applied when every wrapped method been called (Only the first one, iternal method calling will be ignored).

Arguments


forgetCriterias()

Remove all remembered Criterias (Not applied).


getCriterias()

Get all remembered Criterias.


Eloquently

This Abilitiy provides lots of Eloquent style query APIs that you are very familiar with.

API


where($column, $operator = null, $value = null, $boolean = 'and')


orWhere($column, $operator = null, $value = null)


has($relation, $operator = '>=', $count = 1, $boolean = 'and', \Closure $callback = null)


whereHas($relation, Closure $callback, $operator = '>=', $count = 1)


whereDoesntHave($relation, Closure $callback = null)


orWhereHas($relation, Closure $callback, $operator = '>=', $count = 1)


whereIn($column, $values, $boolean = 'and', $not = false)


whereNotIn($column, $values, $boolean = 'and')


orWhereNotIn($column, $values)


whereNull($column, $boolean = 'and', $not = false)


orWhereNull($column)


whereNotNull($column, $boolean = 'and')


orWhereNotNull($column)


CacheStatically

This Ability implemented a very simple cache system: Caching all method returns, and delete them all when creating/updating/deleting, you can clear cache manually too.

Once you use this Ability, everything is automatic. all(), find(), paginate() and others will go through the cache logic, if any cached return be found, then no database query will be executed. Different method has different cache key, even applying query will change the cache key.

This Ability may not be much practical in large project, but it shows the flexibility of Housekeeper, and other cache system is in the roadmap.

Examples

Wrapped methods has their own cache:

API


enableCache()

Enable cache system.


disableCache()

Disable cache system.


isCacheEnabled()

Indicate whether cache system is enabled or not.


clearCache()

Delete all caches of this repository.


Guardable

Housekeeper ignored Mass Assignment Protection by default, use this Ability if you need it.

Guardable disabled Mass Assignment Protection by default too, you have to turn it on manually.

Examples

API


guardUp()

Enable Mass Assignment Protection


guardDown()

Disable Mass Assignment Protection


isGuarded()

Whether or not the Mass Assignment Protection is enabled.


SoftDeletes

To utilize the SoftDeletes trait of the Eloquent, you should use this Ability in your repository.

API


startWithTrashed()

Include soft deletes.


startWithTrashedOnly()

Include soft deletes only.


forceDelete($id)

Hard delete a record by primary key.

Arguments


restore($id)

Restore a soft-deleted record by primary key.

Arguments


Console Commands

Create a new repository:

Create a new repsitory and a new model:

Create a new repository with some Abilities

Issue

If you have any question about Housekeeper, feel free to create an issue, I'll reply you ASAP.

Any useful pull request are welcomed too.

Lisence

Licensed under the APACHE LISENCE 2.0

Credits

Thanks to prettus/l5-repository for inspiring.

Thanks to sunkey for the awesome LOGOs!

Thanks to @DarKDinDoN, @Bruce Peng, @FelipeUmpierre, @rsdev000 for your contributions!

Thanks to Laravel for making our life easier!


All versions of housekeeper with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.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 aaronjan/housekeeper contains the following files

Loading the files please wait ....