invoke($archive, $path, $options); } /** * Packages a Windows Azure project structure. * * @command-name Create * @command-description Packages a Windows Azure project structure. * * @command-parameter-for $path Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Path|-p Required. The path to package. * @command-parameter-for $runDevFabric Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --RunDevFabric|-dev Required. Switch. Run and deploy to the Windows Azure development fabric. * @command-parameter-for $outputPath Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --OutputPath|-out Optional. The output path for the resulting package. */ public function createPackageCommand($path, $runDevFabric, $outputPath) { // Create output paths if ($outputPath == '') { $outputPath = realpath($path . '/../'); } $packageOut = $outputPath . '/' . basename($path) . '.cspkg'; // Find Windows Azure SDK bin folder $windowsAzureSdkFolderCandidates = array_merge( isset($_SERVER['ProgramFiles']) ? glob($_SERVER['ProgramFiles'] . '\Windows Azure SDK\*\bin', GLOB_NOSORT) : array(), isset($_SERVER['ProgramFiles']) ? glob($_SERVER['ProgramFiles(x86)'] . '\Windows Azure SDK\*\bin', GLOB_NOSORT) : array(), isset($_SERVER['ProgramFiles']) ? glob($_SERVER['ProgramW6432'] . '\Windows Azure SDK\*\bin', GLOB_NOSORT) : array() ); if (count($windowsAzureSdkFolderCandidates) == 0) { throw new Zend_Service_Console_Exception('Could not locate Windows Azure SDK for PHP.'); } $cspack = '"' . $windowsAzureSdkFolderCandidates[0] . '\cspack.exe' . '"'; $csrun = '"' . $windowsAzureSdkFolderCandidates[0] . '\csrun.exe' . '"'; // Open the ServiceDefinition.csdef file and check for role paths $serviceDefinitionFile = $path . '/ServiceDefinition.csdef'; if (!file_exists($serviceDefinitionFile)) { require_once 'Zend/Service/Console/Exception.php'; throw new Zend_Service_Console_Exception('Could not locate ServiceDefinition.csdef at ' . $serviceDefinitionFile . '.'); } $serviceDefinition = Zend_Xml_Security::scanFile($serviceDefinitionFile); $xmlRoles = array(); if ($serviceDefinition->WebRole) { if (count($serviceDefinition->WebRole) > 1) { $xmlRoles = array_merge($xmlRoles, $serviceDefinition->WebRole); } else { $xmlRoles = array_merge($xmlRoles, array($serviceDefinition->WebRole)); } } if ($serviceDefinition->WorkerRole) { if (count($serviceDefinition->WorkerRole) > 1) { $xmlRoles = array_merge($xmlRoles, $serviceDefinition->WorkerRole); } else { $xmlRoles = array_merge($xmlRoles, array($serviceDefinition->WorkerRole)); } } // Build '/role:' command parameter $roleArgs = array(); foreach ($xmlRoles as $xmlRole) { if ($xmlRole["name"]) { $roleArgs[] = '/role:' . $xmlRole["name"] . ';' . realpath($path . '/' . $xmlRole["name"]); } } // Build command $command = $cspack; $args = array( $path . '\ServiceDefinition.csdef', implode(' ', $roleArgs), '/out:' . $packageOut ); if ($runDevFabric) { $args[] = '/copyOnly'; } passthru($command . ' ' . implode(' ', $args)); // Can we copy a configuration file? $serviceConfigurationFile = $path . '/ServiceConfiguration.cscfg'; $serviceConfigurationFileOut = $outputPath . '/ServiceConfiguration.cscfg'; if (file_exists($serviceConfigurationFile) && !file_exists($serviceConfigurationFileOut)) { copy($serviceConfigurationFile, $serviceConfigurationFileOut); } // Do we have to start the development fabric? if ($runDevFabric) { passthru($csrun . ' /devstore:start /devfabric:start'); passthru($csrun . ' /removeAll'); passthru($csrun . ' /run:"' . $packageOut . ';' . $serviceConfigurationFileOut . '" /launchBrowser'); } } /** * Creates a scaffolder from a given path. * * @command-name CreateScaffolder * @command-description Creates a scaffolder from a given path. * * @command-parameter-for $rootPath Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Path|-p Required. The path to package into a scaffolder. * @command-parameter-for $scaffolderFile Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --OutFile|-out Required. The filename of the scaffolder. */ public function createScaffolderCommand($rootPath, $scaffolderFile) { $archive = new Phar($scaffolderFile); $archive->buildFromIterator( new RecursiveIteratorIterator( new RecursiveDirectoryIterator(realpath($rootPath))), realpath($rootPath)); } } Zend_Service_Console_Command::bootstrap($_SERVER['argv']);