Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/decodelabs/veneer
Automated static frontages for PHP
https://github.com/decodelabs/veneer
facade frontage php
Last synced: 17 days ago
JSON representation
Automated static frontages for PHP
- Host: GitHub
- URL: https://github.com/decodelabs/veneer
- Owner: decodelabs
- License: mit
- Created: 2019-09-10T23:08:20.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2024-09-04T21:39:17.000Z (5 months ago)
- Last Synced: 2024-09-22T19:45:27.121Z (4 months ago)
- Topics: facade, frontage, php
- Language: PHP
- Homepage:
- Size: 213 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Veneer
[![PHP from Packagist](https://img.shields.io/packagist/php-v/decodelabs/veneer?style=flat)](https://packagist.org/packages/decodelabs/veneer)
[![Latest Version](https://img.shields.io/packagist/v/decodelabs/veneer.svg?style=flat)](https://packagist.org/packages/decodelabs/veneer)
[![Total Downloads](https://img.shields.io/packagist/dt/decodelabs/veneer.svg?style=flat)](https://packagist.org/packages/decodelabs/veneer)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/decodelabs/veneer/integrate.yml?branch=develop)](https://github.com/decodelabs/veneer/actions/workflows/integrate.yml)
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-44CC11.svg?longCache=true&style=flat)](https://github.com/phpstan/phpstan)
[![License](https://img.shields.io/packagist/l/decodelabs/veneer?style=flat)](https://packagist.org/packages/decodelabs/veneer)### 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](https://blog.decodelabs.com)._
---
## Install
```bash
composer require decodelabs/veneer
```## Usage
Say you have a common library class you use regularly:```php
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:
```php
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 aPlugin
attribute, includeLazyLoad
attribute too if it doesn't need to be loaded straight away.```php
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](./LICENSE) for the full license text.