public function testLoadClass()
 {
     $loader = new ClassLoader();
     $loader->register();
     $this->assertEquals(true, class_exists("Controller"));
     $this->assertEquals(false, class_exists("MyController"));
 }
Example #2
0
 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;
 }
Example #3
0
 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);
 }
Example #4
0
 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;
 }
 /**
  * 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;
 }
Example #6
0
 /**
  * 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;
     }
 }
function init()
{
    $loader = new ClassLoader();
    $map = (require __DIR__ . '/autoload_namespaces.php');
    foreach ($map as $namespace => $path) {
        $loader->add($namespace, $path);
    }
    $loader->register();
    return $loader;
}
Example #8
0
 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);
     }
 }
Example #9
0
 /**
  * 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;
 }
 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;
 }
Example #11
0
 /**
  * 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();
 }
    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();
        }
      }');
    }
Example #13
0
 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');
 }
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new ClassLoader();
     }
     return self::$instance;
 }
 /**
  * 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;
 }
 /**
  * Sets up test case
  *
  */
 public function setUp()
 {
     try {
         $this->classname = $this->testClassName();
         $this->interfacename = $this->testClassName('I');
     } catch (IllegalStateException $e) {
         throw new PrerequisitesNotMetError($e->getMessage());
     }
     // Create an archive
     $this->tempfile = new TempFile($this->name);
     $archive = new Archive($this->tempfile);
     $archive->open(ARCHIVE_CREATE);
     $this->add($archive, $this->classname, '
     uses("util.Comparator", "' . $this->interfacename . '");
     class ' . $this->classname . ' extends Object implements ' . $this->interfacename . ', Comparator { 
       public function compare($a, $b) {
         return strcmp($a, $b);
       }
     }
   ');
     $this->add($archive, $this->interfacename, 'interface ' . $this->interfacename . ' { } ');
     $archive->create();
     // Setup classloader
     $this->classloader = new ArchiveClassLoader($archive);
     ClassLoader::getDefault()->registerLoader($this->classloader, TRUE);
 }
Example #17
0
 public function testSimpleImport()
 {
     $lv = ActiveRecordModel::getNewInstance('Language');
     $lv->setID('xx');
     $lv->save();
     $profile = new CsvImportProfile('Product');
     $profile->setField(0, 'Product.sku');
     $profile->setField(1, 'Product.name', array('language' => 'en'));
     $profile->setField(2, 'Product.name', array('language' => 'xx'));
     $profile->setField(3, 'Product.shippingWeight');
     $profile->setParam('delimiter', ';');
     $csvFile = ClassLoader::getRealPath('cache.') . 'testDataImport.csv';
     file_put_contents($csvFile, 'test; "Test Product"; "Parbaudes Produkts"; 15' . "\n" . 'another; "Another Test"; "Vel Viens"; 12.44');
     $import = new ProductImport($this->getApplication());
     $csv = $profile->getCsvFile($csvFile);
     $cnt = $import->importFile($csv, $profile);
     $this->assertEquals($cnt, 2);
     $test = Product::getInstanceBySKU('test');
     $this->assertTrue($test instanceof Product);
     $this->assertEquals($test->shippingWeight->get(), '15');
     $this->assertEquals($test->getValueByLang('name', 'en'), 'Test Product');
     $another = Product::getInstanceBySKU('another');
     $this->assertEquals($another->getValueByLang('name', 'xx'), 'Vel Viens');
     unlink($csvFile);
 }
Example #18
0
 /**
  * Loads all the files that the environment requires
  */
 public static function load_imports()
 {
     require_once PATH_TO_ROOT . '/kernel/framework/helper/deprecated_helper.inc.php';
     include_once PATH_TO_ROOT . '/kernel/framework/core/ClassLoader.class.php';
     ClassLoader::init_autoload();
     AppContext::init_bench();
 }
Example #19
0
 /**
  * 获取类的单一实例
  *
  * @return static
  */
 public static function getInstance()
 {
     if (!is_object(self::$instance)) {
         self::$instance = new static();
     }
     return self::$instance;
 }
    public static function dummyConnectionClass()
    {
        self::$conn = ClassLoader::defineClass('RestClientExecutionTest_Connection', 'peer.http.HttpConnection', array(), '{
        protected $result= NULL;
        protected $exception= NULL;

        public function __construct($status, $body, $headers) {
          parent::__construct("http://test");
          if ($status instanceof Throwable) {
            $this->exception= $status;
          } else {
            $this->result= "HTTP/1.1 ".$status."\\r\\n";
            foreach ($headers as $name => $value) {
              $this->result.= $name.": ".$value."\\r\\n";
            }
            $this->result.= "\\r\\n".$body;
          }
        }
        
        public function send(HttpRequest $request) {
          if ($this->exception) {
            throw $this->exception;
          } else {
            return new HttpResponse(new MemoryInputStream($this->result));
          }
        }
      }');
    }
 /**
  * 
  * @return ClassLoader
  */
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #22
0
 private function getFilterUrlTemplate()
 {
     include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.categoryUrl.php';
     $params = array('filters' => array(new ManufacturerFilter(999, '___')), 'data' => Category::getRootNode()->toArray());
     $templateUrl = createCategoryUrl($params, $this->application);
     return strtr($templateUrl, array(999 => '#', '___' => '|'));
 }
 public static function getGenerator(CustomerOrder $order)
 {
     $class = ActiveRecordModel::getApplication()->getConfig()->get('INVOICE_NUMBER_GENERATOR');
     self::loadGeneratorClass($class);
     ClassLoader::import('application.model.order.invoiceNumber.' . $class);
     return new $class($order);
 }
Example #24
0
 public function __construct(LiveCart $application)
 {
     if ($application->getConfig()->get('SSL_BACKEND')) {
         $application->getRouter()->setSslAction('');
     }
     parent::__construct($application);
     if (!isset($_SERVER['HTTP_USER_AGENT'])) {
         $_SERVER['HTTP_USER_AGENT'] = 'Firefox';
     }
     // no IE yet
     if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
         ClassLoader::import('application.controller.backend.UnsupportedBrowserException');
         throw new UnsupportedBrowserException();
     }
     if (!$this->user->hasBackendAccess() && !$this instanceof SessionController) {
         SessionUser::destroy();
         $url = $this->router->createUrl(array('controller' => 'backend.session', 'action' => 'index', 'query' => array('return' => $_SERVER['REQUEST_URI'])));
         if (!$this->isAjax()) {
             header('Location: ' . $url);
         } else {
             header('Content-type: text/javascript');
             echo json_encode(array('__redirect' => $url));
         }
         exit;
     }
 }
