This setup can be used to prefix classnames, say for a wordpress plugin.
install globally not within you package.
composer global require php-scoper --with-all-dependencies
Create the scoper.inc.php
file
php-scoper init
In my case i have my psr-4 namespaced class in ./lib
, so, I modified scoper.inc.php
,
FIND -> Finder::create()->files()->in('src'),
REPLACE -> Finder::create()->files()->in('lib'),
cd /path/to/project
chmod +x ./scope.sh
./scope.sh
Instead of requiring vendor/autoload.php
I include vendor/scoper-autoload.php
which also includes the standard autoloader.
Option 1) Just require the file
require_once __DIR__ . '/vendor/scoper-autoload.php';
Option 2) Sometimes you just want to start working without running scoper, so, this works wel for that situation.
// autloading scoped vs. unscoped
if ( file_exists( __DIR__ . '/vendor/scoper-autoload.php' ) ) {
require_once __DIR__ . '/vendor/scoper-autoload.php';
} else {
require_once __DIR__ . '/vendor/autoload.php';
}
<?php
$loader = require_once __DIR__ . '/vendor/scoper-autoload.php';
print_r( $loader->getClassMap() );
exit;