2017 © Pedro Peláez
 

library iguana

image

dxw/iguana

  • Tuesday, September 26, 2017
  • by tomdxw
  • Repository
  • 6 Watchers
  • 2 Stars
  • 5,938 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 5 Open issues
  • 4 Versions
  • 10 % Grown

The README.md

iguana

An extensible theme and plugin framework for WordPress., (*1)

Components

  • iguana is the library that allows themes and plugins to set up autoloading and dependency injection without nearly as much boilerplate code
  • iguana-theme builds on iguana and allows themes to register helper functions and use template layouts

Theme templates that use Iguana

Installation

Add the iguana library to your theme or plugin:, (*2)

$ composer require dxw/iguana

Add these two lines to templates/functions.php (modify appropriately if functions.php isn't in a subdirectory):, (*3)

$registrar = require __DIR__.'/../app/load.php';
$registrar->register();

Add a new file called app/load.php:, (*4)

<?php

require __DIR__.'/../vendor.phar';

return \Dxw\Iguana\Init::init(__DIR__, 'MyTheme');

(Replace MyTheme with the namespace of your own theme/plugin.), (*5)

Add a new file called app/di.php:, (*6)

It can start out blank:, (*7)

<?php

But eventually it will contain the code necessary to construct the dependency graph of your code, i.e.:, (*8)

$registrar->addInstance(new \MyTheme\MyClass());
$registrar->addInstance(new \MyTheme\MyOtherClass(
    $registrar->getInstance(\MyTheme\MyClass::class)
));

What Iguana provides

For your dependency-injected class structure

Your classes can indicate that they have code that needs running (this is run on the call to $registrar->register() in functions.php):, (*9)

<?php

namespace MyTheme;

class MyClass implements \Dxw\Iguana\Registerable
{
    public function register()
    {
        add_filter(...);
    }
}

Any instance added to the registrar that implements \Dxw\Iguana\Registerable will have its register() method called., (*10)

This means you don't have to remember call the register() method somewhere after adding it to app/di.php., (*11)

And moving the calls to add_filter(), 'register_xyz()`, etc out of the constructor makes unit testing easier., (*12)

For your background processes and cron jobs

If you're running a background process or cron job outside of WordPress, you can $registrar = require('path/to/load.php'); to load all the code in your theme/plugin. If you need to register it, you can do it piece-by-piece, or you can $registrar->register(); to register it all at once., (*13)

Licence

MIT, (*14)

The Versions

26/09 2017

dev-feature/psalm

dev-feature/psalm https://github.com/dxw/iguana

  Sources   Download

MIT

The Requires

 

The Development Requires

14/12 2016

dev-master

9999999-dev https://github.com/dxw/iguana

  Sources   Download

MIT

The Requires

 

The Development Requires

08/07 2016

v1.1.0

1.1.0.0 https://github.com/dxw/iguana

  Sources   Download

MIT

The Requires

 

The Development Requires

18/05 2016

v1.0.0

1.0.0.0 https://github.com/dxw/iguana

  Sources   Download

MIT

The Requires

 

The Development Requires