PHP code example of exteon / chaining-class-resolver
1. Go to this page and download the library: Download exteon/chaining-class-resolver 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/ */
exteon / chaining-class-resolver example snippets
use Exteon\Loader\ChainingClassResolver\ChainingClassResolver;
use Exteon\Loader\ChainingClassResolver\Module;
use Exteon\Loader\ChainingClassResolver\ClassFileResolver\PSR4ClassFileResolver;
$chainingClassResolver = new ChainingClassResolver(
[
new Module(
'Code base',
[new PSR4ClassFileResolver(__DIR__ . '/base', 'Code\\Base')]
),
new Module(
'Plugin 1',
[new PSR4ClassFileResolver(__DIR__ . '/plugins/plugin1', 'Plugin1')]
),
new Module(
'Plugin 2',
[new PSR4ClassFileResolver(__DIR__ . '/plugins/plugin2', 'Plugin2')]
),
new Module(
'Plugin 3',
[new PSR4ClassFileResolver(__DIR__ . '/plugins/plugin3', 'Plugin3')]
)
],
'Target'
);
use Exteon\Loader\MappingClassLoader\MappingClassLoader;
use Exteon\Loader\MappingClassLoader\StreamWrapLoader;
$loader = new MappingClassLoader(
[],
[
$chainingClassResolver
],
[],
new StreamWrapLoader([
'enableMapping' => true
])
);
$loader->register();
use Target\A;
use Target\B;
$a = new A();
$b = new B();
var_dump($a->whoami());
var_dump($b->whoami());
$loader->dumpHintClasses(__DIR__.'/dev/hints');
namespace Target {
/**
* @extends \Code\Base\A
* @extends \Plugin1\A
*/
class A extends \Plugin2\A {}
}
class A {
public function whoami(){
return ['A'];
}
}
trait T1 {
public function whoami(){
return array_merge(parent::whoami(),['T1']);
}
}
trait T2 {
public function whoami(){
return array_merge(parent::whoami(),['T2']);
}
}
class B extends A {
use T1,T2;
public function whoami(){
return array_merge(parent::whoami(),['B']);
}
}