Esempio n. 1
0
 public function httpGetInterceptor($method, $uri)
 {
     if ($method !== 'GET' || DevelopRequestHandler::getResponseMode() != 'json') {
         return true;
     }
     $pathParts = \Site::splitPath($uri);
     $rootPath = RootCollection::filterName($pathParts[0]);
     if (count($pathParts) && array_key_exists($rootPath, RootCollection::$siteDirectories)) {
         $className = RootCollection::$siteDirectories[$rootPath];
         $node = new $className($pathParts[0]);
         if (count($pathParts) > 1) {
             $node = $node->resolvePath(array_splice($pathParts, 1));
         }
     } else {
         $node = \Site::resolvePath($uri, false);
     }
     if (!$node) {
         throw new \Sabre\DAV\Exception\FileNotFound();
     }
     $children = array();
     foreach ($node->getChildren() as $child) {
         $children[] = $child->getData();
     }
     $this->server->httpResponse->sendStatus(200);
     $this->server->httpResponse->setHeader('Content-Type', 'application/json');
     $this->server->httpResponse->sendBody(json_encode(array('path' => $uri, 'children' => $children)));
     return false;
 }
 public static function handleRequest()
 {
     // build file path
     $filePath = Site::$pathStack;
     array_unshift($filePath, static::$libraryCollection);
     // try to get node
     $fileNode = Site::resolvePath($filePath);
     if ($fileNode) {
         $fileNode->outputAsResponse();
     } else {
         Site::respondNotFound('Resource not found');
     }
 }
Esempio n. 3
0
 public function loadPlugin($pluginName, $forceRehash = true)
 {
     if ($pluginName == 'array') {
         $pluginName = 'helper.array';
     }
     foreach (static::$searchPaths as $path) {
         if ($pluginNode = \Site::resolvePath("dwoo-plugins/{$path}{$pluginName}.php")) {
             break;
         }
     }
     if ($pluginNode && file_exists($pluginNode->RealPath)) {
         require $pluginNode->RealPath;
     } else {
         throw new \Dwoo_Exception('Plugin "' . $pluginName . '" can not be found in the Emergence VFS.');
     }
 }
 public static function handleRequest()
 {
     if (!($accessKey = Site::getHostConfig('AccessKey'))) {
         Site::respondUnauthorized('Remote emergence access is disabled');
     } elseif (empty($_REQUEST['accessKey']) || $_REQUEST['accessKey'] != $accessKey) {
         Site::respondUnauthorized('Remote emergence access denied');
     }
     //Debug::dumpVar(Site::$requestPath, false);
     //Debug::dumpVar(Site::$pathStack, false);
     if ($node = Site::resolvePath(Site::$pathStack, false)) {
         //Debug::dumpVar($node);
         //header('X-Emergence-Site-ID: '.static::$ID);
         if (method_exists($node, 'outputAsResponse')) {
             $node->outputAsResponse();
         } else {
             Site::respondBadRequest();
         }
     } else {
         Site::respondNotFound('File not found');
     }
 }
 public static function handleRequest()
 {
     if (extension_loaded('newrelic')) {
         newrelic_disable_autorum();
     }
     if (!Site::getConfig('inheritance_key')) {
         Site::respondUnauthorized('Remote emergence access is disabled');
     } elseif (empty($_REQUEST['accessKey']) || $_REQUEST['accessKey'] != Site::getConfig('inheritance_key')) {
         // attempt to authenticate via developer session
         if (!UserSession::getFromRequest()->hasAccountLevel('Developer')) {
             Site::respondUnauthorized('Remote emergence access denied');
         }
     }
     if ($_REQUEST['remote'] == 'parent') {
         set_time_limit(1800);
         $remoteParams = array();
         if (!empty($_REQUEST['exclude'])) {
             $remoteParams['exclude'] = $_REQUEST['exclude'];
         }
         HttpProxy::relayRequest(array('url' => static::buildUrl(Site::$pathStack, $remoteParams), 'autoAppend' => false, 'autoQuery' => false, 'timeout' => 500));
     }
     if (empty(Site::$pathStack[0])) {
         return static::handleTreeRequest();
     } elseif ($node = Site::resolvePath(Site::$pathStack)) {
         if (method_exists($node, 'outputAsResponse')) {
             $node->outputAsResponse(true);
         } elseif (is_a($node, 'SiteCollection')) {
             return static::handleTreeRequest($node);
         } else {
             Site::respondBadRequest();
         }
     } else {
         header('HTTP/1.0 404 Not Found');
         die('File not found');
     }
 }
