public static function handleFrameworkRequest($framework, $version = null)
 {
     if (!$version) {
         $version = Sencha::$frameworks[$framework]['defaultVersion'];
     }
     $version = Sencha::normalizeFrameworkVersion($framework, $version);
     $filePath = static::getPath();
     array_unshift($filePath, 'sencha-workspace', "{$framework}-{$version}");
     if ($fileNode = Site::resolvePath($filePath)) {
         $fileNode->outputAsResponse();
     } else {
         return static::throwNotFoundError('Framework asset not found');
     }
 }
Example #2
0
 public static function getVersionedFrameworkPath($framework, $filePath, $version = null)
 {
     if (!$version) {
         $version = Sencha::$frameworks[$framework]['defaultVersion'];
     }
     $version = Sencha::normalizeFrameworkVersion($framework, $version);
     if (is_string($filePath)) {
         $filePath = Site::splitPath($filePath);
     }
     $assetPath = Sencha_RequestHandler::$externalRoot . '/' . $framework . '-' . $version . '/' . implode('/', $filePath);
     array_unshift($filePath, 'sencha-workspace', "{$framework}-{$version}");
     $Asset = Site::resolvePath($filePath);
     if ($Asset) {
         return $assetPath . '?_sha1=' . $Asset->SHA1;
     } else {
         return $assetPath;
     }
 }
Example #3
0
$GLOBALS['Session']->requireAccountLevel('Developer');
set_time_limit(0);
Benchmark::startLive();
// get app name
if (empty($_REQUEST['name'])) {
    die('Parameter name required');
}
$appName = $_REQUEST['name'];
// get framework
if (empty($_REQUEST['framework']) || !array_key_exists($_REQUEST['framework'], Sencha::$frameworks)) {
    die('Parameter framework required');
}
$framework = $_REQUEST['framework'];
// get framework version
$frameworkVersion = Sencha::normalizeFrameworkVersion($framework, empty($_REQUEST['frameworkVersion']) ? Sencha::$frameworks[$framework]['defaultVersion'] : $_REQUEST['frameworkVersion']);
Benchmark::mark("configured request: appName={$appName}, framework={$framework}, frameworkVersion={$frameworkVersion}");
// get temporary directory
$tmpPath = Emergence_FS::getTmpDir();
$tmpConfigPath = "{$tmpPath}/.sencha";
$tmpFrameworkPath = "{$tmpPath}/{$framework}";
Benchmark::mark("created tmp: {$tmpPath}");
$workspacePath = 'sencha-workspace';
$workspaceConfigPath = "{$workspacePath}/.sencha";
$workspaceFrameworkPath = "{$workspacePath}/{$framework}-{$frameworkVersion}";
// precache framework and workspace config
$cachedFiles = Emergence_FS::cacheTree($workspaceConfigPath);
Benchmark::mark("precached {$workspaceConfigPath}");
$cachedFiles = Emergence_FS::cacheTree($workspaceFrameworkPath);
Benchmark::mark("precached {$workspaceFrameworkPath}");
// write workspace to tmp
 public function getFrameworkVersion()
 {
     return Sencha::normalizeFrameworkVersion($this->getFramework(), $this->getBuildCfg('app.framework.version'));
 }
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)) : '');
}
Example #6
0
 * // @require-package my-package-name
 * ````
 * 
 * TODO:
 * - For packages required by pages, all files within all packages' overrides folder should be automatically included in that page's build
 *
 */
$GLOBALS['Session']->requireAccountLevel('Developer');
set_time_limit(0);
if (empty($_GET['dumpWorkspace'])) {
    Benchmark::startLive();
}
// load build cfg
$buildConfig = Sencha::loadProperties(Site::resolvePath('sencha-workspace/pages/.sencha/workspace/sencha.cfg')->RealPath);
$framework = $buildConfig['pages.framework'];
$frameworkVersion = Sencha::normalizeFrameworkVersion($framework, $buildConfig['pages.framework.version']);
$cmdVersion = $buildConfig['workspace.cmd.version'];
if (!$framework) {
    die("app.framework not found in sencha.cfg");
}
// set paths
$pagesPath = 'sencha-workspace/pages';
$frameworkPath = "sencha-workspace/{$framework}-{$frameworkVersion}";
// get temporary directory and set paths
$tmpPath = Emergence_FS::getTmpDir();
Benchmark::mark("created tmp: {$tmpPath}");
// change into tmpPath
chdir($tmpPath);
Benchmark::mark("chdir to: {$tmpPath}");
// precache and write pages
$cachedFiles = Emergence_FS::cacheTree($pagesPath);