Пример #1
0
 /**
  * @return RobotLoader
  */
 public static function createRobotLoader($options)
 {
     $loader = new RobotLoader();
     $loader->autoRebuild = !Environment::isProduction();
     //$loader->setCache(Environment::getCache('Nette.RobotLoader'));
     $dirs = isset($options['directory']) ? $options['directory'] : array(Environment::getVariable('appDir'), Environment::getVariable('libsDir'));
     $loader->addDirectory($dirs);
     $loader->register();
     return $loader;
 }
Пример #2
0
/** 2b) check if needed directories are writable */
if (!is_writable(Environment::getVariable('tempDir'))) {
    die("Make directory '" . realpath(Environment::getVariable('tempDir')) . "' writable!");
}
if (!is_writable(Environment::getVariable('logDir'))) {
    die("Make directory '" . realpath(Environment::getVariable('logDir')) . "' writable!");
}
/** 2c) Setup Nette\Debug for better exception and error visualisation */
//Debug::$productionMode = $_SERVER['REMOTE_ADDR'] !== '127.0.0.1';  // admin's computer IP
$mode = !Environment::isProduction() && !Environment::getHttpRequest()->isAjax() ? Debug::DEVELOPMENT : Debug::PRODUCTION;
Debug::enable($mode, NULL);
Debug::$strictMode = TRUE;
Debug::$showLocation = TRUE;
/** 2d) enable RobotLoader - this allows load all classes automatically */
$loader = new RobotLoader();
$loader->addDirectory(explode(';', $config->scanDirs));
$loader->autoRebuild = Environment::isProduction() ? FALSE : TRUE;
// rebuild if class is not found?
$loader->register();
/** 2e) load extension methods */
if (is_file(APP_DIR . '/extensions.php')) {
    include_once APP_DIR . '/extensions.php';
}
/** 2f) enable DebugBar */
if ($mode == Debug::DEVELOPMENT) {
    Debug::$showBar = TRUE;
}
/** 2g) Session setup [optional] */
if (Environment::getVariable('sessionDir') !== NULL && !is_writable(Environment::getVariable('sessionDir'))) {
    die("Make directory '" . realpath(Environment::getVariable('sessionDir')) . "' writable!");
}
Пример #3
0
<?php

// loader
require LIB_DIR . '/Nette/loader.php';
$loader = new RobotLoader();
$loader->addDirectory(APP_DIR);
$loader->addDirectory(LIB_DIR);
$loader->autoRebuild = TRUE;
$loader->register();
// configure
foreach (require Environment::expand('%settingsFile%') as $k => $v) {
    Environment::setVariable($k, $v);
}
foreach (require Environment::expand('%adminLoginFile%') as $k => $v) {
    define('ADMIN_' . strtoupper($k), $v);
}
foreach (require Environment::expand('%commonFile%') as $k => $v) {
    Environment::setVariable($k, $v);
}
if (!function_exists('date_default_timezone_set')) {
    function date_default_timezone_set($timezone)
    {
        ini_set('date.timezone', $timezone);
    }
}
date_default_timezone_set(require Environment::expand('%timezoneFile%'));
// debugging
Debug::enable(NULL, BASE_DIR . '/error.log', Environment::expand('%adminEmail%'));
// paths
Environment::setVariable('themeDir', Environment::expand('%baseDir%/themes'));
Environment::setVariable('templatesDir', Environment::expand('%themeDir%/%theme%'));
Пример #4
0
<h1>Nette\Loaders\RobotLoader test</h1>

