| Recommend this page to a friend! |
| Packages of Axel Pardemann | PHP Using Facades | docs/sections/usage.md | Download |
|
|||||||||||||||||||||
layout: default title: Usage nav_order: 2 permalink: /usageUsage{: .no_toc } Table of contents{: .no_toc .text-delta }
A Facade allows you to call object instance methods as if they were static. Underneath, the object creation will be handled by the facade (although you need to pass at least the required parameters to actually be able to build the object). Defining a FacadeTo create a facade for an object, your _base_ class should have a public constructor or implement the The method calls that the facade can proxy can be the object's own methods and also the registered extension methods for an The only requirement for the facade is that it should have the target object class defined.
Using a FacadeTo use an object's method through a facade, you call the method _statically_ on the facade, prepending the parameters for the object creation to the parameters required by the method. Expanding on the previous code snippets, one would use the facade as follows:
As you can see, the facade automatically handles the object creation using the first parameter ( Bypassing constructor optional parametersSometimes, for whatever reason, you want a facade to skip an object's constructor optional parameters when creating it and just use the provieded defaults. This can be achieved as follows:
This will tell the Facade to use just
The facade call will use the first parameter ( If we hadn't specify the |