Esempio n. 6
0
// check if there is an existing repo
if (!is_dir("{$repoPath}/.git")) {
    die("{$repoPath} does not contain .git");
}
// get repo
chdir($repoPath);
// sync trees
foreach ($repoCfg['trees'] as $srcPath => $treeOptions) {
    if (is_string($treeOptions)) {
        $treeOptions = array('path' => $treeOptions);
    }
    $treeOptions = array_merge($exportOptions, $treeOptions, ['dataPath' => false]);
    if (!is_string($srcPath)) {
        $srcPath = $treeOptions['path'];
    } elseif (!$treeOptions['path']) {
        $treeOptions['path'] = $srcPath;
    }
    $srcFileNode = Site::resolvePath($srcPath);
    if (is_a($srcFileNode, 'SiteFile')) {
        $destDir = dirname($treeOptions['path']);
        if ($destDir && !is_dir($destDir)) {
            mkdir($destDir, 0777, true);
        }
        copy($srcFileNode->RealPath, $treeOptions['path']);
        Benchmark::mark("exported file {$srcPath} to {$treeOptions['path']}");
    } else {
        $exportResult = Emergence_FS::exportTree($srcPath, $treeOptions['path'], $treeOptions);
        Benchmark::mark("exported directory {$srcPath} to {$treeOptions['path']}: " . http_build_query($exportResult));
    }
}
Benchmark::mark("wrote all changes");
Esempio n. 7
0
Benchmark::mark("exported {$appPath} to {$appTmpPath}: " . http_build_query($exportResult));
// ... last production build
mkdir($buildTmpPath, 0777, true);
$exportResult = Emergence_FS::exportTree($buildPath, $buildTmpPath);
Benchmark::mark("exported {$buildPath} to {$buildTmpPath}: " . http_build_query($exportResult));
// write any libraries from classpath
$classPaths = explode(',', $App->getBuildCfg('app.classpath'));
foreach ($classPaths as $classPath) {
    if (strpos($classPath, '${workspace.dir}/x/') === 0) {
        $extensionPath = substr($classPath, 19);
        $classPathSource = "ext-library/{$extensionPath}";
        $classPathDest = "{$tmpPath}/x/{$extensionPath}";
        Benchmark::mark("importing classPathSource: {$classPathSource}");
        #		$cachedFiles = Emergence_FS::cacheTree($classPathSource);
        #		Benchmark::mark("precached $cachedFiles files in $classPathSource");
        $sourceNode = Site::resolvePath($classPathSource);
        if (is_a($sourceNode, SiteFile)) {
            mkdir(dirname($classPathDest), 0777, true);
            copy($sourceNode->RealPath, $classPathDest);
            Benchmark::mark("copied file {$classPathSource} to {$classPathDest}");
        } else {
            $exportResult = Emergence_FS::exportTree($classPathSource, $classPathDest);
            Benchmark::mark("exported {$classPathSource} to {$classPathDest}: " . http_build_query($exportResult));
        }
    }
}
// write archive
if (!empty($_GET['archive'])) {
    try {
        $exportResult = Emergence_FS::exportTree($archivePath, $archiveTmpPath);
        Benchmark::mark("exported {$archivePath} to {$archiveTmpPath}: " . http_build_query($exportResult));
 public static function getSourceNodes($paths, $root, $contentType = null)
 {
     $paths = static::splitMultipath($paths);
     if (is_string($root)) {
         $root = Site::splitPath($root);
     }
     $sourceFiles = array();
     foreach ($paths as $path) {
         $path = array_merge($root, $path);
         list($filename) = array_slice($path, -1);
         if ($filename == '*') {
             array_pop($path);
             Emergence_FS::cacheTree($path);
             foreach (Emergence_FS::getTreeFiles($path, false, $contentType ? array('Type' => $contentType) : null) as $path => $fileData) {
                 $sourceFiles[$path] = $fileData;
             }
         } else {
             $node = Site::resolvePath($path);
             if (!$node || !is_a($node, 'SiteFile')) {
                 throw new Exception('Source file "' . implode('/', $path) . '" does not exist', self::ERROR_NOT_FOUND);
             }
             if ($node->Type != $contentType) {
                 throw new Exception('Source file "' . implode('/', $path) . '" does not match requested content type "' . $contentType . '"', self::ERROR_TYPE_MISMATCH);
             }
             $sourceFiles[join('/', $path)] = array('ID' => $node->ID, 'SHA1' => $node->SHA1);
         }
     }
     return $sourceFiles;
 }
Esempio n. 9
0
<?php

$GLOBALS['Session']->requireAccountLevel('Developer');
set_time_limit(0);
RequestHandler::$responseMode = 'json';
if (empty($_REQUEST['path'])) {
    RequestHandler::throwError('path required');
}
if (empty($_REQUEST['host'])) {
    RequestHandler::throwError('host required');
}
if (!($sourceCollection = Site::resolvePath($_REQUEST['path']))) {
    RequestHandler::throwError('path not found locally');
}
// create stream context for remote server
$syncer = new EmergenceSyncer(array('host' => $_REQUEST['host'], 'authUsername' => $_SERVER['PHP_AUTH_USER'], 'authPassword' => $_SERVER['PHP_AUTH_PW']));
$diff = $syncer->diffCollection($sourceCollection, !empty($_REQUEST['deep']));
if (empty($_REQUEST['push'])) {
    RequestHandler::respond('diff', array('diff' => $diff));
} else {
    $result = $syncer->pushDiff($diff);
    RequestHandler::respond('pushComplete', array('result' => $result));
}
Esempio n. 10
0
$repo->git("pull origin {$repoCfg['workingBranch']}");
Benchmark::mark("pulled from origin/{$repoCfg['workingBranch']}");
// sync trees
foreach ($repoCfg['trees'] as $srcPath => $treeOptions) {
    if (is_string($treeOptions)) {
        $treeOptions = array('path' => $treeOptions);
    }
    if (!is_string($srcPath)) {
        $srcPath = $treeOptions['path'];
    } elseif (!$treeOptions['path']) {
        $treeOptions['path'] = $srcPath;
    }
    $treeOptions['exclude'][] = '#(^|/)\\.git(/|$)#';
    if (is_file($treeOptions['path'])) {
        $sha1 = sha1_file($treeOptions['path']);
        $existingNode = Site::resolvePath($srcPath);
        if (!$existingNode || $existingNode->SHA1 != $sha1) {
            $fileRecord = SiteFile::createFromPath($srcPath, null, $existingNode ? $existingNode->ID : null);
            SiteFile::saveRecordData($fileRecord, fopen($treeOptions['path'], 'r'), $sha1);
            Benchmark::mark("importing file {$srcPath} from {$treeOptions['path']}");
        } else {
            Benchmark::mark("skipped unchanged file {$srcPath} from {$treeOptions['path']}");
        }
    } else {
        $cachedFiles = Emergence_FS::cacheTree($srcPath);
        Benchmark::mark("precached {$srcPath}: " . $cachedFiles);
        $exportResult = Emergence_FS::importTree($treeOptions['path'], $srcPath, $treeOptions);
        Benchmark::mark("importing directory {$srcPath} from {$treeOptions['path']}: " . http_build_query($exportResult));
    }
}
// commit changes
Esempio n. 11
0
 public function getAsset($filePath, $useCache = true)
 {
     if (is_string($filePath)) {
         $filePath = Site::splitPath($filePath);
     }
     $appName = $this->getName();
     $framework = $this->getFramework();
     $frameworkVersion = $this->getFrameworkVersion();
     if ($filePath[0] == 'x') {
         array_shift($filePath);
         array_unshift($filePath, 'ext-library');
     } elseif ($filePath[0] == 'sdk' || $filePath[0] == $framework) {
         array_shift($filePath);
         array_unshift($filePath, 'sencha-workspace', "{$framework}-{$frameworkVersion}");
     } elseif ($filePath[0] == 'packages') {
         array_shift($filePath);
         array_unshift($filePath, 'sencha-workspace', 'packages');
     } elseif ($filePath[0] == 'microloaders') {
         array_shift($filePath);
         array_unshift($filePath, 'sencha-workspace', 'microloaders', $framework);
     } elseif ($filePath[0] == 'build') {
         if ($filePath[1] == 'sdk' || $filePath[1] == $framework) {
             array_shift($filePath);
             array_shift($filePath);
             array_unshift($filePath, 'sencha-workspace', "{$framework}-{$frameworkVersion}");
         } else {
             array_shift($filePath);
             array_unshift($filePath, 'sencha-build', $appName);
         }
     } else {
         array_unshift($filePath, 'sencha-workspace', $appName);
     }
     return Site::resolvePath($filePath, true, $useCache);
 }
<?php

$GLOBALS['Session']->requireAccountLevel('Developer');
$requestData = JSON::getRequestData();
if (!is_array($requestData['nodes'])) {
    JSON::error('Expecting array under nodes key');
}
// TODO: something more elegant to prevent non-specified classes from being inherited?
Site::$autoPull = true;
$succeeded = array();
$failed = array();
foreach ($requestData['nodes'] as $updateData) {
    $Node = Site::resolvePath($updateData['path']);
    if ($Node->Collection->Site == 'Local') {
        $failed[] = array('path' => $updateData['path'], 'error' => 'CURRENT_IS_LOCAL', 'message' => 'Current node is local and blocks any remote updates');
        continue;
    }
    if ($Node->SHA1 != $updateData['localSHA1']) {
        $failed[] = array('path' => $updateData['path'], 'error' => 'LOCAL_SHA1_MISMATCH', 'message' => 'Current node\'s SHA1 hash does not match that which this update was requested for');
        continue;
    }
    if (empty($updateData['remoteSHA1'])) {
        $Node->delete();
    } else {
        $NewNode = Emergence::resolveFileFromParent($Node->Collection, $Node->Handle, true);
        if (!$NewNode) {
            $failed[] = array('path' => $updateData['path'], 'error' => 'DOWNLOAD_FAILED', 'message' => 'The remote file failed to download');
            continue;
        }
        if ($NewNode->SHA1 != $updateData['remoteSHA1']) {
            $NewNode->destroyRecord();
 public static function handleCacheManifestRequest(Sencha_App $App)
 {
     $templateNode = Emergence\Dwoo\Template::findNode($App->getFramework() . '.tpl');
     $cacheConfig = $App->getAppCfg('appCache');
     header('Content-Type: text/cache-manifest');
     echo "CACHE MANIFEST\n";
     echo "# {$templateNode->SHA1}\n";
     if (!empty($cacheConfig['cache']) && is_array($cacheConfig['cache'])) {
         foreach ($cacheConfig['cache'] as $path) {
             if ($path != 'index.html') {
                 $path = "build/production/{$path}";
                 echo "{$path}\n";
                 if ($assetNode = $App->getAsset($path)) {
                     echo "#{$assetNode->SHA1}\n";
                 }
             }
         }
     }
     if (!empty($_GET['platform']) && !empty($cacheConfig['platformCache']) && !empty($cacheConfig['platformCache'][$_GET['platform']]) && is_array($cacheConfig['platformCache'][$_GET['platform']])) {
         echo "\n# {$_GET['platform']}:\n";
         foreach ($cacheConfig['platformCache'][$_GET['platform']] as $path) {
             $path = "build/production/{$path}";
             if ($assetNode = $App->getAsset($path)) {
                 echo "{$path}\n";
                 echo "#{$assetNode->SHA1}\n";
             }
         }
     }
     echo "\nFALLBACK:\n";
     if (!empty($cacheConfig['fallback']) && is_array($cacheConfig['fallback'])) {
         foreach ($cacheConfig['fallback'] as $path) {
             echo "{$path}\n";
         }
     }
     echo "\nNETWORK:\n";
     if (!empty($cacheConfig['network']) && is_array($cacheConfig['network'])) {
         foreach ($cacheConfig['network'] as $path) {
             echo "{$path}\n";
         }
     }
     echo "\n# TRIGGERS:\n";
     $templateNode = Emergence\Dwoo\Template::findNode($App->getFramework() . '.tpl');
     echo "#template: {$templateNode->SHA1}\n";
     if (!empty($cacheConfig['triggers']) && is_array($cacheConfig['triggers'])) {
         foreach ($cacheConfig['triggers'] as $path) {
             $assetNode = $path[0] == '/' ? Site::resolvePath($path) : $App->getAsset($path);
             if ($assetNode) {
                 echo "#{$assetNode->SHA1}\n";
             }
         }
     }
     exit;
 }
Esempio n. 14
0
 public static function getWorkspaceCfg($key = null)
 {
     if (!static::$_workspaceCfg) {
         // get from filesystem
         $configPath = array('sencha-workspace', '.sencha', 'workspace', 'sencha.cfg');
         if ($configNode = Site::resolvePath($configPath, true, false)) {
             static::$_workspaceCfg = Sencha::loadProperties($configNode->RealPath);
         } else {
             static::$_workspaceCfg = array();
         }
     }
     return $key ? static::$_workspaceCfg[$key] : static::$_workspaceCfg;
 }
Esempio n. 15
0
<?php

if ($_SERVER['REQUEST_METHOD'] != 'POST') {
    die('POST method required');
}
$GLOBALS['Session']->requireAccountLevel('Developer');
set_time_limit(0);
Benchmark::startLive();
// get requested test suite
$testSuite = empty($_GET['suite']) ? 'emergence.read-only' : $_GET['suite'];
// set paths
$testsPath = "phpunit-tests";
$suitePath = "{$testsPath}/{$testSuite}";
if (!Site::resolvePath($suitePath)) {
    die('Requested test suite not found');
}
// get temporary directory and set paths
$tmpPath = Emergence_FS::getTmpDir();
$suiteTmpPath = "{$tmpPath}/{$testSuite}";
$configTmpPath = "{$tmpPath}/phpunit.xml";
Benchmark::mark("created tmp: {$tmpPath}");
// export tests
Emergence_FS::cacheTree($suitePath);
$exportResult = Emergence_FS::exportTree($suitePath, $suiteTmpPath);
Benchmark::mark("exported {$suitePath} to {$suiteTmpPath}: " . http_build_query($exportResult));
// write phpunit configuration
$timezone = date_default_timezone_get();
// bootstrap path
$bootstrapPath = dirname($_SERVER['SCRIPT_FILENAME']) . '/phpunit.php';
file_put_contents($configTmpPath, <<<EOT
<?xml version="1.0" encoding="UTF-8" ?>
 public static function importFile($sourcePath, $destinationPath)
 {
     if (!file_exists($sourcePath)) {
         return false;
     }
     $existingNode = Site::resolvePath($destinationPath);
     // calculate hash for incoming file
     $sha1 = sha1_file($sourcePath);
     // skip if existing local or remote file matches hash
     if (!$existingNode || $existingNode->SHA1 != $sha1) {
         // use lower level create methods to supply already-calculated hash
         $fileRecord = SiteFile::createFromPath($destinationPath, null, $existingNode ? $existingNode->ID : null);
         return SiteFile::saveRecordData($fileRecord, fopen($sourcePath, 'r'), $sha1);
     }
     return false;
 }
Esempio n. 17
0
function Dwoo_Plugin_sencha_bootstrap(Dwoo_Core $dwoo, $App = null, $classPaths = array(), $packages = array(), $patchLoader = true, $framework = 'ext', $frameworkVersion = null, $packageRequirers = null)
{
    // retrieve app if available
    if (!$App) {
        $App = $dwoo->data['App'];
    }
    // load workspace classpaths
    $classPaths = array_merge($classPaths, explode(',', Sencha::getWorkspaceCfg('workspace.classpath')));
    // if app provided, load classpaths and packages
    if ($App) {
        $framework = $App->getFramework();
        $frameworkVersion = $App->getFrameworkVersion();
        $appPath = 'sencha-workspace/' . $App->getName();
        // recursively merge app's required packages and their required packages into packages list
        $packages = array_merge($packages, $App->getRequiredPackages(false));
        // false to skip crawling decendents, we'll do it here later
        // add theme to packages list
        if ($themeName = $App->getBuildCfg('app.theme')) {
            $packages[] = $themeName;
        }
        // include classpath files
        $classPaths = array_merge($classPaths, explode(',', $App->getBuildCfg('app.classpath')));
        // include override files
        if ($overridesPath = $App->getBuildCfg('app.overrides')) {
            $classPaths = array_merge($classPaths, explode(',', $overridesPath));
        }
    }
    // pull package requirements from source files
    if (!empty($packageRequirers)) {
        if (is_string($packageRequirers)) {
            $packageRequirers = array($packageRequirers);
        }
        foreach ($packageRequirers as $packageRequirer) {
            if ($sourceNode = Site::resolvePath($packageRequirer)) {
                $packages = array_merge($packages, Sencha::getRequiredPackagesForSourceFile($sourceNode->RealPath));
            }
        }
    }
    // apply default framework version and normalize
    if (!$frameworkVersion) {
        $frameworkVersion = Sencha::$frameworks[$framework]['defaultVersion'];
    }
    $frameworkVersion = Sencha::normalizeFrameworkVersion($framework, $frameworkVersion);
    $frameworkPath = "sencha-workspace/{$framework}-{$frameworkVersion}";
    // initialize output state
    $manifest = array();
    $autoLoadPaths = array();
    // set framework path if patching loader
    if ($patchLoader) {
        $manifest['Ext'] = "/app/{$framework}-{$frameworkVersion}/src";
    }
    // add paths for packages
    $packages = array_unique(Sencha::crawlRequiredPackages(array_unique($packages), $framework, $frameworkVersion));
    foreach ($packages as $packageName) {
        // check workspace and framework package dirs
        $packagePath = "sencha-workspace/packages/{$packageName}";
        if (!Site::resolvePath($packagePath)) {
            $packagePath = "{$frameworkPath}/packages/{$packageName}";
            if (!Site::resolvePath($packagePath)) {
                throw new Exception("Source for package {$packageName} not found in workspace or framework");
            }
        }
        array_push($classPaths, "{$packagePath}/src", "{$packagePath}/overrides");
    }
    // include classpaths from packages
    $classPaths = array_merge($classPaths, Sencha::aggregateClassPathsForPackages($packages));
    // filter classpaths
    $classPaths = array_unique(array_filter($classPaths));
    // build list of all source trees, resolving CMD variables and children
    $sources = array();
    foreach ($classPaths as $classPath) {
        if (strpos($classPath, '${workspace.dir}/x/') === 0) {
            $classPath = substr($classPath, 19);
            $manifest[str_replace('/', '.', $classPath)] = '/app/x/' . $classPath;
            $classPath = 'ext-library/' . $classPath;
        } elseif (strpos($classPath, 'ext-library/') === 0) {
            $classPath = substr($classPath, 12);
            $manifest[str_replace('/', '.', $classPath)] = '/app/x/' . $classPath;
            $classPath = 'ext-library/' . $classPath;
        } elseif (strpos($classPath, '${app.dir}/') === 0) {
            $classPath = $appPath . substr($classPath, 10);
        } elseif (strpos($classPath, '${ext.dir}/') === 0) {
            $classPath = $frameworkPath . substr($classPath, 10);
        } elseif (strpos($classPath, '${touch.dir}/') === 0) {
            $classPath = $frameworkPath . substr($classPath, 12);
        }
        Emergence_FS::cacheTree($classPath);
        $sources = array_merge($sources, Emergence_FS::getTreeFiles($classPath, false, array('Type' => 'application/javascript')));
    }
    // skip patching loader if manifest will be empty
    if (empty($sources)) {
        return '';
    }
    // process all source files and build manifest and list of classes to automatically load
    foreach ($sources as $path => &$source) {
        $autoLoad = false;
        $addToManifest = true;
        // rewrite path to canonican external URL
        if ($appPath && strpos($path, "{$appPath}/") === 0) {
            $webPath = '/app/' . substr($path, 17);
            // app overrides should automatically be loaded
            if (substr($path, strlen($appPath), 11) == '/overrides/') {
                $autoLoad = true;
                $addToManifest = false;
            }
        } elseif (strpos($path, 'ext-library/') === 0) {
            $webPath = '/app/x' . substr($path, 11);
        } elseif (strpos($path, 'sencha-workspace/packages/') === 0) {
            $webPath = '/app/' . substr($path, 17);
            // package overrides should automatically be loaded
            if (substr($path, strpos($path, '/', 26), 11) == '/overrides/') {
                $autoLoad = true;
                $addToManifest = false;
            }
        } elseif (strpos($path, $frameworkPath) === 0) {
            $webPath = "/app/{$framework}-{$frameworkVersion}/" . substr($path, strlen($frameworkPath) + 1);
            // package overrides should automatically be loaded
            if (substr($path, strpos($path, '/', strlen($frameworkPath) + 10), 11) == '/overrides/') {
                $autoLoad = true;
                $addToManifest = false;
            }
        } elseif (strpos($path, 'sencha-workspace/pages/') === 0) {
            $webPath = '/app/' . substr($path, 17);
        } elseif (strpos($path, $frameworkPath) === 0) {
            $webPath = '/app/' . substr($path, 17);
        } else {
            // this class was not in a recognized externally loadable collection
            continue;
        }
        // discover class name
        $sourceCacheKey = "sencha-class-name/{$source['SHA1']}";
        if (!($source['Class'] = Cache::fetch($sourceCacheKey))) {
            $sourceNode = Site::resolvePath($path);
            $sourceReadHandle = $sourceNode->get();
            while (($line = fgets($sourceReadHandle, 4096)) !== false) {
                if (preg_match('/^\\s*(Ext\\.define\\(\\s*([\'"])([^\\2]+)\\2|\\/\\/\\s*@define[ \\t]+(\\S+))/i', $line, $matches)) {
                    $source['Class'] = empty($matches[4]) ? $matches[3] : $matches[4];
                    break;
                }
            }
            fclose($sourceReadHandle);
            // cache class name
            Cache::store($sourceCacheKey, $source['Class']);
        }
        // skip if class name could not be determined
        if (!$source['Class']) {
            continue;
        }
        // apply fingerprint signature to path
        $webPath = "{$webPath}?_sha1={$source['SHA1']}";
        // map class name to path
        if ($addToManifest) {
            $manifest[$source['Class']] = $webPath;
        }
        // add path to autoLoad list
        if ($autoLoad) {
            $autoLoadPaths[] = $webPath;
        }
    }
    // build loader overrides
    $loaderPatch = '';
    if ($patchLoader) {
        $loaderPatch .= 'Ext.Loader.setConfig("disableCaching", false);';
        $loaderPatch .= 'function _versionScriptUrl(url) {' . 'if (url[0] != "/") {' . 'url = window.location.pathname + url;' . 'while (url.match(/\\/\\.\\.\\//)) url = url.replace(/\\/[^\\/]+\\/\\.\\./g, "");' . '}' . 'if(!url.match(/\\?_sha1=/)) {' . 'console.warn("Fingerprinted URL not found for %o, it will be loaded with a cache-buster", url);' . 'url += "?" + dcParam + "=" + now;' . '}' . 'return url;' . '}';
        $loaderPatch .= 'function _overrideMethod(cls, method, override) {' . 'var parent = cls[method] || Ext.emptyFn;' . 'cls[method] = function() {' . 'var me = this;' . 'callArgs = Array.prototype.slice.call(arguments, 0);' . 'callArgs.unshift(function() {' . 'parent.apply(me, arguments);' . '});' . 'return override.apply(this, callArgs);' . '};' . '}';
        #        if (Sencha::isVersionNewer('5', $frameworkVersion)) {
        if ($framework == 'ext') {
            $loaderPatch .= '_overrideMethod(Ext.Loader, "loadScript", function(parent, options) {' . 'if (typeof options == "string") {' . 'options = _versionScriptUrl(options);' . '} else {' . 'options.url = _versionScriptUrl(options.url);' . '}' . 'return parent(options);' . '});';
        } else {
            $loaderPatch .= '_overrideMethod(Ext.Loader, "loadScriptFile", function(parent, url, onLoad, onError, scope, synchronous) {' . 'return parent(_versionScriptUrl(url), onLoad, onError, scope, synchronous);' . '});';
        }
    }
    // output loader patch and manifest
    return '<script type="text/javascript">(function(){' . 'var dcParam = Ext.Loader.getConfig("disableCachingParam")' . ',now = Ext.Date.now();' . $loaderPatch . 'Ext.Loader.addClassPathMappings(' . json_encode($manifest) . ');' . '})()</script>' . (count($autoLoadPaths) ? implode('', array_map(function ($url) {
        return '<script type="text/javascript" src="' . $url . '"></script>';
    }, $autoLoadPaths)) : '');
}
Esempio n. 18
0
 public static function getBlankPath($contextClass)
 {
     $node = Site::resolvePath(static::$iconPath);
     return $node ? $node->RealPath : null;
 }
Esempio n. 19
0
 public static function loadConfig($className)
 {
     $cacheKey = 'class-config:' . $className;
     if (!($configFileIds = Cache::fetch($cacheKey))) {
         $configFileIds = array();
         // look for primary config file
         if ($lastNsPos = strrpos($className, '\\')) {
             $namespace = substr($className, 0, $lastNsPos);
             $className = substr($className, $lastNsPos + 1);
             $path = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
         } else {
             $path = '';
         }
         $path .= str_replace('_', DIRECTORY_SEPARATOR, $className);
         $configFileNode = Site::resolvePath("php-config/{$path}.config.php");
         // Fall back on looking for Old_School_Underscore_Namespacing in root
         if (!$configFileNode && empty($namespace) && $path != $className) {
             $configFileNode = Site::resolvePath("php-config/{$className}.config.php");
         }
         if ($configFileNode && $configFileNode->MIMEType == 'application/php') {
             $configFileIds[] = $configFileNode->ID;
         }
         // look for composite config files
         $collectionPath = "php-config/{$path}.config.d";
         Emergence_FS::cacheTree($collectionPath);
         foreach (Emergence_FS::getAggregateChildren($collectionPath) as $filename => $node) {
             if ($node->Type == 'application/php') {
                 $configFileIds[] = $node->ID;
             }
         }
         Cache::store($cacheKey, $configFileIds);
     }
     foreach ($configFileIds as $id) {
         require SiteFile::getRealPathByID($id);
     }
 }
Esempio n. 20
0
 public static function getBlankPath($contextClass)
 {
     $path = array('site-root', 'img', sprintf(static::$defaultFilenameFormat, $contextClass));
     if ($node = Site::resolvePath($path)) {
         return $node->RealPath;
     } else {
         throw new Exception('Could not load ' . implode('/', $path));
     }
 }
Esempio n. 21
0
 protected function getFaceListFromClassifier($classifier)
 {
     $faceList = face_detect($this->imagePath, Site::resolvePath('php-classes/stojg/crop' . $classifier)->RealPath);
     return $faceList;
 }