PHP code example of phine / locator

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

    

phine / locator example snippets


use Phine\Locator\Locator;
use Phine\Locator\Service\AbstractService;
use Phine\Locator\Service\ResolvableInterface;

/**
 * A service that simply gets returned.
 */
class SimpleService extends AbstractService
{
}

/**
 * A service that causes the locator to return something else.
 */
class ResolvedService extends AbstractService implements ResolvableInterface
{
    /**
     * {@inheritDoc}
     */
    public function getResolvedValue()
    {
        return 'Something else.';
    }
}

// create my locator
$locator = new Locator();

// register my services
$locator->registerService('simple', new SimpleService());
$locator->registerService('resolved', new ResolvedService());

// access my services
echo get_class($locator->getService('simple')); // "SimpleService"
echo $locator->resolveService('resolved'); // "Something else."

use Phine\Locator\ArrayLocator;

// create my locator
$locator = new ArrayLocator();

// register my services
$locator['simple'] = new SimpleService();
$locator['resolved'] = new ResolvedService();

// access my services
echo get_class($locator['simple']); // "SimpleService"
echo $locator['resolved']; // "Something else."