PHP code example of apishka / easy-extend

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

    

apishka / easy-extend example snippets




return array(
    'easy-extend' => array(
        'finder' => function($finder)
        {
            $finder
                ->in('source/')
                ->files()
                ->name('*.php')
            ;

            return $finder;
        }
    ),
);
 

class Library_User_Implementation
{
    /**
     * We have to 

class My_Library_User_Implementation extends Library_User_Implementation
{
}

Library_User_Implementation::apishka(); // instanceof My_Library_User_Implementation

class My_Library_ItemsRouter extends \Apishka\EasyExtend\Router\ByKeyAbstract
{
    protected function isCorrectItem(\ReflectionClass $reflector)
    {
        return $reflector->isSubclassOf('My_Library_ItemsInterface');
    }

    protected function getClassVariants(\ReflectionClass $reflector, $item)
    {
        return $item->getAliases();
    }
}

class My_Library_ItemApple implements My_Library_ItemsInterface
{
    public function getAliases()
    {
        return array(
            'apple',
            'red_apple',
        );
    }
}

var_dump(
    get_class(My_Library_ItemsRouter::apishka()->getItem('apple')
); // My_Library_ItemApple

var_dump(
    get_class(My_Library_ItemsRouter::apishka()->getItem('red_apple')
); // My_Library_ItemApple

class My_Library_ItemRedApple extends My_Library_ItemApple
{
}

// after ./vendor/bin/easy-extend
var_dump(
    get_class(My_Library_ItemsRouter::apishka()->getItem('apple')
); // My_Library_ItemRedApple