PHP code example of oktopost / skeleton

1. Go to this page and download the library: Download oktopost/skeleton 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/ */

    

oktopost / skeleton example snippets


// 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");

// 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);

// 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));

// 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);

// 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);

// 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);