PHP code example of lorddashme / php-static-class-interface
1. Go to this page and download the library: Download lorddashme/php-static-class-interface 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/ */
lorddashme / php-static-class-interface example snippets
e __DIR__ . '/src/Exception/ClassNamespaceResolver.php';
sInterface\Facade;
class ServiceClassFacade extends Facade
{
protected static function getStaticClassAccessor()
{
return '\Namespace\ServiceClass';
}
}
pace Demo\MyClass;
// Import the main class of the package.
use LordDashMe\StaticClassInterface\Facade;
// This is the original service class.
class ServiceClass
{
public function testService($context)
{
echo 'Hello World ' . $context . '!';
}
}
// This is the mimic service class that can now access like static class.
class ServiceClassFacade extends Facade
{
protected static function getStaticClassAccessor()
{
// The namespace of the Service Class that will convert
// into a "static" like class.
return '\Demo\MyClass\ServiceClass';
}
}
// This is the Service Class.
$service = new ServiceClass();
$service->testService('ServiceClass'); // echo Hello World ServiceClass!
// And we can now use the Service Class like a "static" class implementation.
ServiceClassFacade::testService('ServiceFacadeClass'); // echo Hello World ServiceFacadeClass!