PHP code example of mepihindeveloper / php-service-locator

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

    

mepihindeveloper / php-service-locator example snippets




declare(strict_types = 1);

use mepihindeveloper\components\container\interfaces\ServiceInterface;
use mepihindeveloper\components\container\ServiceLocator;

error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

$filePath;

    public function __construct(string $filePath = '') {
        $this->filePath = $filePath;
    }

    /**
     * Получает путь к файлу
     * 
     * @return string
     */
    public function getFilePath(): string {
        return $this->filePath;
    }
};
$serviceLocator->addInstance(get_class($logger), $logger);
var_dump($serviceLocator->has(get_class($logger)), $serviceLocator->get(get_class($logger)));

// OR

$serviceLocator->addService(get_class($logger), ['/var/www/']);
$logger = $this->serviceLocator->get(get_class($logger));
var_dump($logger->getFilePath()); // /var/www/


src/
--- exceptions/
------ ContainerObjectInvalidTypeException.php
--- interfaces/
------ ServiceInterface.php
--- ServiceLocator.php