Example #1
0
 public function testFirst()
 {
     global $foo, $counter;
     $file = File::generateFilepath('class_cache', 'fooClass');
     if (is_file($file)) {
         unlink($file);
     }
     $proxy = new Cache('fooClass');
     $this->assertEquals($proxy->foobar(1, 2, 3), $proxy->foobar(1, 2, 3));
     $this->assertEquals($proxy->foobar(1, 2, 3), $proxy->foobar(1, 2, 3));
     $x = $proxy->foobar(1, 2, 3);
     $this->assertEquals($x[0], $foo);
     $this->assertEquals($counter, 1);
     unset($proxy);
 }
Example #2
0
File: One.php Project: crodas/cli
 /**
  *  @CliPlugin One
  *  @CliPlugin Crontab
  */
 public function main(zCallable $function, $input, $output)
 {
     $args = $function->getOne('one,crontab')->getArgs();
     $lock = File::generateFilePath('lock', $function->getName());
     if (!empty($args)) {
         $lock = $args[0];
     }
     if (filesize($lock) > 0) {
         $pid = trim(file_get_contents($lock));
         if (posix_getsid($pid) !== false) {
             throw new RuntimeException("Process {$function->getName()}() is still running");
         }
     }
     File::write($lock, getmypid());
 }
Example #3
0
 public function __construct(array $config, Build $builder)
 {
     $collections = new Generate\Collections($config['files'], $this);
     self::$cdir = $config['loader'];
     $namespace = "ActiveMongo2\\Namspace" . uniqid(true);
     $rnd = uniqid();
     $valns = $collections->getValidatorNS();
     $validator = $collections->getValidator();
     class_exists("crodas\\FileUtil\\File");
     // preload class
     $args = compact('docs', 'namespace', 'mapper', 'indexes', 'self', 'collections', 'valns', 'rnd', 'validator');
     $code = Template\Templates::get('documents')->render($args, true);
     if (strlen($code) >= 1024 * 1024 || !class_exists('crodas\\SimpleView\\FixCode')) {
         File::write($config['loader'], $code);
     } else {
         File::write($config['loader'], FixCode::fix($code));
     }
     $this->writeFileWatch($builder, $collections);
 }
Example #4
0
 public function generate()
 {
     $output = $this->getOutput();
     $cache = new Watch($output . '.cache');
     $dirs = array_unique($this->dirs);
     $files = array_unique($this->files);
     $files[] = $output;
     $dirs[] = __DIR__ . '/Filters';
     $cache->watchFiles($files);
     $cache->watchDirs($dirs);
     if (!$cache->hasChanged()) {
         return;
     }
     $annotations = new \Notoj\Filesystem(array_unique(array_merge($dirs, $files)));
     $compiler = new Compiler($this, $annotations);
     File::write($output, $compiler->getOutput());
     $cache->watchFiles($files)->watchDirs($dirs);
     $cache->watch();
     return $compiler->getOutput();
 }
Example #5
0
 public function __call($name, array $arguments)
 {
     $strid = serialize($arguments);
     $files = [];
     $args = [];
     if (is_array($arguments[0])) {
         $files = $arguments[0];
     } else {
         $files = $arguments;
     }
     if (count($arguments) == 2 && is_array($arguments[1])) {
         $args = $arguments[1];
     }
     return $this->build($name, File::generateFilePath('build', $name, $strid), $files, $args);
 }
Example #6
0
 protected function renderSingle($output)
 {
     $code = Templates::get('autoloader')->render($this->GetTemplateArgs($output), true);
     File::write($output, $code);
 }
Example #7
0
 public function writeTo($file)
 {
     return File::write($file, $this->GetCode());
 }
Example #8
0
 public function __construct($loader = '')
 {
     $this->loader = $loader ?: File::generateFilepath('activemongo2', getcwd());
     $this->cache = new Cache\Cache();
 }
Example #9
0
 /**
  *  @expectedException RuntimeException
  */
 public function testFilePathException()
 {
     File::generateFilepath();
 }
Example #10
0
 public function addFile($name, $path = NULL)
 {
     if ($path == NULL) {
         $path = $name;
     }
     $name = trim($name, "\\/");
     $realPath = $this->tmp . '/' . $name;
     $this->files[$name] = true;
     if (file_exists($path)) {
         File::write($realPath, file_get_contents($path));
     } else {
         File::write($realPath, $path);
     }
 }
Example #11
0
<?php

use crodas\FileUtil\File;
require __DIR__ . "/../vendor/autoload.php";
@mkdir(__DIR__ . "/tmp");
foreach (glob(__DIR__ . "/tmp/*") as $delete) {
    echo "delete: {$delete}\n";
    unlink($delete);
}
File::overrideFilepathGenerator(function ($prefix) {
    return __DIR__ . '/tmp/';
});
function getConnection($cache = false)
{
    static $first;
    $conf = new \ActiveMongo2\Configuration(__DIR__ . "/tmp/mapper.php");
    $conf->addModelPath(__DIR__ . '/docs')->development();
    if (!empty($_SERVER["NAMESPACE"])) {
        if (!$first) {
            print "Using namespace {$_SERVER['NAMESPACE']}\n";
        }
        $conf->SetNamespace($_SERVER["NAMESPACE"]);
    }
    if (!$first) {
        $mongo = new MongoClient();
        $mongo->selectDB('activemongo2_tests')->drop();
        $mongo->selectDB('activemongo2_tests_foobar')->drop();
        $config = new ActiveMongo2\Configuration();
        unlink($config->getLoader());
    }
    if (empty($_SERVER["NAMESPACE"])) {
Example #12
0
 public function __construct($dir, $temporary = null, $prod = false)
 {
     $this->dir = $dir;
     $this->temp = $temporary ? $temporary : File::generateFilepath('validator', $dir);
     $this->prod = defined('DEVELOPMENT_MODE') ? DEVELOPMENT_MODE : $prod;
 }
Example #13
0
 public function __construct($className, $temporary = null)
 {
     $this->className = $className;
     $this->temp = $temporary ? $temporary : File::generateFilepath('validator', $className);
     $this->prod = !(defined('DEVELOPMENT_MODE') && DEVELOPMENT_MODE);
 }