<pre>
<?php 
require_once '../../Nette/loader.php';
/*use Nette\Debug;*/
/*use Nette\Environment;*/
Environment::setVariable('tempDir', dirname(__FILE__) . '/tmp');
foreach (glob(Environment::expand('%tempDir%/*')) as $file) {
    unlink($file);
}
// delete all files
$loader = new RobotLoader();
$loader->addDirectory('../../Nette/');
$loader->addDirectory(dirname(__FILE__));
$loader->addDirectory(dirname(__FILE__));
// purposely doubled
$loader->register();
if (class_exists('TestClass')) {
    echo 'class TestClass successfully loaded';
}
Пример #5
0
 /**
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 public function generateClassCase(InputInterface $input, OutputInterface $output)
 {
     $src = $this->getSrc();
     $dest = $this->getDest();
     $configNeon = $this->getNeonData($dest);
     $config = Arrays::get($configNeon, 'tests', array());
     $configServices = Arrays::get($config, 'services', array());
     $configData = Arrays::get($config, 'case', array());
     $configCount = count($configData);
     if ($configCount == 0) {
         return;
     }
     $this->writeNotice($output, "Generating Class Specific Tests: " . $configCount);
     $robotLoader = new RobotLoader();
     $robotLoader->autoRebuild = TRUE;
     $robotLoader->setCacheStorage(new FileStorage($this->getCacheDirectory()));
     $robotLoader->addDirectory($dest);
     $robotLoader->rebuild();
     $robotLoader->register();
     $autoloaderClasses = $robotLoader->getIndexedClasses();
     $classReflections = array();
     foreach ($autoloaderClasses as $class) {
         $classReflections[] = $class;
     }
     foreach ($configServices as $configName => $configClass) {
         $classPrototype = Arrays::get($configClass, 'class');
         $classType = $classPrototype . "Test";
         $classFilename = Arrays::get($autoloaderClasses, $classType, NULL);
         $classGeneratorProperties = array();
         $classGeneratorMethods = array();
         $classGeneratorConst = array();
         $classGeneratorImplements = array();
         $classDependencies = array();
         if (NULL === $classFilename) {
             $classPrototypeReflection = ReflectionClassType::from($classPrototype);
             $classParent = "\\" . $classPrototypeReflection->getName() . "Base";
             $classPrototypeName = $classPrototypeReflection->getName();
             $classPrototypeGenerator = PhpGeneratorClassType::from($classPrototypeReflection);
             $className = $classPrototypeGenerator->getName() . "Test";
             $classReflection = $classPrototypeReflection;
             $classGenerator = new PhpGeneratorClassType($classReflection);
             $classGenerator->setName($className);
             $classGenerator->setExtends($classParent);
             $classGenerator->setImplements($classGeneratorImplements);
             $classGenerator->setProperties($classGeneratorProperties);
             $classGenerator->setMethods($classGeneratorMethods);
             $classGenerator->setConsts($classGeneratorConst);
             $classGenerator->addProperty("className", "\\" . $configName);
             $classFilename = dirname(str_replace($this->getRootDir(), $this->getDest(), $classReflection->getFileName())) . DIRECTORY_SEPARATOR . $classGenerator->getName() . ".php";
         } else {
             $classReflection = ReflectionClassType::from($classType);
             $classGenerator = PhpGeneratorClassType::from($classReflection);
             $classGeneratorConst = $classGenerator->getConsts();
             $classGeneratorProperties = $classGenerator->getProperties();
             $classGeneratorImplements = $classGenerator->getImplements();
             $classGeneratorMethods = $classGenerator->getMethods();
         }
         if ('interface' == $classGenerator->getType() || $classGenerator->isAbstract()) {
             continue;
         }
         $classGeneratorAnnotation = $classReflection->getAnnotations();
         $classAnnotationsSwitch = Arrays::get($classGeneratorAnnotation, 'no-test', FALSE);
         if (FALSE !== $classAnnotationsSwitch) {
             continue;
         }
         try {
             $instanceProvider = $classReflection->getMethod("getInstance");
         } catch (\Exception $e) {
             $instanceProvider = $classGenerator->addMethod("getInstance");
             $instanceProvider->setBody('return parent::getInstance();');
             $instanceProvider->setDocuments(array('return' => "@return \\" . $classPrototype));
         }
         $classDependency = "";
         foreach ($classDependencies as $dependency => $dependencyClass) {
             $classDependency .= "\nuse " . $dependency;
             if ('' == $dependencyClass) {
                 $classDependency .= " as " . $dependencyClass;
             }
             $classDependency .= ";";
         }
         $classCode = sprintf("<?php\nnamespace %s;\n%s\n%s", $classReflection->getNamespaceName(), $classDependency, $classGenerator);
         $this->saveClass($classCode, new \SplFileInfo($classFilename));
     }
 }