Example #1
0
 /**
  * Creates RAD app kernel, which you can use to manage your app.
  *
  * Loads intl, swift and then requires/initializes/returns custom
  * app kernel.
  *
  * @param ClassLoader $loader      Composer class loader
  * @param string      $environment Environment name
  * @param Boolean     $debug       Debug mode?
  *
  * @return RadAppKernel
  */
 public static function createAppKernel(ClassLoader $loader, $environment, $debug)
 {
     require_once __DIR__ . '/RadAppKernel.php';
     if (null === self::$projectRootDir) {
         self::$projectRootDir = realpath(__DIR__ . '/../../../../../../..');
     }
     $autoloadIntl = function ($rootDir) use($loader) {
         if (!function_exists('intl_get_error_code')) {
             require_once $rootDir . '/vendor/symfony/symfony/src/' . 'Symfony/Component/Locale/Resources/stubs/functions.php';
             $loader->add(null, $rootDir . '/vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
         }
     };
     $autoloadSwift = function ($rootDir) use($loader) {
         require_once $rootDir . '/vendor/swiftmailer/swiftmailer/lib/classes/Swift.php';
         \Swift::registerAutoload($rootDir . '/vendor/swiftmailer/swiftmailer/lib/swift_init.php');
     };
     $loader->add(null, self::$projectRootDir . '/src');
     if (file_exists($custom = self::$projectRootDir . '/config/autoload.php')) {
         require $custom;
     } else {
         $autoloadIntl(self::$projectRootDir);
         $autoloadSwift(self::$projectRootDir);
     }
     return new \RadAppKernel($environment, $debug);
 }
Example #2
0
 /**
  * Tests regular PSR-0 and PSR-4 class loading.
  *
  * @dataProvider getLoadClassTests
  *
  * @param string $class            The fully-qualified class name to test, without preceding namespace separator.
  */
 public function testLoadClass($class)
 {
     $loader = new ClassLoader();
     $loader->add('Namespaced\\', __DIR__ . '/Fixtures');
     $loader->add('Pearlike_', __DIR__ . '/Fixtures');
     $loader->addPsr4('ShinyVendor\\ShinyPackage\\', __DIR__ . '/Fixtures');
     $loader->loadClass($class);
     $this->assertTrue(class_exists($class, false), "->loadClass() loads '{$class}'");
 }
Example #3
0
 protected function registerModuleLoaders()
 {
     foreach ($this->parameters['modules'] as $items) {
         if (isset($items['autoload']['psr-0'])) {
             foreach ($items['autoload']['psr-0'] as $key => $val) {
                 $this->classLoader->add($key, $items['path'] . '/' . $val);
             }
         }
         if (isset($items['autoload']['files'])) {
             foreach ($items['autoload']['files'] as $file) {
                 include_once $items['path'] . '/' . $file;
             }
         }
     }
 }
 /**
  * Tests regular PSR-0 and PSR-4 class loading.
  *
  * @dataProvider getLoadClassTests
  *
  * @param string $class The fully-qualified class name to test, without preceding namespace separator.
  * @param bool $prependSeparator Whether to call ->loadClass() with a class name with preceding
  *                               namespace separator, as it happens in PHP 5.3.0 - 5.3.2. See https://bugs.php.net/50731
  */
 public function testLoadClass($class, $prependSeparator = FALSE)
 {
     $loader = new ClassLoader();
     $loader->add('Namespaced\\', __DIR__ . '/Fixtures');
     $loader->add('Pearlike_', __DIR__ . '/Fixtures');
     $loader->addPsr4('ShinyVendor\\ShinyPackage\\', __DIR__ . '/Fixtures');
     if ($prependSeparator) {
         $prepend = '\\';
         $message = "->loadClass() loads '{$class}'.";
     } else {
         $prepend = '';
         $message = "->loadClass() loads '\\{$class}', as required in PHP 5.3.0 - 5.3.2.";
     }
     $loader->loadClass($prepend . $class);
     $this->assertTrue(class_exists($class, false), $message);
 }
Example #5
0
 /**
  * Adds autoloader prefixes from user's config
  */
 protected function registerCustomAutoloaders()
 {
     if (isset($this->config['autoloaders']) && is_array($this->config['autoloaders'])) {
         foreach ($this->config['autoloaders'] as $prefix => $path) {
             $this->autoloader->add($prefix, $path);
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getLoader()
 {
     $loader = new ClassLoader();
     foreach ($this->information as $prefix => $paths) {
         $loader->add($prefix, array_map(array($this, 'prependPathWithBaseDir'), (array) $paths));
     }
     return array($loader, 'loadClass');
 }
Example #7
0
 /**
  * @param string $ns Namespace's description
  * @param string $path Namespace's path
  * @throws Exception
  */
 public static function registerNamespace($ns, $path)
 {
     switch (true) {
         case self::$loader instanceof \Composer\Autoload\ClassLoader:
             self::$loader->add($ns, $path);
             break;
         case self::$loader instanceof \Zend\Loader\SplAutoloader:
             self::$loader->registerPrefix($ns, $path . '/' . $ns);
             break;
             // @TODO: This hasn't been tested nor confirmed. Must test & check if OK.
         // @TODO: This hasn't been tested nor confirmed. Must test & check if OK.
         case self::$loader instanceof \Symfony\Component\ClassLoader\UniversalClassLoader:
             self::$loader->registerNamespace($ns, $path);
             break;
         default:
             throw new \Exception('No Loader detected!');
     }
 }
 /**
  * Load the addon.
  *
  * @param $path
  */
 public function load($path)
 {
     if (file_exists($autoload = $path . '/vendor/autoload.php')) {
         include $autoload;
         return;
     }
     if (!file_exists($path . '/composer.json')) {
         return;
     }
     $composer = json_decode(file_get_contents($path . '/composer.json'), true);
     if (!array_key_exists('autoload', $composer)) {
         return;
     }
     foreach (array_get($composer['autoload'], 'psr-4', []) as $namespace => $autoload) {
         $this->loader->addPsr4($namespace, $path . '/' . $autoload, false);
     }
     foreach (array_get($composer['autoload'], 'psr-0', []) as $namespace => $autoload) {
         $this->loader->add($namespace, $path . '/' . $autoload, false);
     }
     foreach (array_get($composer['autoload'], 'files', []) as $file) {
         include $path . '/' . $file;
     }
 }
 /**
  * Check that the auto loading information is correct.
  *
  * @param array  $information The autoload information.
  *
  * @param string $baseDir     The base directory.
  *
  * @return bool
  */
 public function validateComposerAutoLoadingPsr0($information, $baseDir)
 {
     $result = true;
     // Scan all directories mentioned and validate the class map against the entries.
     foreach ($information as $namespace => $path) {
         $subPath = str_replace('//', '/', $baseDir . '/' . $path);
         $classMap = $this->createClassMap($subPath, $namespace);
         $this->loader->add($namespace, $subPath);
         if (!$this->validateComposerAutoLoadingPsr0ClassMap($classMap, $subPath, $namespace)) {
             $result = false;
         }
     }
     return $result;
 }
Example #10
0
 /**
  * Adds autoloader prefixes from user's config
  */
 protected function registerCustomAutoloaders()
 {
     if (isset($this->config['autoloaders']) && is_array($this->config['autoloaders'])) {
         foreach ($this->config['autoloaders'] as $prefix => $path) {
             $this->autoloader->add($prefix, $path);
         }
     }
     if (isset($this->config['autoloaders_psr4']) && is_array($this->config['autoloaders_psr4'])) {
         foreach ($this->config['autoloaders_psr4'] as $prefix => $path) {
             $this->autoloader->addPsr4($prefix, $path);
         }
     }
     if (isset($this->config['autoload_files']) && is_array($this->config['autoload_files'])) {
         foreach ($this->config['autoload_files'] as $file) {
             require $file;
         }
     }
 }
 public function register()
 {
     $app = $this->app;
     foreach ($app['contenttypes'] as $contentType) {
         $key = $contentType->getKey();
         $model = $this->getModel($contentType);
         $repository = $this->getRepository($contentType);
         $package = $this->getPackage();
         $vendor = $package->getVendor();
         $lowerVendor = strtolower($vendor);
         $name = $package->getName();
         $lowerName = strtolower($name);
         $loader = new ClassLoader();
         $loader->add($vendor . '\\' . $name . '\\', $app['paths']['base'] . '/vendor/' . $lowerVendor . '/' . $lowerName . '/src');
         $loader->register();
         $this->registerModel($key, $model);
         $this->registerRepository($key, $repository);
     }
 }
Example #12
0
 /**
  * Class Prefix (Namespace) Register
  *
  * @param string $prefix
  * @param string $path
  * @throws \Exception
  */
 public function registerNamespace($prefix, $path)
 {
     switch (true) {
         // Zend Loader
         case self::$loader instanceof \Zend\Loader\SplAutoloader:
             self::$loader->registerPrefix($prefix, $path . '/' . str_replace('\\', '/', $prefix));
             break;
             // Composer Loader
         // Composer Loader
         case self::$loader instanceof \Composer\Autoload\ClassLoader:
             self::$loader->add($prefix, $path);
             break;
             // Symphony Loader
             // @TODO: Wonder if we should implement this as well or not
             // Throw exception for not finding a suported loader
         // Symphony Loader
         // @TODO: Wonder if we should implement this as well or not
         // Throw exception for not finding a suported loader
         default:
             throw new Exception\UndefinedClassLoaderException(sprintf('Unexpected ClassLoader type: \'%s\'', get_class(self::$loader)));
     }
     return $this;
 }
Example #13
0
<?php

/**
 * Created by PhpStorm.
 * User: info_000
 * Date: 28.08.2015
 * Time: 0:00
 */
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Composer\Autoload\ClassLoader;
use Core\Libs\Route;
//$loader = new \Composer\Autoload\ClassLoader();
$loader = new ClassLoader();
$loader->add('Core\\Libs\\Route', $_SERVER['DOCUMENT_ROOT'] . '');
$loader->register();
$route = new Route();
/*
print_r(__NAMESPACE__);

new Routing();

echo '1';



use \Core\Libs\Routing;
use \Core\Libs\Controller;


function spl_autoload($class){
Example #14
0
 /**
  * Adds autoloader prefixes from user's config
  *
  * @param ClassLoader $autoloader
  */
 public function registerCustomAutoloaders(ClassLoader $autoloader)
 {
     $mask = '<debug>Registered %s autoloader </debug> <info>%s</info> -> <comment>%s</comment>';
     foreach ($this->getArray('autoloaders') as $prefix => $paths) {
         $paths = (array) $paths;
         $this->debugWriteln(sprintf($mask, self::PSR_0, OutputFormatter::escape($prefix), implode(",", $paths)));
         $autoloader->add($prefix, $paths);
     }
     foreach ($this->getArray('autoloaders_psr4') as $prefix => $paths) {
         $paths = (array) $paths;
         $this->debugWriteln(sprintf($mask, self::PSR_4, OutputFormatter::escape($prefix), implode(",", $paths)));
         $autoloader->addPsr4($prefix, $paths);
     }
 }
Example #15
0
 public static function add($namespace, $dir)
 {
     if (!in_array($namespace, self::$autoloader->getPrefixes())) {
         self::$autoloader->add($namespace, dirname($dir));
     }
 }
Example #16
0
 /**
  * Registers default autoloading for the Extension.
  *
  * @return \Composer\Autoload\ClassLoader
  */
 public function registerDefaultAutoloading()
 {
     $loader = new ClassLoader();
     $loader->add($this->namespace, $this->path . '/src');
     $loader->register();
     $loader->setUseIncludePath(true);
     return $this->autoloaders[] = $loader;
 }
 /**
  * {@inheritdoc}
  */
 public function addPsr0($nsPrefix, $paths, $prepend = false)
 {
     $this->autoloader->add($nsPrefix, $paths, $prepend);
 }
 /**
  * Registers an autoloader based on an autoload map returned by parseAutoloads
  *
  * @param  array       $autoloads see parseAutoloads return value
  * @return ClassLoader
  */
 public function createLoader(array $autoloads)
 {
     $loader = new ClassLoader();
     if (isset($autoloads['psr-0'])) {
         foreach ($autoloads['psr-0'] as $namespace => $path) {
             $loader->add($namespace, $path);
         }
     }
     if (isset($autoloads['psr-4'])) {
         foreach ($autoloads['psr-4'] as $namespace => $path) {
             $loader->addPsr4($namespace, $path);
         }
     }
     if (isset($autoloads['classmap'])) {
         foreach ($autoloads['classmap'] as $dir) {
             $loader->addClassMap($this->generateClassMap($dir));
         }
     }
     return $loader;
 }
Example #19
0
<?php

namespace tests;

use Composer\Autoload\ClassLoader;
require_once dirname(__DIR__) . '/vendor/autoload.php';
$loader = new ClassLoader();
$loader->add('tests', dirname(__DIR__));
$loader->register();
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Composer\Autoload\ClassLoader;
$loader = new ClassLoader();
$loader->add('PROCERGS\\LoginCidadao\\MonitorBundle', __DIR__);
$loader->register();
return $loader;
Example #21
0
 protected function loadModule($modCfgArray, $modIdx)
 {
     $cfg = new Config($modCfgArray['default']);
     $ns = $cfg->get('namespace');
     // If this class can't be loaded, enable the autoload using the composer class loader.
     if (!empty($ns)) {
         // Full directory of the module to be initialized.
         $dir = $cfg->get('directory');
         $parentDir = $this->config->get('directory');
         $parentModulesDir = $this->config->get('modulesDir');
         if (preg_match('/^\\//', $dir) > 0) {
         } else {
             if (preg_match('/^\\//', $parentModulesDir) > 0) {
                 $dir = $parentModulesDir . DIRECTORY_SEPARATOR . $dir;
             } else {
                 $dir = $parentDir . DIRECTORY_SEPARATOR . $parentModulesDir . DIRECTORY_SEPARATOR . $dir;
             }
         }
         $dirReal = realpath($dir) . DIRECTORY_SEPARATOR;
         if (!$dirReal) {
             throw new \Exception("The directory {$dir} of the child module does not exists or is not readable.");
         }
         // Override the current module 'directory' value
         $cfg->set('directory', $dir);
         // Add the namespacec to the  composer ClassLoader
         $loader = new ClassLoader();
         $loader->add($ns, $dir);
         $loader->register();
         $loader->setUseIncludePath(true);
     }
     if ($cn = $cfg->get('moduleClassName')) {
         $mClass = $ns . '\\' . $cn;
     } else {
         // Use the default moduleClassName. See the top of this file.
         $mClass = $this->config->get('moduleClassName');
     }
     // Add others options sets, if provided
     foreach ($modCfgArray as $k => $optSet) {
         if ($k == 'default') {
             continue;
         }
         $cfg->set($optSet, null, $k);
     }
     // Instance the module.
     $mod = new $mClass($cfg, $this, $this->injections);
     return $this->children[$modIdx] = $mod;
 }
Example #22
0
 /**
  * Add a local namepspace
  * 
  * @param string $namespace
  * @param string $path
  */
 public function addLocalNamespace($namespace, $path)
 {
     $this->class_loader->add($namespace, $path);
 }
Example #23
0
 /**
  * Adds autoloader prefixes from user's config
  *
  * @param ClassLoader $autoloader
  */
 public function registerCustomAutoloaders(ClassLoader $autoloader)
 {
     $output = $this->output;
     if (isset($this->config['autoloaders']) && is_array($this->config['autoloaders'])) {
         foreach ($this->config['autoloaders'] as $prefix => $path) {
             $autoloader->add($prefix, $path);
             if (OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity()) {
                 $output->writeln('<debug>Registrered PSR-2 autoloader </debug> <info>' . $prefix . '</info> -> <comment>' . $path . '</comment>');
             }
         }
     }
     if (isset($this->config['autoloaders_psr4']) && is_array($this->config['autoloaders_psr4'])) {
         foreach ($this->config['autoloaders_psr4'] as $prefix => $path) {
             $autoloader->addPsr4($prefix, $path);
             if (OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity()) {
                 $output->writeln('<debug>Registrered PSR-4 autoloader </debug> <info>' . $prefix . ' </info> -> <comment>' . $path . '</comment>');
             }
         }
     }
 }
Example #24
0
 /**
  * Boot modules Class AutoLoader
  *
  * @param \CID\Core\Module\Json $module
  */
 protected function bootClassAutoLoader(Json $module)
 {
     $autoload = $module->getModuleAutoLoad();
     $loader = new ClassLoader();
     // boot classmap
     if (array_key_exists('classmap', $autoload)) {
         $loader->addClassMap($autoload['classmap']);
     }
     // boot psr-0
     if (array_key_exists('psr-0', $autoload)) {
         foreach ($autoload['psr-0'] as $prefix => $path) {
             $loader->add($prefix, $module->getBasePath() . DIRECTORY_SEPARATOR . $path);
         }
     }
     // boot-psr-4
     if (array_key_exists('psr-4', $autoload)) {
         foreach ($autoload['psr-4'] as $prefix => $path) {
             $loader->addPsr4($prefix, $module->getBasePath() . DIRECTORY_SEPARATOR . $path);
         }
     }
     // register the autoloader
     $loader->register();
 }
Example #25
0
<?php

/**
 * Created by PhpStorm.
 * User: info_000
 * Date: 18.09.2015
 * Time: 0:53
 */
require_once $_SERVER['DOCUMENT_ROOT'] . "/vendor/autoload.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/application/settings/settings.php";
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Composer\Autoload\ClassLoader;
use Application\Libs\Data;
use Application\Libs\Route;
use Application\Libs\Controller;
$loader = new ClassLoader();
$loader->add('Application\\Libs\\Data', $_SERVER['DOCUMENT_ROOT'] . '');
$loader->add('Application\\Libs\\Route', $_SERVER['DOCUMENT_ROOT'] . '');
$loader->add('Application\\Libs\\Controller', $_SERVER['DOCUMENT_ROOT'] . '');
$loader->register();
$paths = array($doctrina_paths_entity_files);
$isDevMode = false;
$config = Setup::createAnnotationMetadataConfiguration($paths, true);
$db = EntityManager::create($dbParams, $config);
$data = new Data();
$route = new Route();
$controller = new Controller();
$route->start($route_settings);
Example #26
0
 /**
  * Initializes CurryCms using the specified configuration.
  * 
  * @param string|array|null $config Path to configuration file, array with configuration options or null for no configuration.
  * @param float|null $startTime Time when initialization was started (use microtime(true)), if not specified the current time will be used.
  * @param bool|null $initAutoloader Attempt to initialize vendor/autoload.php
  */
 public static function init($config, $startTime = null, $initAutoloader = null)
 {
     self::$startTime = $startTime === null ? microtime(true) : $startTime;
     if (get_magic_quotes_gpc()) {
         throw new Exception('magic quotes gpc is enabled, please disable!');
     }
     // Initialize autoloader?
     if ($initAutoloader === null) {
         $initAutoloader = spl_autoload_functions();
         $initAutoloader = $initAutoloader === false || !count($initAutoloader);
     }
     if ($initAutoloader) {
         $autoload = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
         if (!file_exists($autoload)) {
             throw new Exception('curry/vendor/autoload.php not found, make sure composer dependencies have been installed.');
         }
         self::$autoloader = (require_once $autoload);
     }
     // load configuration
     self::$config = new Zend_Config(self::getConfig($config));
     // add project path to autoloader
     if ($initAutoloader) {
         $projectInclude = Curry_Util::path(self::$config->curry->projectPath, 'include');
         self::$autoloader->add('', $projectInclude);
         set_include_path($projectInclude . PATH_SEPARATOR . get_include_path());
     }
     // trigger hook
     self::triggerHook('Curry_Core::preInit');
     // try to use utf-8 locale
     setlocale(LC_ALL, 'en_US.UTF-8', 'en_US.UTF8', 'UTF-8', 'UTF8');
     // umask
     if (self::$config->curry->umask) {
         umask(self::$config->curry->umask);
     }
     // init
     self::initErrorHandling();
     self::initLogging();
     self::initPropel();
     self::initCache();
     self::initEncoding();
     Curry_URL::setDefaultBaseUrl(self::$config->curry->baseUrl);
     Curry_URL::setDefaultSecret(self::$config->curry->secret);
     self::triggerHook('Curry_Core::postInit');
     register_shutdown_function(array(__CLASS__, 'shutdown'));
 }
Example #27
0
 /**
  * Registers an autoloader based on an autoload map returned by parseAutoloads
  *
  * @param  array       $autoloads see parseAutoloads return value
  * @return ClassLoader
  */
 public function createLoader(array $autoloads)
 {
     $loader = new ClassLoader();
     if (isset($autoloads['psr-0'])) {
         foreach ($autoloads['psr-0'] as $namespace => $path) {
             $loader->add($namespace, $path);
         }
     }
     if (isset($autoloads['psr-4'])) {
         foreach ($autoloads['psr-4'] as $namespace => $path) {
             $loader->addPsr4($namespace, $path);
         }
     }
     if (isset($autoloads['classmap'])) {
         foreach ($autoloads['classmap'] as $dir) {
             try {
                 $loader->addClassMap($this->generateClassMap($dir));
             } catch (\RuntimeException $e) {
                 $this->io->writeError('<warning>' . $e->getMessage() . '</warning>');
             }
         }
     }
     return $loader;
 }
Example #28
0
<?php

use Composer\Autoload\ClassLoader;
if (!@(include __DIR__ . '/../vendor/autoload.php')) {
    die(<<<'EOT'
You must set up the project dependencies, run the following commands:
wget http://getcomposer.org/composer.phar
php composer.phar install
EOT
);
}
$loader = new ClassLoader();
$loader->add('Acme', __DIR__ . '/Peytz/Test/Wizard/Fixtures');
$loader->register();
 /**
  * Registers an autoloader based on an autoload map returned by parseAutoloads
  *
  * @param  array       $autoloads see parseAutoloads return value
  * @return ClassLoader
  */
 public function createLoader(array $autoloads)
 {
     $loader = new ClassLoader();
     if (isset($autoloads['psr-0'])) {
         foreach ($autoloads['psr-0'] as $namespace => $path) {
             $loader->add($namespace, $path);
         }
     }
     if (isset($autoloads['psr-4'])) {
         foreach ($autoloads['psr-4'] as $namespace => $path) {
             $loader->addPsr4($namespace, $path);
         }
     }
     return $loader;
 }
Example #30
0
 public static function addPrefix($prefix, $paths)
 {
     self::$autoloader->add($prefix, $paths);
 }