Example #25
0
 /**
  * Loads the directory recursively
  * 
  * @param string $specDir
  * @param array  $ignore
  * @return array
  */
 public function load($specDir, $ignore = array())
 {
     $ignore = $this->lookForIgnoreConfig($specDir, $ignore);
     $directory = new \DirectoryIterator($specDir);
     $loaded = array();
     foreach ($directory as $file) {
         if ($file->isDot()) {
             continue;
         }
         if ($this->fileIsNotInIgnoreList($file, $ignore)) {
             if ($file->isDir()) {
                 $loaded = array_merge($loaded, $this->load($file->getRealpath(), $ignore));
             } else {
                 $example = parent::load($file->getRealpath());
                 if ($example !== false && $example !== array(false)) {
                     if (!is_array($example)) {
                         $example = array($example);
                     }
                     $loaded = array_merge($loaded, $example);
                 }
             }
         }
     }
     return $loaded;
 }
 public static function defineExiterClass()
 {
     self::$exiterClass = ClassLoader::defineClass('net.xp_framework.unittest.core.Exiter', 'lang.Object', array(), '{
     public function __construct() { throw new SystemExit(0); }
     public static function doExit() { new self(); }
   }');
 }
Example #27
0
 public function notify($requestArray)
 {
     $requestArray['version'] = '1.2open';
     $keys = array('TPE', 'date', 'montant', 'reference', 'texte-libre', 'version', 'code-retour');
     $values = array();
     foreach (array('TPE', 'date', 'montant', 'reference', 'texte-libre', 'version', 'code-retour') as $key) {
         $values[$key] = $requestArray[$key];
     }
     $macParams = array_combine($keys, $values);
     $mac = $requestArray['retourPLUS'] . implode('+', $macParams) . '+';
     $hash = strtoupper($this->CMCIC_hmac($mac));
     ob_end_clean();
     file_put_contents(ClassLoader::getRealPath('cache.') . get_class($this) . '.php', var_export($requestArray, true));
     if ('annulation' == strtolower($requestArray['code-retour'])) {
         printf("Pragma: no-cache \nContent-type: text/plain \nVersion: 1 %s", 'Annulation');
     } else {
         if ($hash == $requestArray['MAC']) {
             $result = new TransactionResult();
             $result->gatewayTransactionID->set($requestArray['reference']);
             $result->amount->set(substr($requestArray['montant'], 0, -3));
             $result->currency->set(substr($requestArray['montant'], -3));
             $result->rawResponse->set($requestArray);
             $result->setTransactionType(TransactionResult::TYPE_SALE);
             printf("Pragma: no-cache \nContent-type: text/plain \nVersion: 1 %s", 'OK');
             return $result;
         } else {
             printf("Pragma: no-cache \nContent-type: text/plain \nVersion: 1 %s", 'Document falsifie');
             exit;
         }
     }
 }
