PHP code example of decodelabs / veneer

1. Go to this page and download the library: Download decodelabs/veneer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

decodelabs / veneer example snippets


namespace Some\Random\Library;

// This is a library class you use regularly
class MyThing
{
    public function doAThing() {
        echo 'Done!';
    }
}

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
    CoolThing::class // frontage class
);




namespace Some\Other\Code;

use App\CoolThing;

// Your general userland code
CoolThing::doAThing();

namespace My\Library
{
    use DecodeLabs\Veneer\Plugin;

    class MyThing {

        #[Plugin]
        public MyPlugin $plugin;

        #[Plugin(auto: true)]
        public MyPlugin $autoPlugin;

        #[Plugin(lazy: true)]
        public MyPlugin $lazyPlugin;

        public function __construct() {
            $this->plugin = new MyPlugin();
        }
    }


    class MyPlugin
    {
        public function doAThing(): string {
            return 'Hello from plugin';
        }
    }
}

namespace Some\Other\Code
{
    use My\Library\MyThing;

    MyThing::$plugin->doAThing(); // Hello from plugin
    MyThing::$autoPlugin->doAThing(); // Hello from plugin
    MyThing::$lazyPlugin->doAThing(); // Hello from plugin
}

namespace My\Library
{
    use DecodeLabs\Veneer\Plugin;

    class MyThing {

        #[Plugin]
        protected(set) MyPlugin $plugin {
            get => $this->plugin ??= new MyPlugin();
        }
    }
}