PHP code example of magic-tool / container

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

    

magic-tool / container example snippets

 php

//\App\Controller\GoodsController::getInstance()->index();
pp\Service\OrderService;
use Dependency\Initiation\SystemInitiation;
use App\Facades\Http\Facade\HttpFacade;
use App\Facades\Http\Request;

//初始化命名空间
SystemInitiation::setNameSpaces(function () {
    return [
        'App\Service',
        'App\Controller',
    ];
});
//运行自动加载的后缀
SystemInitiation::setClassSuffixList([
    'Service',
    'Model',
//    'Facade'
]);

SystemInitiation::setNameSpaceList(function () {
    return [
        HttpFacade::class => Request::class
    ];
});

//HttpFacade::swap(Request::class);

//执行调用
try {
    invoke(GoodsController::class)->execute('index');
    echo app(GoodsModel::class)->getGoodsCount();
    app(OrderService::class)->createOrder(10, 20);
    OrderService::getInstance()->createOrder(10, 20);
} catch (Exception $exception) {
    print_r($exception->getMessage());
}