Beispiel #1
0
 function find($file)
 {
     foreach ($this->paths() as $loadPath) {
         $path = Path::join(array($loadPath, $file));
         if (file_exists($path)) {
             return $path;
         } else {
             foreach ($this->extensions() as $ext) {
                 if (file_exists($path . $ext)) {
                     return $path . $ext;
                 }
             }
         }
     }
     return false;
 }
Beispiel #2
0
 protected function getExtensions()
 {
     if (null === $this->extensions) {
         $basename = $this->getBasename();
         # Avoid treating name of a dotfile as extension by
         # ignoring dots at the first offset in the string
         if (!$basename or false === ($pos = strpos($basename, '.', 1))) {
             return array();
         }
         $extensions = explode('.', substr($basename, $pos + 1));
         $this->extensions = array_map(function ($ext) {
             return Path::normalizeExtension($ext);
         }, $extensions);
     }
     return $this->extensions;
 }
Beispiel #3
0
 protected function getExtension()
 {
     return Path::normalizeExtension(pathinfo($this->path, PATHINFO_EXTENSION));
 }
Beispiel #4
0
    $stub = <<<'EOF'
#!/usr/bin/env php
<?php

Phar::mapPhar('bob.phar');

require 'phar://bob.phar/bin/bootstrap.php';

__HALT_COMPILER();
EOF;
    $projectDir = \Bob::$application->projectDirectory;
    $phar = new \Phar($task->name, 0, basename($task->name));
    $phar->startBuffering();
    foreach ($task->prerequisites as $file) {
        $file = (string) $file;
        $phar->addFile($file, Path::relativize($file, $projectDir));
    }
    $phar->setStub($stub);
    $phar->stopBuffering();
    chmod($task->name, 0555);
    println(sprintf('Regenerated Archive "%s" with %d entries', basename($task->name), count($phar)));
    unset($phar);
});
desc('Does a system install of Bob, by default to /usr/local/bin');
task('install', array('bin/bob.phar'), function ($task) {
    $prefix = getenv('PREFIX') ?: '/usr/local';
    $success = copy('bin/bob.phar', "{$prefix}/bin/bob");
    chmod("{$prefix}/bin/bob", 0755);
    println(sprintf('Installed the `bob` executable in %s.', $prefix));
});
desc('Removes the `bob` excutable from the PREFIX');
Beispiel #5
0
 /**
  * Returns the content type for the extension, .e.g. "application/javascript"
  * for ".js".
  *
  * @param string $extension
  * @return string
  */
 function contentType($extension)
 {
     return @$this->contentTypes[FileUtils\Path::normalizeExtension($extension)];
 }
Beispiel #6
0
 function execute($tasks)
 {
     $this->prepareEnv();
     $tasks = (array) $tasks;
     $start = microtime(true);
     foreach ($tasks as $taskName) {
         if (!($task = $this['tasks'][$taskName])) {
             throw new \InvalidArgumentException(sprintf('Task "%s" not found.', $taskName));
         }
         $this['log']->info(sprintf('Running Task "%s"', $taskName));
         if ($this->projectDirectory) {
             Path::chdir($this->projectDirectory, array($task, 'invoke'));
         } else {
             $task->invoke();
         }
     }
     $this['log']->info(sprintf('Build finished in %f seconds', microtime(true) - $start));
 }
Beispiel #7
0
 static function normalizeExtension($extension)
 {
     return Path::normalizeExtension($extension);
 }
Beispiel #8
0
 /**
  * @dataProvider testRelativizeProvider
  */
 function testRelativize($expected, $absolute)
 {
     $this->assertEquals($expected, Path::relativize($absolute, __DIR__));
 }
Beispiel #9
0
Datei: Dsl.php Projekt: chh/bob
function cd($path, $callback = null)
{
    return Path::chdir($path, $callback);
}