Author: DMC Date: 2010-03-14 07:50:40 +0100 (Sun, 14 Mar 2010) New Revision: 28521
Added: plugins/xtDojoPlugin/trunk/README plugins/xtDojoPlugin/trunk/config/ plugins/xtDojoPlugin/trunk/config/config_handlers.yml plugins/xtDojoPlugin/trunk/config/xtDojoPluginConfiguration.class.php plugins/xtDojoPlugin/trunk/lib/ plugins/xtDojoPlugin/trunk/lib/config/ plugins/xtDojoPlugin/trunk/lib/config/xtDojoConfigHandler.class.php plugins/xtDojoPlugin/trunk/lib/filter/ plugins/xtDojoPlugin/trunk/lib/filter/xtDojoFilter.class.php plugins/xtDojoPlugin/trunk/lib/task/ plugins/xtDojoPlugin/trunk/lib/task/xtDojoBuildTask.class.php plugins/xtDojoPlugin/trunk/lib/task/xtDojoInitTask.class.php plugins/xtDojoPlugin/trunk/lib/vendor/ plugins/xtDojoPlugin/trunk/lib/vendor/dojo.class.php plugins/xtDojoPlugin/trunk/lib/vendor/xtDojoFileSystem.class.php Log: first release Added: plugins/xtDojoPlugin/trunk/README =================================================================== --- plugins/xtDojoPlugin/trunk/README (rev 0) +++ plugins/xtDojoPlugin/trunk/README 2010-03-14 06:50:40 UTC (rev 28521) @@ -0,0 +1,107 @@ +symfony + dojo = xtDojoPlugin +================================ + +Requirements +------------ +* [symfony framework](http://www.symfony-project.org/installation) 1.2.X or higher + +* [Dojo Toolkit SDK](http://www.dojotoolkit.org/download/) + +Installation +------------ +At first, you need to download or checkout plugin sources. Then to install plugin into project, +move xtDojoPlugin into plugin directory and activate it. + // <project_directory>/config/ProjectConfiguration.class.php + ... + public function setup() + { + ... + $this->enablePlugins('xtDojoPlugin'); + ... + } + ... +After activation run clear cache symfony task. + symfony cc +Now plugin is ready to configure dojo environment. You must run init task +from console like this: + symfony dojo:init +After that download Dojo SDK sources and place it to generated `src` directory. By default it is: `<project_directory>/web/js/dojo/src/` + default directory structure: + + web/ + ... + js/ + ... + dojo/ + dev/ + main.js + src/ + dijit/ + dojo/ + dojox/ + util/ + builder.js +Now dojo is configured and you can start using it. +Using plugin +------------ +Fisrt of all you must define global `dojo.yml` file in the config folder of application you need. For example: + <project_directory>/apps/backend/config/dojo.yml +This file has following structure: + default: # required element + theme: # theme block + name: 'dojo_theme' # dojo theme title | default: tundra + css: ['css_file', 'another_css_file'] # additional css files + actions: # required element, action groups + all: [group_name, another_group_name] # required elemrnt, set wich groups of dijits use for all actions + action_name: [group_name] # set custome action to use specific groups of dijits + dijits: # dijit blocks container + group_name: # dijits block title + block_id: {dojotype: 'dojoType'} # id of html element in template: set of attributes for this id + another_block_id: {dojotype: 'dojoType'} # id of html element in template: set of attributes for this id + another_group_name: # another dijits block +dojo.yml file example: + default: + theme: 'tundra' + actions: + all: ['layout'] + dijits: + layout: + borderConteiner: {dojoType: 'dijit.layout.BorderContainer', design: 'headline', liveSplitters: 'true'} + topPane: {dojoType: 'dijit.layout.ContentPane', region: 'top', minSize: '50', splitter: 'true', style: 'height:50px'} + centerPane: {dojoType: 'dijit.layout.ContentPane', region: 'center', title: 'Another Pane'} +template code for this specification will be: + <div id="borderConteiner"> + <div id="topPane" title="The Title"> + <h1>I'm content!</h1> + </div> + <div id="centerPane"> + <h1>I'm more content!</h1> + </div> + </div> +Also you can use per module dojo.yml files to specify custom definition for layouts. You must place additional dojo.yml files into config folder of module. Files has folowwing structure + default: # same as global, but not required + all: # same as default excepts theme block +> #### Warning! +> default directive is not required for this file. If you specify it here it will rewrite global specification + +Some dojo instances must be defined in layout.php of your application for dojo. You must put in head block the following code: + <?php echo dojo::init() ?> +before </head> tag, and set theme with + <body class="<?php echo dojo::$theme ?>"> +To add javascript functions in onload action you may use + <?php dojo::addOnLoad('<your javascript code here>') ?> +before `init()` is called. +[[BR]] +And at last to specify wich dojo widjets to use edit main.js file in `./web/js/dojo/dev` folder + example main.js listing: + + dojo.provide("app.main"); + + dojo.require("dojo.cookie"); + dojo.require("dojo.parser"); + + dojo.require("dijit.layout.BorderContainer"); + dojo.require("dijit.layout.ContentPane"); + +> questions and suggestions you can sent to sadikoff [at] gmail.com + Added: plugins/xtDojoPlugin/trunk/config/config_handlers.yml =================================================================== --- plugins/xtDojoPlugin/trunk/config/config_handlers.yml (rev 0) +++ plugins/xtDojoPlugin/trunk/config/config_handlers.yml 2010-03-14 06:50:40 UTC (rev 28521) @@ -0,0 +1,6 @@ +# configure symfony to handle dojo.yml files +modules/*/config/dojo.yml: + class: xtDojoConfigHandler + file: %SF_PLUGINS_DIR%/xtDojoPlugin/lib/config/xtDojoConfigHandler.class.php + param: + prefix: dojo_ \ No newline at end of file Added: plugins/xtDojoPlugin/trunk/config/xtDojoPluginConfiguration.class.php =================================================================== --- plugins/xtDojoPlugin/trunk/config/xtDojoPluginConfiguration.class.php (rev 0) +++ plugins/xtDojoPlugin/trunk/config/xtDojoPluginConfiguration.class.php 2010-03-14 06:50:40 UTC (rev 28521) @@ -0,0 +1,44 @@ +<?php +/** + * Plugin configuration file. You can customize folders and + * some other optons here. + * + * @package xtDojoPlugin + * @subpackage config + * @author Sadikov Vladimir aka DMC <[email protected]> + * @version 1.0 + */ + +class xtDojoPluginConfiguration extends sfPluginConfiguration +{ + /** + * Configures the plugin. + * + * This method is called before the plugin's classes have been added to sfAutoload. + */ + public function configure() + { + $sf_web_dir = sfConfig::get('sf_web_dir'); + + $parameters = array( + + 'xtDojo_fullPath' => array ( + 'prod' => $sf_web_dir.'/js/framework', + 'dev' => $sf_web_dir.'/js/dojo/dev', + 'src' => $sf_web_dir.'/js/dojo/src', + ), + + 'xtDojo_buildScriptDir' => '/util/buildscripts', + 'xtDojo_profile' => '/profiles/sf.profile.js', + + 'xtDojo_webPath' => array ( + 'prod' => '/js/framework', + 'dev' => '/js/dojo/dev', + 'src' => '/js/dojo/src' + ), + + ); + + sfConfig::add($parameters); + } +} \ No newline at end of file Added: plugins/xtDojoPlugin/trunk/lib/config/xtDojoConfigHandler.class.php =================================================================== --- plugins/xtDojoPlugin/trunk/lib/config/xtDojoConfigHandler.class.php (rev 0) +++ plugins/xtDojoPlugin/trunk/lib/config/xtDojoConfigHandler.class.php 2010-03-14 06:50:40 UTC (rev 28521) @@ -0,0 +1,111 @@ +<?php +/** + * This handler parses dojo.yml files and writes parsed data in a cache file. + * + * @package xtDojoPlugin + * @subpackage config + * @author Sadikov Vladimir aka DMC <[email protected]> + * @version 1.0 + */ + +class xtDojoConfigHandler extends sfDefineEnvironmentConfigHandler +{ + /** + * Executes this configuration handler. + * + * @param string $configFiles An absolute filesystem path to a configuration file + * + * @return string Data to be written to a cache file + * + * @throws sfConfigurationException If a requested configuration file does not exist or is not readable + * @throws sfParseException If a requested configuration file is improperly formatted + */ + public function execute($configFiles) + { + // get our prefix + $prefix = strtolower($this->getParameterHolder()->get('prefix', '')); + + // add dynamic prefix if needed + if ($this->getParameterHolder()->get('module', false)) + { + $prefix .= "'.strtolower(\$moduleName).'_"; + } + + $config = array(); + + $countFiles = count($configFiles); + + for ( $i = 0; $i < $countFiles; $i++ ) { + $configuration = self::parseYaml($configFiles[$i]); + + if ( $i == 0 ) { + foreach ($configuration as $key => $value) { + $config = array_merge($config, $value); + } + } else { + foreach ($configuration as $key => $value) { + if ($key == 'default') { + foreach ($value as $key_ => $value_) { + $config[$key_] = $value_; + } + } else { + foreach ($value as $key_ => $value_) { + is_array($config[$key_]) && key_exists($key_, $config) ? null : $config[$key_] = array(); + is_array($value_) ? null : $value_ = array(); + if ( $key_ == 'theme' ) { + $config[$key_] = array_merge($config[$key_],$value_); + } else { + $config[$key_] = array_merge_recursive($config[$key_],$value_); + } + } + } + } + } + + } + + $values = array(); + foreach ($config as $category => $keys) + { + $values = array_merge($values, $this->getValues($prefix, $category, $keys)); + } + + $data = ''; + foreach ($values as $key => $value) + { + $data .= sprintf(" '%s' => %s,\n", $key, var_export($value, true)); + } + + // compile data + $retval = ''; + if ($values) + { + $retval = "<?php\n". + "// auto-generated by xtDojoConfigHandler\n". + "// date: %s\nsfConfig::add(array(\n%s));\n"; + $retval = sprintf($retval, date('Y/m/d H:i:s'), $data); + } + + return $retval; + } + + /** + * Gets values from the configuration array. + * + * @param string $prefix The prefix name + * @param string $category The category name + * @param mixed $keys The key/value array + * + * @return array The new key/value array + */ + protected function getValues($prefix, $category, $keys) + { + $key = $prefix.$category; + $value = $keys; + + $values = array($key => $value); + + return $values; + } + +} Added: plugins/xtDojoPlugin/trunk/lib/filter/xtDojoFilter.class.php =================================================================== --- plugins/xtDojoPlugin/trunk/lib/filter/xtDojoFilter.class.php (rev 0) +++ plugins/xtDojoPlugin/trunk/lib/filter/xtDojoFilter.class.php 2010-03-14 06:50:40 UTC (rev 28521) @@ -0,0 +1,104 @@ +<?php +/** + * xtDojoFilter automatically adds javascripts and stylesheet + * information to the sfResponse content. + * + * @package xtDojoPlugin + * @subpackage filter + * @author Sadikov Vladimir aka DMC <[email protected]> + * @version 1.0 + */ + +class xtDojoFilter extends sfFilter +{ + /** + * Executes this filter. + * + * @param sfFilterChain $filterChain A sfFilterChain instance + */ + public function execute(sfFilterChain $filterChain) + { + $response = $this->context->getResponse(); + + $moduleName = $this->context->getModulename(); + require($this->context->getConfigCache()->checkConfig('modules/'.$moduleName.'/config/dojo.yml')); + + $dojoTheme = sfConfig::get('dojo_theme', array('name' => 'tundra')); + + if($this->isFirstCall()) { + $dojoDijits = sfConfig::get ( 'dojo_dijits', array() ); + $dojoViewParams = sfConfig::get ( 'dojo_actions', array('all'=>array('layout')) ); + + $viewAction = $this->context->getActionname(); + $dojoView = key_exists($viewAction, $dojoViewParams) ? array_merge_recursive($dojoViewParams['all'],$dojoViewParams[$viewAction]):$dojoViewParams['all']; + + dojo::addDijits($dojoDijits, $dojoView); + } + + dojo::setTheme($dojoTheme['name']); + + $this->addDojoCss($response, $dojoTheme); + + $this->addDojoJs($response); + + // execute next filter + $filterChain->execute(); + + } + /** + * Includes all dojo CSS files in response + * + * @param sfWebResponse $response + * @param array $dojoTheme + * + * @return void + */ + protected function addDojoCss(sfWebResponse $response, array $dojoTheme) + { + $dojoPaths = $this->getDojoPaths(); + + if('dev' == sfConfig::get('sf_dojo_env','dev')) { + $cssPath = $dojoPaths['src']; + } else { + $cssPath = $dojoPaths['prod']; + } + + $response->addStylesheet($cssPath.'/dijit/themes/'.$dojoTheme['name'].'/'.$dojoTheme['name'].'.css'); + if ( array_key_exists('css', $dojoTheme) && is_array($dojoTheme['css']) && !empty($dojoTheme['css'])) { + foreach ($dojoTheme['css'] as $style) { + $response->addStylesheet($cssPath.$style); + } + } + } + /** + * Includes all dojo JS files in response + * + * @param sfWebResponse $response + * + * @return void + */ + protected function addDojoJs(sfWebResponse $response) + { + $dojoPaths = $this->getDojoPaths(); + + if('dev' == sfConfig::get('sf_dojo_env','dev')) { + $dojoJS = $dojoPaths['src'].'/dojo/dojo.js'; + $mainJS = $dojoPaths['dev'].'/main.js'; + } else { + $dojoJS = $dojoPaths['prod'].'/dojo/dojo.js'; + $mainJS = $dojoPaths['prod'].'/app/main.js'; + } + + $response->addJavascript($dojoJS); + $response->addJavascript($mainJS); + } + /** + * Returns http path to the dojo sources + * + * @return string + */ + protected function getDojoPaths() + { + return sfConfig::get('xtDojo_webPath'); + } +} \ No newline at end of file Added: plugins/xtDojoPlugin/trunk/lib/task/xtDojoBuildTask.class.php =================================================================== --- plugins/xtDojoPlugin/trunk/lib/task/xtDojoBuildTask.class.php (rev 0) +++ plugins/xtDojoPlugin/trunk/lib/task/xtDojoBuildTask.class.php 2010-03-14 06:50:40 UTC (rev 28521) @@ -0,0 +1,107 @@ +<?php +/** + * Task to build dojo javascripts. Not fully implemented yet. + * + * @package xtDojoPlugin + * @subpackage task + * @author Sadikov Vladimir aka DMC <[email protected]> + * @version 0.9alfa + */ +class xtDojoBuildTask extends sfBaseTask +{ + /** + * @see sfTask + */ + protected function configure() + { + $this->addOptions(array( + new sfCommandOption('ver', null, sfCommandOption::PARAMETER_OPTIONAL, 'The Dojo version', 'DEV'), + )); + + $this->namespace = 'dojo'; + $this->name = 'build'; + $this->briefDescription = 'builds production version of dojo'; + $this->detailedDescription = <<<EOF +The [dojo:build|INFO] task builds production javascript using the dojo build system. + +NOTICE: [You need to have java installed!|COMMENT] + +For example you can build dojo without any parameter. Version will be set to "[DEV|COMMENT]" + + [./symfony dojo:build|INFO] + +If you wish to you custom version(default is DEV) set [ver|COMMENT] option like this + + [./symfony dojo:build --ver="1.0"|INFO] + +NOTICE: other building options would be implemented in the future releases! +EOF; + } + + /** + * @see sfTask + */ + protected function execute($arguments = array(), $options = array()) + { + // first we have to load all the plugin configuraton + $this->configuration->loadPlugins(); + + $fileSystem = new xtDojoFileSystem($this->dispatcher, $this->formatter); + + $fullPaths = sfConfig::get('xtDojo_fullPath'); + + $profile = $fileSystem->generateProfile(); + + $cmd = 'java -classpath ../shrinksafe/js.jar:../shrinksafe/shrinksafe.jar org.mozilla.javascript.tools.shell.Main build.js cssOptimize=comments action=clean,release mini=true optimize=shrinksafe expandProvide=true layerOptimize=shrinksafe profile=sf releaseDir='.$fullPaths['prod'].' version="'.$options['ver'].'" releaseName=""'; + + $fileSystem->execute('cd '.$fullPaths['src'].sfConfig::get('xtDojo_buildScriptDir').' && '.$cmd, array($this,'logBuildInfo'), array($this,'logBuildError')); + + $fileSystem->remove($profile); + + $this->logSection('dojo', 'Build finished.'); + } + /** + * Info log function for java output + * + * !NB: This is a test version of function. Will be rewritten in future. + * + * @param string $message + */ + public function logBuildInfo($message) + { + if (strlen($message) > 1) { + $lines = explode("\n", $message); + foreach ($lines as $line) { + if (strlen($line) > 1) { + $lineArray = explode(':',$line); + if ( count( $lineArray ) == 1 ) { + $this->logSection('Info', $lineArray[0]); + } elseif ( count( $lineArray ) > 2 ) { + $this->logSection(trim($lineArray[1]), trim($lineArray[2])); + } else { + $this->logSection(trim($lineArray[0]), trim($lineArray[1])); + } + + } + } + } + } + /** + * Eror log function for java output + * + * !NB: This is a test version of function. Will be rewritten in future. + * + * @param string $message + */ + public function logBuildError($message) + { + if (strlen($message) > 1) { + $lines = explode("\n", $message); + foreach ($lines as $line) { + if (strlen($line) > 1) { + $this->logSection('ERROR', $line, null, 'ERROR'); + } + } + } + } +} \ No newline at end of file Added: plugins/xtDojoPlugin/trunk/lib/task/xtDojoInitTask.class.php =================================================================== --- plugins/xtDojoPlugin/trunk/lib/task/xtDojoInitTask.class.php (rev 0) +++ plugins/xtDojoPlugin/trunk/lib/task/xtDojoInitTask.class.php 2010-03-14 06:50:40 UTC (rev 28521) @@ -0,0 +1,64 @@ +<?php +/** + * Configure default directory structure for plugin, and initializes some + * service files. Not fully implemented yet + * + * @package xtDojoPlugin + * @subpackage task + * @author Sadikov Vladimir aka DMC <[email protected]> + * @version 0.9alfa + */ + +class xtDojoInitTask extends sfBaseTask +{ + /** + * @see sfTask + */ + protected function configure( ) + { + $this->namespace = 'dojo'; + $this->name = 'init'; + $this->briefDescription = 'initializes dojo environment'; + $this->detailedDescription = <<<EOF +The [dojo:init|INFO] task sets up the current project for using the xtDojoPlugin + +Creates default directory structure for dojo: + + [./symfony dojo:init|INFO] + +EOF; + } + + /** + * @see sfTask + */ + protected function execute( $arguments = array( ), $options = array( ) ) + { + // first we have to load all the plugin configuraton + $this->configuration->loadPlugins( ); + + $fileSystem = $this->getFilesystem( ); + + $paths = sfConfig::get('xtDojo_fullPath'); + + foreach ( $paths as $key => $path ) { + if ( $key == 'prod' ) { + continue; + } + $fileSystem->mkdirs( $path ); + } + + $fileSystem->touch( $paths['dev'].'/main.js' ); + file_put_contents( $paths['dev'].'/main.js', "dojo.provide(\"app.main\");\n\r\n\r" ); + + $buildJSContent = sprintf(<<<EOF +var buildScriptsPath = '%s/'; +load(buildScriptsPath + "build.js"); +EOF + ,sfConfig::get('sf_web_dir').'/js/dojo/src'.sfConfig::get('xtDojo_buildScriptDir')); + + $fileSystem->touch( sfConfig::get('sf_web_dir').'/js/dojo/builder.js' ); + file_put_contents( sfConfig::get('sf_web_dir').'/js/dojo/builder.js', $buildJSContent ); + + } +} \ No newline at end of file Added: plugins/xtDojoPlugin/trunk/lib/vendor/dojo.class.php =================================================================== --- plugins/xtDojoPlugin/trunk/lib/vendor/dojo.class.php (rev 0) +++ plugins/xtDojoPlugin/trunk/lib/vendor/dojo.class.php 2010-03-14 06:50:40 UTC (rev 28521) @@ -0,0 +1,172 @@ +<?php +/** + * Service dojo class. + * + * @package xtDojoPlugin + * @subpackage dojo + * @author Sadikov Vladimir aka DMC <[email protected]> + * @version 0.9alfa + */ + +class dojo { + /** + * Theme variable + * @var string + */ + public static $theme = 'tundra'; + /** + * Registered programmatic dijits + * @var array + */ + protected static $_dijits = array(); + /** + * Actions to perform on window load + * @var array + */ + protected static $_dojoOnLoad = array(); + /** + * Has the dijit loader been registered? + * @var bool + */ + protected static $_loaderRegistered = false; + /** + * Arbitrary javascript to include in dojo script + * @var array + */ + protected static $_js = array(); + /** + * Add a script to execute onLoad + * + * @param string $callback + * + * @return void + */ + public static function addOnLoad($callback) { + if (!in_array($callback, self::$_dojoOnLoad, true)) { + self::$_dojoOnLoad[] = ' '.$callback; + } + } + /** + * Prepend an onLoad event to the list of onLoad actions + * + * @param string $callback + * + * @return void + */ + public static function prependOnLoad($callback) { + if (!in_array($callback, self::$_dojoOnLoad, true)) { + array_unshift(self::$_dojoOnLoad, $callback); + } + } + /** + * Sets dojo theme + * + * @param string $theme + * + * @return void + */ + public static function setTheme($theme) { + self::$theme = $theme; + } + /** + * Add a programmatic dijit + * + * @param string $id + * @param array $params + * + * @return void + */ + public static function addDijit($id, array $params) { + self::$_dijits[$id] = array( + 'id' => $id, + 'params' => $params, + ); + } + /** + * Add multiple dijits at once + * + * Expects an array of id => array $params pairs + * + * @param array $dijits + * + * @return void + */ + public static function addDijits(array $dijits, array $viewDijits) { + foreach ($viewDijits as $view) { + foreach ($dijits[$view] as $id => $params) { + self::addDijit($id, $params); + } + } + } + /** + * Retrieve all dijits + * + * Returns dijits as an array of assoc arrays + * + * @return array + */ + public static function getDijits() { + return json_encode(array_values(self::$_dijits)); + } + /** + * Adds custom JavaScript in loader + * + * @param string $js + * + * @return void + */ + public static function addJavaScript($js) { + self::$_js[] = $js; + } + /** + * Create dijit loader functionality + * + * @return void + */ + public static function getLoader() { + if (!self::$_loaderRegistered) { + $js =<<<EOJ + dojo.forEach(dijits, function(info) { + var n = dojo.byId(info.id); + if (null != n) { + dojo.attr(n, dojo.mixin({ id: info.id }, info.params)); + } + }); + dojo.parser.parse(); +EOJ; + self::prependOnLoad($js); + self::addJavaScript('var dijits = '.self::getDijits().';'); + self::$_loaderRegistered = true; + } + } + /** + * initializes dojo application + * + * @return string + */ + public static function init() { + if (!empty(self::$_dijits)) { + self::getLoader(); + } + + $addOnLoad = implode("\n", self::$_dojoOnLoad); + $javascript = implode("\n", self::$_js); + + $html = sprintf(<<<EOF +<script type="text/javascript"> +//<![CDATA[ +dojo.addOnLoad(function(){ +%s +}); +%s +//]]> +</script> +EOF + ,$addOnLoad + ,$javascript + ); + + return $html; + } + +} \ No newline at end of file Added: plugins/xtDojoPlugin/trunk/lib/vendor/xtDojoFileSystem.class.php =================================================================== --- plugins/xtDojoPlugin/trunk/lib/vendor/xtDojoFileSystem.class.php (rev 0) +++ plugins/xtDojoPlugin/trunk/lib/vendor/xtDojoFileSystem.class.php 2010-03-14 06:50:40 UTC (rev 28521) @@ -0,0 +1,117 @@ +<?php +/** + * Extends sfFilesystem for xtDojoBuildTask. + * + * @package xtDojoPlugin + * @subpackage filesystem + * @author Sadikov Vladimir aka DMC <[email protected]> + * @version 1.0 + */ + +class xtDojoFileSystem extends sfFilesystem +{ + /** + * @see sfFilesystem + */ + public function __construct(sfEventDispatcher $dispatcher = null, sfFormatter $formatter = null) + { + parent::__construct($dispatcher, $formatter); + } + /** + * @see sfFilesystem + */ + public function execute($cmd, $stdoutCallback = null, $stderrCallback = null) + { + $this->logSection('exec ', $cmd); + + $descriptorspec = array( + 1 => array('pipe', 'w'), // stdout + 2 => array('pipe', 'w'), // stderr + ); + + $process = proc_open($cmd, $descriptorspec, $pipes); + if (!is_resource($process)) { + throw new RuntimeException('Unable to execute the command.'); + } + + stream_set_blocking($pipes[1], false); + stream_set_blocking($pipes[2], false); + + $output = ''; + $err = ''; + while (!feof($pipes[1])) { + foreach ($pipes as $key => $pipe) { + // default line if (!$line = fread($pipe, 128)) + // was rewriten in case to provide more beautiful java output + if (!$line = fread($pipe, 3072)) { + continue; + } + + if (1 == $key) { + // stdout + $output .= $line; + if ($stdoutCallback){ + call_user_func($stdoutCallback, $line); + } + } else { + // stderr + $err .= $line; + if ($stderrCallback) { + call_user_func($stderrCallback, $line); + } + } + } + + sleep(0.1); + } + + fclose($pipes[1]); + fclose($pipes[2]); + + if (($return = proc_close($process)) > 0) { + throw new RuntimeException('Problem executing command.', $return); + } + + return array($output, $err); + } + /** + * Generates dojo profile for building purposes. + * + * @return string + */ + public function generateProfile() + { + $dojoPaths = sfConfig::get('xtDojo_fullPath'); + + $file_contents = sprintf(<<<EOL +dependencies = { + layers: [ + { + name: "../app/main.js", + layerDependencies: [], + dependencies: ["app.main"] + } + ], + + prefixes: [ + [ "dojo", "%s/dojo" ], + [ "dijit", "%s/dijit" ], + [ "dojox", "%s/dojox" ], + [ "app", "%s" ] + ] +} +EOL + , $dojoPaths['src'] + , $dojoPaths['src'] + , $dojoPaths['src'] + , $dojoPaths['dev'] + ); + + // build filename + $filename = $dojoPaths['src'].sfConfig::get('xtDojo_buildScriptDir').sfConfig::get('xtDojo_profile'); + $this->touch($filename); + file_put_contents($filename, $file_contents); + + return $filename; + } +} \ No newline at end of file -- You received this message because you are subscribed to the Google Groups "symfony SVN" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/symfony-svn?hl=en.
