decodelabs / veneer
Automated static facades
Installs: 30 273
Dependents: 29
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- decodelabs/exceptional: ^0.4
- decodelabs/glitch-support: ^0.4
- psr/container: ^2
Requires (Dev)
- composer-runtime-api: ^2.2
- decodelabs/pandora: ^0.2.11
- decodelabs/phpstan-decodelabs: ^0.6
- decodelabs/slingshot: ^0.1.1
Suggests
- decodelabs/slingshot: Complex plugin instantiation support
- dev-develop / 0.11.x-dev
- v0.11.6
- v0.11.5
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.25
- v0.10.24
- v0.10.23
- v0.10.22
- v0.10.21
- v0.10.20
- v0.10.19
- v0.10.18
- v0.10.17
- v0.10.16
- v0.10.15
- v0.10.14
- v0.10.13
- v0.10.12
- v0.10.11
- v0.10.10
- v0.10.9
- v0.10.8
- v0.10.7
- v0.10.6
- v0.10.5
- v0.10.4
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.4
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.0
- dev-main
This package is auto-updated.
Last update: 2024-12-04 22:26:53 UTC
README
Create automated static frontages for your PHP objects.
Use Veneer to provide easy access to your most commonly used functionality without sacrificing testability.
Get news and updates on the DecodeLabs blog.
Install
composer require decodelabs/veneer
Usage
Say you have a common library class you use regularly:
namespace Some\Random\Library { // This is a library class you use regularly class MyThing { public function doAThing() { echo 'Done!'; } } }
You can bind a static, automatically generated frontage by:
namespace App\Setup { // This is your environment setup code use DecodeLabs\Veneer; use Some\Random\Library\MyThing; use App\CoolThing; Veneer::register( MyThing::class, // active object class MyThingFrontage::class // frontage class ); } namespace Some\Other\Code { use App\CoolThing; // Your general userland code CoolThing::doAThing(); }
Plugins
Unfortunately PHP still doesn't have __getStatic()
yet so we have to statically declare plugin names at binding time, but they're still useful for creating more expansive interfaces.
Define plugins as properties on your FacadeTarget
with a Plugin
attribute, include LazyLoad
attribute too if it doesn't need to be loaded straight away.
namespace My\Library { use DecodeLabs\Veneer\Plugin; use DecodeLabs\Veneer\LazyLoad; class MyThing { #[Plugin] #[LazyLoad] public MyPlugin $plugin; } class MyPlugin { public function doAThing(): string { return 'Hello from plugin1'; } } } namespace Some\Other\Code { use My\Library\MyThing; MyThing::$plugin->doAThing(); // Hello from plugin1 }
Note, if your target class has a constructor with required parameters, you will need to add decodelabs/slingshot
to your project to allow Veneer to instantiate it.
Licensing
Veneer is licensed under the MIT License. See LICENSE for the full license text.