PHP code example of dszczer / minion

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

    

dszczer / minion example snippets


// web/index.php

nded to provide ./src/ namespace, but Minion will try to guess this value
$namespace = 'Project\\';

$app = new Minion\Application($namespace, ['debug' => false, 'environment' => 'prod']);
$app->run();

// src/Controller/DefaultController.php

namespace Project\Controller;

use Minion\Controller;
use Minion\Application;
use Symfony\HttpFoundation\Request;
// ...

class DefaultController extends Controller
{
    public function indexAction(Request $request, Application $app)
    {
        // ...
        
        // if you're using Twig, path is relative to src/Resources/views/
        return $this->render('index.html.twig');
        
        // if you're not using Twig, path is relative to src/
        return $this->render('template_index.html.php');
    }
}

// src/Service/MyService.php

namespace Project\Service;

class MyService
{
    public function foo()
    {
        return 'bar';
    }
}

// src/Service/CustomServiceProvider.php

namespace Project\Service;

use \Minion\Service\ServiceProvider;
use \Silex\Application as SilexApp;

class CustomServiceProvider extends ServiceProvider
{
    public function register(SilexApp $app)
    {
        $config = $this->getServiceConfig();
        $app[ $config->getId() ] = $app->share(function(SilexApp $app) {
            return new MyService();
        });
    }
    
    public function boot(SilexApp $app) {}
}

// src/Service/CustomServiceProvider.php

namespace Project\Service;

use \Minion\Service\ServiceProvider;
use \Silex\Application as SilexApp;

class CustomServiceProvider extends ServiceProvider
{
    public function register(SilexApp $app)
    {
        $app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig, SilexApp $app) {
            $class = $this->getServiceConfig()->getOption('twig.extension.class'); // is \Project\Util\MyTwigExtension
            $twig->addExtension(new $class);

            return $twig;
        }));
    }
    
    public function boot(SilexApp $app) {}
}

// ...
class DefaultController extends Controller
{
    public function defaultAction(Request $request, Application $app) {
        $myServiceName = $app['my_custom_service']->foo(); // should return 'bar'
    }
}

// ...

class CustomServiceProvider extends ServiceProvider
{
    public function register(SilexApp $app)
    {
        $serviceConfiguration = $this->getServiceConfig();
    }
    
    // ...
}

// src/Command/ProjectCommand.php

namespace Project\Command;

use Knp\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ProjectCommand extends Command
{
    // Configure command
    protected function configure() {
        $this
            ->setName('project')
            ->setDescription('project command')
        ;
    }

    // Execute command
    public function execute(InputInterface $input, OutputInterface $output) {
        $output->write('project command in practice');
    }
}