2017 © Pedro Peláez
 

library skeleton

Inversion of Control library

image

oktopost/skeleton

Inversion of Control library

  • Wednesday, August 2, 2017
  • by alexey-pkv
  • Repository
  • 4 Watchers
  • 0 Stars
  • 1,174 Installations
  • PHP
  • 13 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 16 Versions
  • 13 % Grown

The README.md

Build Status, (*1)

Skeleton

Latest version 1.2.0, (*2)

Skeleton is an Inversion of Control (IoC) Library for PHP 7.1 or higher., (*3)

Build Status, (*4)

Installation

composer require oktopost/skeleton

or inside composer.json, (*5)

"require": {
    "oktopost/skeleton": "^1.0"
}

Basic Usage Example:

// src/Proj/Base/IUserDAO.php
interface IUserDAO
{
    public function load($id);
}

// src/Proj/DAO/UserDAO.php
class UserDAO implements IUserDAO
{
    public function load($id)
    {
        // ...
    }
}


// skeleton-config.php
$skeleton = new \Skeleton\Skeleton();
$skeleton->set(Proj\Base\IUserDAO::class, Proj\DAO\UserDAO::class);
// or
$skeleton->set("Using any string as key", Proj\DAO\UserDAO::class);


// Obtaining a new instance using
$service = $skeleton->get(Proj\DAO\IUserDAO::class);
// or
$service = $skeleton->get("Using any string as key");

In this case, $service will be set to a new instance of the UserDAO class that was created by Skeleton., (*6)

Autoloading class

Given the following setup:, (*7)

// src/Proj/Base/IUserDAO.php
interface IUserDAO {}

// src/Proj/Base/IUserService.php
interface IUserService {}

// src/Proj/DAO/UserDAO.php
class UserDAO implements IUserDAO {}


// skeleton-config.php
$skeleton = new \Skeleton\Skeleton();
$skeleton->set(Proj\Base\IUserDAO::class,     Proj\DAO\UserDAO::class);
$skeleton->set(Proj\Base\IUserService::class, Proj\Service\UserService::class);

Instance of UserService may be obtained without autoloading using:, (*8)

// src/Proj/Service/UserService.php
class UserService implements IUserService
{
    public function setUserDAO(IUserDAO $dao)
    {
    }
}

$instance = $skeleton->get(IUserService::class);
$instance->setUserDAO($skeleton->get(IUserDAO::class));

But with autoloading you can omit the call to setUserDAO using one of the following., (*9)

Using setter methods autolaoding

// skeleton-config.php
$skeleton->enableKnot();

// src/Proj/Service/UserService.php
/**
 * @autoload
 */
class UserService implements IUserService
{
    /**
     * @autoload
     * Method must start with the word "set", have only one parameter and the @autoload annotation.
     * Private and protected methods will be also autoloaded.
     */
    public function setUserDAO(IUserDAO $dao)
    {
    }
}

// example.php
$instance = $skeleton->get(IUserService::class);

Using data member autoloading.

// skeleton-config.php
$skeleton->enableKnot();

// src/Proj/Service/UserService.php
/**
 * @autoload
 */
class UserService implements IUserService
{
    /**
     * @autoload
     * @var \Full\Path\To\IUserDAO
     * Important: Full path must be defined under the @var annotation.
     */
    private $dao;
}

// example.php
$instance = $skeleton->get(IUserService::class);

Using __construct autoloading.

In this case the autoload annotation is not required for the class name nor for the __construct method., (*10)

// skeleton-config.php
$skeleton->enableKnot();

// src/Proj/Service/UserService.php
class UserService implements IUserService
{
    public function __construct(IUserDAO $dao)
    {
    }
}

// example.php
$instance = $skeleton->get(IUserService::class);

The Versions

02/08 2017

dev-master

9999999-dev https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexey Puchkov

02/08 2017

1.1.3

1.1.3.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexey Puchkov

31/07 2017

1.1.2

1.1.2.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexey Puchkov

31/07 2017

1.1.1

1.1.1.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexey Puchkov

27/07 2017

1.1.0

1.1.0.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexey Puchkov

28/06 2017

1.0.10

1.0.10.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexey Puchkov

20/02 2017

1.0.9

1.0.9.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

by Alexey Puchkov

28/11 2016

1.0.8

1.0.8.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

by Alexey Puchkov

09/10 2016

dev-Orthopaedist

dev-Orthopaedist https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

by Alexey Puchkov

05/10 2016

1.0.6

1.0.6.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

by Alexey Puchkov

01/10 2016

1.0.5

1.0.5.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

by Alexey Puchkov

01/10 2016

1.0.4

1.0.4.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

by Alexey Puchkov

28/09 2016

1.0.3

1.0.3.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

by Alexey Puchkov

20/07 2016

1.0.2

1.0.2.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

by Alexey Puchkov

14/07 2016

1.0.1

1.0.1.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

by Alexey Puchkov

07/07 2016

1.0.0

1.0.0.0 https://github.com/Oktopost/Skeleton

Inversion of Control library

  Sources   Download

MIT

The Requires

 

by Alexey Puchkov