PHP code example of wok / services

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

    

wok / services example snippets

 php
use \WOK\Services\Services;
$services = new Services();

// Sample with Symfony/Translation as `translator` service and the locale code as parameter
$services->addService('translator', function($locale) {

    $translator = new \Symfony\Component\Translation\Translator($locale);
    $translator->addLoader('ini', new \Symfony\Component\Translation\Loader\IniFileLoader());

    $files = new DirectoryIterator($path);
    foreach($files as $resource) {

        if($resource->getExtension() != 'ini') {
            continue;
        }

        // Only accepted files as `domain.locale.(ini|yml)`
        $basename = $resource->getBasename();
        $domain = mb_substr($basename, 0, mb_strpos($basename, '.'));

        $translator->addResource($resource->getExtension(), $resource->getPathname(), $locale, $domain);

    }

    return $translator;

});


// Far far away ...


$translator = $services->getService('translator', array('fr_FR'));