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'); } }
<?php $currentPath = explode('/', __FILE__); $basePath = implode("/", array_slice($currentPath, 0, count($currentPath) - 3)); require_once $basePath . "/sencha2/init.php"; // Add class areas to the class loader Sencha::references(array('examples' => 'app examples mvc', 'sencha2' => 'mvc widgets validators cache')); // Initalise sencha and the url parser $settings = new ex_Settings(); Sencha::initApp($settings); Sencha::app__setUrlParser('urlparser_Gyokuro'); // Execute sencha Sencha::app__go('/cron/stand_alone_script/'); // Render the processed output Sencha::app__render(); // Render debug if required if ($settings->get_debug) { Sencha::app__renderDebug(); }
Benchmark::mark("precached {$appPath}"); $exportResult = Emergence_FS::exportTree($appPath, $appTmpPath); Benchmark::mark("exported {$appPath} to {$appTmpPath}: " . http_build_query($exportResult)); // write any libraries from classpath $classPaths = explode(',', $App->getBuildCfg('app.classpath')); foreach ($classPaths as $classPath) { if (substr($classPath, 0, 2) == 'x/') { $classPathSource = 'ext-library' . substr($classPath, 1); $cachedFiles = Emergence_FS::cacheTree($classPathSource); Benchmark::mark("precached {$cachedFiles} files from {$classPathSource}"); $exportResult = Emergence_FS::exportTree($classPathSource, "{$appTmpPath}/{$classPath}"); Benchmark::mark("exported {$classPathSource} to {$appTmpPath}/{$classPath}: " . http_build_query($exportResult)); } } // change into app's directory chdir($appTmpPath); Benchmark::mark("chdir to: {$appTmpPath}"); // prepare and run upgrade command $upgradeCmd = Sencha::buildCmd($cmdVersion, 'app upgrade --noframework'); Benchmark::mark("running upgrade CMD: {$upgradeCmd}"); passthru($upgradeCmd, $upgradeCmdStatus); Benchmark::mark("Upgrade CMD finished: exitCode={$upgradeCmdStatus}"); // import results Benchmark::mark("importing {$appTmpPath}"); $importResults = Emergence_FS::importTree($appTmpPath, $appPath, array('exclude' => array("#^/x(/|\$)#", "#/\\.sass-cache(/|\$)#", "#/\\.sencha-backup(/|\$)#", "#/\\.emergence(/|\$)#"))); Benchmark::mark("imported files: " . http_build_query($importResults)); // clean up if (empty($_GET['leaveWorkspace'])) { exec("rm -R {$tmpPath}"); Benchmark::mark("erased {$tmpPath}"); }
} } // write archive if (!empty($_GET['archive'])) { try { $exportResult = Emergence_FS::exportTree($archivePath, $archiveTmpPath); Benchmark::mark("exported {$archivePath} to {$archiveTmpPath}: " . http_build_query($exportResult)); } catch (Exception $e) { Benchmark::mark("failed to export {$archivePath}, continueing"); } } // change into app's directory chdir($appTmpPath); Benchmark::mark("chdir to: {$appTmpPath}"); // prepare cmd $cmd = Sencha::buildCmd($cmdVersion, 'ant', "-Dbuild.dir={$buildTmpPath}", 'sass'); Benchmark::mark("running CMD: {$cmd}"); // execute CMD passthru("{$cmd} 2>&1", $cmdStatus); Benchmark::mark("CMD finished: exitCode={$cmdStatus}"); // import resources directory if ($cmdStatus == 0) { Benchmark::mark("importing {$buildTmpPath}/resources to {$buildPath}/resources"); $importResults = Emergence_FS::importTree("{$buildTmpPath}/resources", "{$buildPath}/resources", array('exclude' => $defaultExclude)); Benchmark::mark("imported files: " . http_build_query($importResults)); } // clean up if (empty($_GET['leaveWorkspace'])) { exec("rm -R {$tmpPath}"); Benchmark::mark("erased {$tmpPath}"); }
die('Parameter framework required'); } $framework = $_REQUEST['framework']; Benchmark::mark("configured request: framework={$framework}"); // get temporary directory $tmpPath = Emergence_FS::getTmpDir(); Benchmark::mark("created tmp: {$tmpPath}"); // write workspace $workspacePath = 'sencha-workspace'; Benchmark::mark("precaching workspace: {$workspacePath}"); $cachedFiles = Emergence_FS::cacheTree($workspacePath); Benchmark::mark("precaching finished: {$cachedFiles} files loaded/updated"); Benchmark::mark("exporting workspace: {$workspacePath} to {$tmpPath}"); $exportResult = Emergence_FS::exportTree($workspacePath, $tmpPath); Benchmark::mark("exported finished: " . http_build_query($exportResult)); // begin cmd set_time_limit(0); $cmd = Sencha::buildCmd($framework, 'generate workspace', $tmpPath); Benchmark::mark("running CMD: {$cmd}"); passthru($cmd, $cmdStatus); Benchmark::mark("CMD finished: exitCode={$cmdStatus}"); // import app if ($cmdStatus == 0) { $destPath = 'sencha-workspace'; Benchmark::mark("importing to: {$destPath}"); $filesImported = Emergence_FS::importTree($tmpPath, $destPath); Benchmark::mark("imported {$filesImported} files"); } // clean up exec("rm -R {$tmpPath}"); Benchmark::mark("erased {$tmpPath}");
} } // write archive if (!empty($_GET['archive'])) { try { $exportResult = Emergence_FS::exportTree($archivePath, $archiveTmpPath); Benchmark::mark("exported {$archivePath} to {$archiveTmpPath}: " . http_build_query($exportResult)); } catch (Exception $e) { Benchmark::mark("failed to export {$archivePath}, continueing"); } } // change into app's directory chdir($appTmpPath); Benchmark::mark("chdir to: {$appTmpPath}"); // prepare cmd $cmd = Sencha::buildCmd($cmdVersion, 'ant', "-Dbuild.dir={$buildTmpPath}", "-Dapp.output.base={$buildTmpPath}", "-D{$framework}.dir={$frameworkTmpPath}", $buildType, 'build'); Benchmark::mark("running CMD: {$cmd}"); // optionally dump workspace and exit if (!empty($_GET['dumpWorkspace']) && $_GET['dumpWorkspace'] != 'afterBuild') { header('Content-Type: application/x-bzip-compressed-tar'); header('Content-Disposition: attachment; filename="' . $appName . '.' . date('Y-m-d') . '.tbz"'); chdir($tmpPath); passthru("tar -cjf - ./"); exec("rm -R {$tmpPath}"); exit; } // execute CMD // - optionally dump workspace and exit if (!empty($_GET['dumpWorkspace']) && $_GET['dumpWorkspace'] == 'afterBuild') { exec($cmd); header('Content-Type: application/x-bzip-compressed-tar');
$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 $exportResult = Emergence_FS::exportTree($workspaceConfigPath, $tmpConfigPath); Benchmark::mark("exported {$workspaceConfigPath} to {$tmpConfigPath}: " . http_build_query($exportResult)); $exportResult = Emergence_FS::exportTree($workspaceFrameworkPath, $tmpFrameworkPath); Benchmark::mark("exported {$workspaceFrameworkPath} to {$tmpFrameworkPath}: " . http_build_query($exportResult)); // begin cmd $appPath = "{$workspacePath}/{$appName}"; $appTmpPath = "{$tmpPath}/{$appName}"; $cmd = Sencha::buildCmd(null, "-sdk {$tmpFrameworkPath}", 'generate app', $appName, $appTmpPath); //config -prop templates.dir=/root/templates then Benchmark::mark("running CMD: {$cmd}"); passthru("{$cmd} 2>&1", $cmdStatus); Benchmark::mark("CMD finished: exitCode={$cmdStatus}"); // import app if ($cmdStatus == 0) { Benchmark::mark("importing {$appTmpPath} to {$appPath}"); $importResults = Emergence_FS::importTree($appTmpPath, $appPath, array('exclude' => array("#^/{$framework}/#"))); Benchmark::mark("imported files: " . http_build_query($importResults)); } // clean up if (empty($_GET['leaveWorkspace'])) { exec("rm -R {$tmpPath}"); Benchmark::mark("erased {$tmpPath}"); }
public function getRequiredPackages($deep = true) { $packages = $this->getAppCfg('requires'); if ($themeName = $this->getBuildCfg('app.theme')) { $packages[] = $themeName; } if ($deep) { $packages = array_unique(Sencha::crawlRequiredPackages($packages, $this->getFramework(), $this->getFrameworkVersion())); } return $packages; }
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; }
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)) : ''); }
$cachedFiles = Emergence_FS::cacheTree($classPathSource); Benchmark::mark("precached {$cachedFiles} files in {$classPathSource}"); $sourceNode = Site::resolvePath($classPathSource); if (is_a($sourceNode, SiteFile)) { mkdir(dirname($classPath), 0777, true); copy($sourceNode->RealPath, $classPath); Benchmark::mark("copied file {$classPathSource} to {$classPath}"); } else { $exportResult = Emergence_FS::exportTree($classPathSource, $classPath); Benchmark::mark("exported {$classPathSource} to {$classPath}: " . http_build_query($exportResult)); } } } // prepare cmd $classPaths[] = 'src'; $cmd = Sencha::buildCmd($cmdVersion, "-sdk ./{$framework}", 'compile', "-classpath=" . implode(',', array_unique($classPaths)), 'union -class Ext.Boot and concat -yui ./build/common.js', 'and union -recursive -class Site.Common', count($commonOverrides) ? ' and ' . implode(' and ', $commonOverrides) : '', 'and save common', count($pageLoadCommands) ? 'and ' . join(' and ', $pageLoadCommands) . ' and restore common' : '', count($pageNames) > 1 ? 'and intersect -min=2 -set ' . join(',', $pageNames) . ' and include -set common' . ' and exclude -namespace Site.page' . ' and save common' : 'and restore common', "and concat -yui -append ./build/common.js", count($pageBuildCommands) ? 'and ' . join(' and ', $pageBuildCommands) : ''); Benchmark::mark("running CMD: {$cmd}"); // optionally dump workspace and exit if (!empty($_GET['dumpWorkspace']) && $_GET['dumpWorkspace'] != 'afterBuild') { header('Content-Type: application/x-bzip-compressed-tar'); header('Content-Disposition: attachment; filename="' . $appName . '.' . date('Y-m-d') . '.tbz"'); passthru("tar -cjf - ./"); exec("rm -R {$tmpPath}"); exit; } // execute CMD // - optionally dump workspace and exit if (!empty($_GET['dumpWorkspace']) && $_GET['dumpWorkspace'] == 'afterBuild') { exec($cmd); header('Content-Type: application/x-bzip-compressed-tar'); header('Content-Disposition: attachment; filename="' . $appName . '.' . date('Y-m-d') . '.tbz"');