Example #28
0
 public function setUp()
 {
     ActiveRecordModel::getApplication()->clearCachedVars();
     ActiveRecordModel::beginTransaction();
     if (empty($this->autoincrements)) {
         foreach ($this->getUsedSchemas() as $table) {
             $res = $this->db->executeQuery("SHOW TABLE STATUS LIKE '{$table}'");
             $res->next();
             $this->autoincrements[$table] = (int) $res->getInt("Auto_increment");
         }
     }
     if ($this instanceof BackendControllerTestCase) {
         ClassLoader::import('application.model.user.SessionUser');
         ClassLoader::import('application.model.user.UserGroup');
         // set up user
         $group = UserGroup::getNewInstance('Unit tester');
         $group->save();
         $group->setAllRoles();
         $group->save();
         $user = User::getNewInstance('*****@*****.**', null, $group);
         $user->save();
         SessionUser::setUser($user);
     }
     if ($this instanceof ControllerTestCase) {
         $this->request = self::getApplication()->getRequest();
     }
 }
Example #29
0
 public static function instance()
 {
     if (!self::$instance) {
         self::$instance = new ClassLoader();
     }
     return self::$instance;
 }
Example #30
0
 /**
  * Main
  *
  * @param  string[] $args
  * @return int
  */
 public static function main(array $args)
 {
     $command = null;
     if (empty($args)) {
         $class = new XPClass(self::class);
         $source = $class->getClassLoader();
         $markdown = $class->getComment();
     } else {
         if ('@' === $args[0][0]) {
             $resource = substr($args[0], 1);
             if (null === ($source = ClassLoader::getDefault()->findResource($resource))) {
                 Console::$err->writeLine('No help topic named ', $resource);
                 return 2;
             }
             $markdown = $source->getResource($resource);
         } else {
             $class = $args[0];
             if (null === ($source = ClassLoader::getDefault()->findClass($class))) {
                 Console::$err->writeLine('No class named ', $class);
                 return 2;
             }
             $markdown = $source->loadClass($class)->getComment();
         }
     }
     self::render(Console::$out, $markdown, $source);
     return 1;
 }