Exemplo n.º 1
0
 /**
  * combines code from defined "document root relative" paths and returns path to destination file
  * @param array files
  */
 public function combine($files = array())
 {
     try {
         if (strlen(LBoxJSCombine) < 1) {
             throw new LBoxException("\$extOut: " . LBoxException::MSG_INSTANCE_VAR_STRING_NOTNULL, LBoxException::CODE_BAD_CLASS_VAR);
         }
         if (count($files) < 1) {
             throw new LBoxException(LBoxException::MSG_PARAM_ARRAY_NOTNULL, LBoxException::CODE_BAD_PARAM);
         }
         $sDocRoot = $_SERVER['DOCUMENT_ROOT'];
         $destination = $this->getPathDestination();
         LBoxUtil::createDirByPath($destination);
         // get and merge code
         $sCode = "";
         $aLastModifieds = array();
         foreach ($files as $file) {
             $file = LBOX_PATH_PROJECT . $file;
             $file = str_ireplace('project/project/', 'project/', $file);
             if (!file_exists($file)) {
                 throw new LBoxExceptionFilesystem("{$file}: " . LBoxExceptionFilesystem::MSG_FILE_NOT_EXISTS, LBoxExceptionFilesystem::CODE_FILE_NOT_EXISTS);
             }
             $aLastModifieds[] = filemtime($file);
             $sCode .= file_get_contents($file) . "\n";
         }
         // sort dates, newest first
         rsort($aLastModifieds);
         $fileName = md5($aLastModifieds[0]) . ".js";
         $destinationFile = "{$destination}/{$fileName}";
         // cache the data
         if (!file_exists($destinationFile)) {
             //LBoxFirePHP::warn("$destinationFile zatim NEexistuje - vytvarim novy");
             switch (LBoxConfigSystem::getInstance()->getParamByPath("output/js_compress")) {
                 case 1:
                     $sCode = $this->compress($sCode);
                     break;
                 case -1:
                     if (LBOX_REQUEST_IP != "127.0.0.1") {
                         $sCode = $this->compress($sCode);
                     }
                     break;
             }
             $sCode = "/*merged from files: " . implode($files, ",\n") . "*/" . $sCode;
             $fo = fopen($destinationFile, "w");
             fwrite($fo, $sCode);
             fclose($fo);
         } else {
             //LBoxFirePHP::log("$destinationFile uz existuje");
         }
         return str_replace(LBOX_PATH_PROJECT, "", $destinationFile);
     } catch (Exception $e) {
         throw $e;
     }
 }
 /**
  * getter na file path
  * @return string
  */
 protected function getFilePath()
 {
     try {
         if (strlen($this->pathDataSave) < 1) {
             throw new LBoxExceptionFormProcessor(LBoxExceptionFormProcessor::MSG_INSTANCE_VAR_STRING_NOTNULL, LBoxExceptionFormProcessor::CODE_BAD_INSTANCE_VAR);
         }
         $path = $this->pathDataSave;
         $path = str_replace("<project>", LBOX_PATH_PROJECT, $path);
         $path = LBoxUtil::fixPathSlashes($path);
         LBoxUtil::createDirByPath(dirname($path));
         return $path;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 3
0
 /**
  *
  * @return PHPTAL
  */
 protected function getTAL()
 {
     try {
         if (!$this->TAL instanceof PHPTAL) {
             $this->TAL = new PHPTAL($this->getPathTemplate());
         }
         $translator = new LBoxTranslator($this->getPathTemplate());
         // zajistit existenci ciloveho adresare PHP kodu pro TAL:
         $phptalPhpCodeDestination = LBoxUtil::fixPathSlashes(LBoxConfigSystem::getInstance()->getParamByPath("output/tal/PHPTAL_PHP_CODE_DESTINATION"));
         LBoxUtil::createDirByPath($phptalPhpCodeDestination);
         $this->TAL->setTranslator($translator);
         $this->TAL->setForceReparse(LBoxConfigSystem::getInstance()->getParamByPath("output/tal/PHPTAL_FORCE_REPARSE"));
         $this->TAL->setPhpCodeDestination($phptalPhpCodeDestination);
         $this->TAL->SELF = $this;
         return $this->TAL;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 4
0
/**
 * runs all defined tests
 * if tests directory contains coverage folder, it will generate coverage results there
 */
function run_tests()
{
    global $argv;
    // read test directory and run all tests
    $path = dirname(__FILE__) . '/tests';
    $dir = dir($path);
    $lime_output = new lime_output();
    $coverage = $coveragePath = '';
    $tests = array();
    while (($entry = $dir->read()) !== false) {
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        if (is_dir("{$path}/{$entry}")) {
            if ($entry == 'coverage') {
                $coveragePath = $path . '/' . $entry;
            }
            continue;
        }
        if (is_test($entry)) {
            $tests[getTestNameByPath("{$path}/{$entry}")] = "{$path}/{$entry}";
        }
    }
    // run concrete test
    if (($testName = $argv[1]) && can_param_be_test($testName)) {
        $testName .= 'Test';
        if (!array_key_exists($testName, $tests)) {
            $lime_output->error("cannot find test " . $argv[1] . ' in ' . $path);
            return;
        }
        if ($coveragePath) {
            $coveragePathConcrete = $coveragePath . '/' . $testName;
            LBoxUtil::createDirByPath($coveragePathConcrete);
            $coverage = '--coverage-html ' . $coveragePathConcrete . ' ';
            //$coverage			.=	' --coverage-clover '. $coveragePathConcrete . '/clover.xml ';
        }
        $path = $tests[$testName];
        $call = "phpunit {$coverage} {$path}";
        //$lime_output->info($call);
        $out = getCallReturn($call);
        if (preg_match('/OK \\((\\d+) test(s?)\\, (\\d+) assertion(s?)\\)/', $out, $matchAll)) {
            $lime_output->green_bar($testName);
        } else {
            $lime_output->red_bar($testName);
        }
        echo $out;
        if (strlen($coverage) > 0) {
            if (!doesContainErrorNotification($out)) {
                $lime_output->info("coverage results in {$coveragePath}");
            }
        }
        return;
    }
    // run all loaded tests
    if (count($tests) < 1) {
        $lime_output->comment('no test found in ' . $path);
        return;
    }
    $assertionsCountAtomic = 0;
    $testsCountAtomic = 0;
    foreach ($tests as $name => $path) {
        if ($coveragePath) {
            $coveragePathConcrete = $coveragePath . '/' . $name;
            LBoxUtil::createDirByPath($coveragePathConcrete);
            $coverage = '--coverage-html ' . $coveragePathConcrete . ' ';
            //$coverage			.=	' --coverage-clover '. $coveragePathConcrete . '/clover.xml ';
        }
        $call = "phpunit {$coverage} {$path}";
        //$lime_output->info($call);
        $out = getCallReturn($call);
        $space = '';
        if (preg_match('/OK \\((\\d+) test(s?)\\, (\\d+) assertion(s?)\\)/', $out, $matchAll)) {
            $i = 1;
            foreach ($matchAll as $k => $v) {
                if (is_numeric($v)) {
                    $match[$i] = $v;
                    $i++;
                }
            }
            $assertionsCountAtomic += $match[2];
            $testsCountAtomic += $match[1];
            $outPartName = $name . ' (' . $match[1] . ' tests, ' . $match[2] . ' assertions)';
            for ($i = 0; $i < 68 - strlen($outPartName); $i++) {
                $space .= ' ';
            }
            $lime_output->green_bar($outPartName . $space . 'OK ');
        } else {
            for ($i = 0; $i < 64 - strlen($name); $i++) {
                $space .= ' ';
            }
            $lime_output->red_bar($name . $space . 'FAILED ');
            echo $out;
        }
    }
    $lime_output->echoln("{$testsCountAtomic} tests, {$assertionsCountAtomic} assertions done", array('fg' => 'green'));
    if (strlen($coverage) > 0) {
        if (!doesContainErrorNotification($out)) {
            $lime_output->info("coverage results in {$coveragePath}");
        }
    }
    $dir->close();
}
Exemplo n.º 5
0
    die;
}
// firePHP debug
//LBoxFirePHP::log(LBoxConfigSystem::getInstance()->getParamByPath("metanodes/images/path"));
//LBoxFirePHP::table($_FILES['image'], "uploaded image data");
try {
    //////////////////////////////////////////////////////////////////////
    //	saving data
    //////////////////////////////////////////////////////////////////////
    if (strlen($tmpPath = $_FILES['image']['tmp_name']) > 0) {
        $imgName = $_FILES["image"]["name"];
        $userRecord = LBoxXTProject::isLogged() ? LBoxXTProject::getUserXTRecord() : LBoxXTDBFree::getUserXTRecord();
        $dirTarget = LBoxUtil::fixPathSlashes(LBoxConfigSystem::getInstance()->getParamByPath("metanodes/images/path") . SLASH . $userRecord->nick . SLASH . date("Ym"));
        $imgNameTarget = date("YmdHis") . "." . LBoxUtil::getExtByFilename($imgName);
        $imageURL = str_replace('\\', '/', LBoxUtil::fixPathSlashes(str_replace(LBOX_PATH_PROJECT, "", "{$dirTarget}/{$imgNameTarget}")));
        LBoxUtil::createDirByPath($dirTarget);
        if (!move_uploaded_file($tmpPath, "{$dirTarget}" . SLASH . "{$imgNameTarget}")) {
            throw new LBoxExceptionFilesystem(LBoxExceptionFilesystem::MSG_FILE_UPLOAD_ERROR, LBoxExceptionFilesystem::CODE_FILE_UPLOAD_ERROR);
        }
        $ret = new stdclass();
        // PHP base class
        $ret->status = "UPLOADED";
        $ret->image_url = $imageURL;
        header("HTTP/1.1 200 OK");
        header("content-type: text/html");
        die(json_encode($ret));
    }
} catch (Exception $e) {
    throwExceptionToFirePHP($e);
    $ret = new stdclass();
    // PHP base class