Download the PHP package imanghafoori/laravel-decorator without Composer

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

:christmas_tree: Laravel Decorator

Decorator pattern in Laravel apps

Quality Score StyleCI Check Imports Latest Stable Version Code Coverage Total Downloads

Made with :heart: for smart clean coders

A try to port "decorator" feature from python language to laravel framework.

python-and-prey

:truck: Installation:

What is a "Decorator" :question:

A decorator is callable which wraps around the original decorated callable, in order to form a new callable composed of the previous two.

Like a python snake swallowing a deer whole and wraps around its body !

After that the snake becomes capable to eat and digest grasses :herb: because it has a deer inside it.

Technically, A "Decorator":

1- Is a "callable"

2- which takes another "callable" (as it's only argument, like a snake swallows another snake)

3- and returns a new "callable" (which internally calls the original callable, putting some code before and after it.)

What?!??! ???! (0_o)

What can be considered as a "callable" within laravel ?!

Long story short, anything that can be called (invoked) with App::call(); or call_user_func() like: 'MyClass@myMethod' or a closure, [UserRepo::class, 'find']

Cache Like a Pro:

Caching DB queries is always a need, but it is always annoying to add more code to the existing code. It will become more messy, we may break the current code, after all it adds a layer of fog. Yeah?

Imagine that you have a UserControllerwhich calls a UserRepo@find to get a $user .

Then after a while you decide to put a cache layer between those two classes for obvious reasons.

According to SOLID principles, you shouldn't put the caching code logic neither in your controller nor your UserRepo. But somewhere in between.

In other words, you want to add a new feature (caching in this case) without modifying the existing code.

It smells like Open-closed Principle Yeah?! 👃

You want to keep the responsibilities separate. In this case caching should not be in a repository or controller but in its own class.

It smells like Single Responsibility Principle yeah?! 👃

ok now there is no cache, going on. it is a direct call.

With the help of laravel-decorator built-in cache decorator, you can go to AppServiceProvider.php (or any other service provider):

You will get cached results from your calls, in your UserController without touching it! but remember to change:

Define Your Own Decorators:

Then you can use this name (myDecoratorName) to decorate methods.

How to decorate a method?

How to call a method with its decorators?

image

Decorate Facades:

Decorating Facade Methods

First you should extend the Imanghafoori\Decorator\DecoratableFacade class (instead of the laravel base Facade).

image

Now You Can Apply Decorators in your ServiceProvider's boot method:

image

Then if you call your facade as normal you get decorated results.

image

:warning: Warning:

With great power, comes great responsibilities.

Remember not to violate the Liskoves Substitution Principle when you decorate something.

For example a method call which returns int|null should not unexpectedly return a string after being decorated.

$result = app('decorate')->call(...

Since the users of the method should be ready for type of value they get back.

But if you return only int and your decorator causes the null value to be filtered out. that's ok.

:star: Your Stars Make Us Do More :star:

As always if you found this package useful, and you want to encourage us to maintain and work on it, Please press the star button to declare your willingness.

More packages from the author:

:gem: A minimal yet powerful package to give you opportunity to refactor your controllers.


:gem: A minimal yet powerful package to give a better structure and caching opportunity for your laravel apps.


:gem: It allows you log in with any password in local environment only.


:gem: Authorization and ACL is now very easy with hey-man package!



All versions of laravel-decorator with dependencies

PHP Build Version
Package Version
Requires php Version 7.4.*|8.0.*|8.1.*|8.2.*|8.3.*|8.4.*
illuminate/support Version ~5.5|6.*|7.*|8.*|9.*|10.*|^11.0|^12.0
illuminate/container Version ~5.5|6.*|7.*|8.*|9.*|10.*|^11.0|^12.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 imanghafoori/laravel-decorator contains the following files

Loading the files please wait ....