本文整理汇总了PHP中ClassLoader类的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader类的具体用法?PHP ClassLoader怎么用?PHP ClassLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClassLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLoadClass
public function testLoadClass()
{
$loader = new ClassLoader();
$loader->register();
$this->assertEquals(true, class_exists("Controller"));
$this->assertEquals(false, class_exists("MyController"));
}
示例2: getLoader
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('\\Composer\\Autoload\\Initializer', 'loadClassLoader'), true, true);
self::$loader = $loader = new ClassLoader();
spl_autoload_unregister(array('\\Composer\\Autoload\\Initializer', 'loadClassLoader'));
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
$map = (require __DIR__ . '/autoload_namespaces.php');
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$classMap = (require __DIR__ . '/autoload_classmap.php');
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register(true);
$includeFiles = (require __DIR__ . '/autoload_files.php');
foreach ($includeFiles as $file) {
require $file;
}
return $loader;
}
示例3: __construct
public function __construct(ClassLoader $aClassLoader, $sNamespace = null, $nPriority = Package::all)
{
$arrClasses = array();
foreach ($aClassLoader->packageIterator($nPriority) as $aPackage) {
if ($sNamespace) {
$sPackageNamespace = $aPackage->ns();
if ($sNamespace == $sPackageNamespace) {
$sSubNs = null;
} else {
if (strpos($sNamespace, $sPackageNamespace . '\\') === 0) {
$sSubNs = substr($sNamespace, strlen($sPackageNamespace) + 1);
} else {
continue;
}
}
} else {
$sSubNs = null;
}
foreach ($aPackage->classIterator($sSubNs) as $sClass) {
if (!in_array($sClass, $arrClasses)) {
$arrClasses[] = $sClass;
}
}
}
sort($arrClasses);
parent::__construct($arrClasses);
}
示例4: getLoader
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('AutoloaderInit', 'loadClassLoader'), true, true);
self::$loader = $loader = new ClassLoader();
spl_autoload_unregister(array('AutoloaderInit', 'loadClassLoader'));
/* $map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}*/
/* $map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}*/
$includeFiles = (require __DIR__ . '/autoload_files.php');
foreach ($includeFiles as $file) {
composerRequire($file);
}
$classMap = (require __DIR__ . '/autoload_classmap.php');
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register(true);
return $loader;
}
示例5: make
/**
* Makes autoloader.
*
* @return ClassLoader The class loader
*/
public static function make()
{
if (!static::$loader) {
$loader = new ClassLoader();
$loader->register();
static::$loader = $loader;
}
return static::$loader;
}
示例6: configure
/**
* Add autoload configuration of packages managed by Composer
*
* @param ClassLoader $classLoader class loader instance to configure
* @param string $vendorDirPath path to the vendor directory without trailing slash
*/
public static function configure(ClassLoader $classLoader, $vendorDirPath)
{
$composerBasePath = $vendorDirPath . '/composer/';
$classLoader->addClassMap(include $composerBasePath . 'autoload_classmap.php');
$classLoader->addPrefixes(include $composerBasePath . 'autoload_psr4.php');
$classLoader->addPrefixes(include $composerBasePath . 'autoload_namespaces.php', ClassLoader::PSR0);
foreach (include $composerBasePath . 'autoload_files.php' as $file) {
require $file;
}
}
示例7: init
function init()
{
$loader = new ClassLoader();
$map = (require __DIR__ . '/autoload_namespaces.php');
foreach ($map as $namespace => $path) {
$loader->add($namespace, $path);
}
$loader->register();
return $loader;
}
示例8: registerClassLoader
public function registerClassLoader()
{
if (!interface_exists("ClassLoader", false)) {
require \pocketmine\PATH . "src/spl/ClassLoader.php";
require \pocketmine\PATH . "src/spl/BaseClassLoader.php";
require \pocketmine\PATH . "src/pocketmine/CompatibleClassLoader.php";
}
if ($this->classLoader !== null) {
$this->classLoader->register(true);
}
}
示例9: getLoader
/**
* Constructs and returns the class loader.
*
* @param array $map Array containing path to each namespace.
*
* @return ClassLoader
*/
public static function getLoader(array $map)
{
if (null !== self::$loader) {
return self::$loader;
}
self::$loader = $loader = new ClassLoader();
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$loader->register(true);
return $loader;
}
示例10: getLoader
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoLoaderInit', 'loadClassLoader'), true, true);
self::$loader = $loader = new ClassLoader();
spl_autoload_unregister(array('ComposerAutoLoaderInit', 'loadClassLoader'));
$class_map = (require dirname(__FILE__) . '/autoload_classmap.php');
if ($class_map) {
$loader->addClassMap($class_map);
}
$loader->register();
return $loader;
}
示例11: start
/**
* Loads all aspects from configured paths and activates class loader.
*/
public function start()
{
$classLoader = new ClassLoader();
$aspectLoader = AspectLoader::getLoader();
$registry = Registry::getRegistry();
foreach ($this->getAspectPaths() as $aspectPath) {
$aspectLoader->loadAspects($aspectPath);
}
$aspectLoader->activate();
$aspectLoader->deactivate();
foreach ($aspectLoader->getAspects() as $aspectClass) {
$registry->parseClass($aspectClass);
}
$classLoader->activate();
}
示例12: __static
static function __static()
{
// For singletonInstance test
ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousSingleton', 'lang.Object', array(), '{
protected static $instance= NULL;
static function getInstance() {
if (!isset(self::$instance)) self::$instance= new AnonymousSingleton();
return self::$instance;
}
}');
// For returnNewObject and returnNewObjectViaReflection tests
ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousList', 'lang.Object', array(), '{
function __construct() {
ReferencesTest::registry("list", $this);
}
}');
ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousFactory', 'lang.Object', array(), '{
static function factory() {
return new AnonymousList();
}
}');
ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousNewInstanceFactory', 'lang.Object', array(), '{
static function factory() {
return XPClass::forName("net.xp_framework.unittest.core.AnonymousList")->newInstance();
}
}');
}
示例13: run
public static function run($accessString)
{
if (empty($accessString)) {
return true;
}
if (preg_match_all('/([\\w\\.]+)(?:\\(([\\w\\.]*)(?:\\/(\\w*))?\\))?,?/', $accessString, $roles)) {
ClassLoader::import('application.model.user.SessionUser');
$currentUser = SessionUser::getUser();
$controller = Controller::getCurrentController();
$rolesParser = $controller->getRoles();
$currentControllerName = $controller->getRequest()->getControllerName();
$currentActionName = $controller->getRequest()->getActionName();
$rolesCount = count($roles[0]);
for ($i = 0; $i < $rolesCount; $i++) {
$roleString = $roles[0][$i];
$roleName = $roles[1][$i];
$roleControllerName = empty($roles[3][$i]) ? $currentControllerName : $roles[2][$i];
$roleActionName = empty($roles[3][$i]) ? empty($roles[2][$i]) ? $currentActionName : $roles[2][$i] : $currentActionName;
if ($roleControllerName == $currentControllerName && $roleActionName == $currentActionName) {
$aRoleName = $rolesParser->getRole($roleActionName);
if ($currentUser->hasAccess($aRoleName) && $currentUser->hasAccess($roleName)) {
return true;
}
}
}
return false;
}
throw new ApplicationException('Access string ("' . $accessString . '") has illegal format');
}
示例14: getInstance
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new ClassLoader();
}
return self::$instance;
}
示例15: deployBean
/**
* Deploy
*
* @param remote.server.deploy.Deployable deployment
*/
public function deployBean($deployment)
{
if ($deployment instanceof IncompleteDeployment) {
throw new DeployException('Incomplete deployment originating from ' . $deployment->origin, $deployment->cause);
}
$this->cat && $this->cat->info($this->getClassName(), 'Begin deployment of', $deployment);
// Register beans classloader. This classloader must be put at the beginning
// to prevent loading of the home interface not implmenenting BeanInterface
$cl = $deployment->getClassLoader();
ClassLoader::getDefault()->registerLoader($cl, TRUE);
$impl = $cl->loadClass($deployment->getImplementation());
$interface = $cl->loadClass($deployment->getInterface());
$directoryName = $deployment->getDirectoryName();
// Fetch naming directory
$directory = NamingDirectory::getInstance();
// Create beanContainer
// TBI: Check which kind of bean container has to be created
$beanContainer = StatelessSessionBeanContainer::forClass($impl);
$this->cat && $beanContainer->setTrace($this->cat);
// Create invocation handler
$invocationHandler = new ContainerInvocationHandler();
$invocationHandler->setContainer($beanContainer);
// Now bind into directory
$directory->bind($directoryName, Proxy::newProxyInstance($cl, array($interface), $invocationHandler));
$this->cat && $this->cat->info($this->getClassName(), 'End deployment of', $impl->getName(), 'with ND entry', $directoryName);
return $beanContainer;
}