Microsoft_WindowsAzure_CommandLine
[ class tree: Microsoft_WindowsAzure_CommandLine ] [ index: Microsoft_WindowsAzure_CommandLine ] [ all elements ]

Source for file index.php

Documentation is available at index.php

  1. <?php
  2. /**
  3.  * Copyright (c) 2009 - 2011, RealDolmen
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions are met:
  8.  *     * Redistributions of source code must retain the above copyright
  9.  *       notice, this list of conditions and the following disclaimer.
  10.  *     * Redistributions in binary form must reproduce the above copyright
  11.  *       notice, this list of conditions and the following disclaimer in the
  12.  *       documentation and/or other materials provided with the distribution.
  13.  *     * Neither the name of RealDolmen nor the
  14.  *       names of its contributors may be used to endorse or promote products
  15.  *       derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
  18.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20.  * DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
  21.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  *
  28.  * @category   Microsoft
  29.  * @package    Microsoft_WindowsAzure
  30.  * @copyright  Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  31.  * @license    http://phpazure.codeplex.com/license
  32.  * @version    $Id: SharedKeyCredentials.php 14561 2009-05-07 08:05:12Z unknown $
  33.  */
  34.  
  35.  
  36. /**
  37.  * @category   Microsoft
  38.  * @package    Microsoft_WindowsAzure_CommandLine
  39.  * @copyright  Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  40.  * @license    http://phpazure.codeplex.com/license
  41.  * 
  42.  * @command-handler DefaultScaffolder
  43.  * 
  44.  * @command-handler-description Windows Azure SDK for PHP default scaffolder.
  45.  * @command-handler-header Windows Azure SDK for PHP
  46.  * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  47.  * @command-handler-footer
  48.  * @command-handler-footer The DefaultScaffolder automatically installs PHP
  49.  * @command-handler-footer to the Windows Azure virtual machine. If a customized
  50.  * @command-handler-footer php.ini is required, add it in the /php folder after
  51.  * @command-handler-footer running the scaffolder.
  52.  */ 
  53. {
  54.     /**
  55.      * Runs a scaffolder and creates a Windows Azure project structure which can be customized before packaging.
  56.      * 
  57.      * @command-name Run
  58.      * @command-description Runs the scaffolder.
  59.      * 
  60.      * @command-parameter-for $scaffolderFile Argv --Phar Required. The scaffolder Phar file path. This is injected automatically.
  61.      * @command-parameter-for $rootPath Argv|ConfigFile --OutputPath|-out Required. The path to create the Windows Azure project structure. This is injected automatically.
  62.      * @command-parameter-for $diagnosticsConnectionString Argv|ConfigFile|Env --DiagnosticsConnectionString|-d Optional. The diagnostics connection string. This defaults to development storage.
  63.      * @command-parameter-for $webRoleNames Argv|ConfigFile|Env --WebRoles|-web Optional. A comma-separated list of names for web roles to create when scaffolding. Set this value to an empty parameter to skip creating a web role.
  64.      * @command-parameter-for $workerRoleNames Argv|ConfigFile|Env --WorkerRoles|-workers Optional. A comma-separated list of names for worker roles to create when scaffolding.
  65.      */
  66.     public function runCommand($scaffolderFile$rootPath$webRoleNames 'PhpOnAzure.Web'$workerRoleNames ''$diagnosticsConnectionString 'UseDevelopmentStorage=true')
  67.     {
  68.         // Load Phar
  69.         $phar new Phar($scaffolderFile);
  70.         
  71.         // Extract to disk
  72.         $this->log('Extracting resources...');
  73.         $this->createDirectory($rootPath);
  74.         $this->extractResources($phar$rootPath);
  75.         $this->log('Extracted resources.');
  76.         
  77.         // Configuration files
  78.         $serviceDefinitionIncludes array();
  79.         $serviceConfigurationIncludes array();
  80.         
  81.         // Follow instructions listed in $webRoleNames and $workerRoleNames
  82.         $httpPort 80;
  83.         $webRoles explode(','$webRoleNames);
  84.         foreach ($webRoles as $webRole{
  85.             if ($webRole == ''continue;
  86.             
  87.             $this->log('Creating web role "' $webRole '"...');
  88.             
  89.             // Copy all files
  90.             $this->createDirectory($rootPath '/' $webRole);
  91.             $this->copyDirectory($rootPath '/Common'$rootPath '/' $webRolefalse);
  92.             $this->copyDirectory($rootPath '/CommonWeb'$rootPath '/' $webRolefalse);
  93.             
  94.             // Configure role
  95.             $this->log('  Configuring web role "' $webRole '"...');
  96.             
  97.             $serviceDefinitionFile $rootPath '/' $webRole '/ServiceDefinition.' $webRole '.csdef';
  98.             $serviceConfigurationFile $rootPath '/' $webRole '/ServiceConfiguration.' $webRole '.cscfg';
  99.             copy($rootPath '/ServiceDefinition.Web.csdef'$serviceDefinitionFile);
  100.             copy($rootPath '/ServiceConfiguration.Web.cscfg'$serviceConfigurationFile);
  101.  
  102.             $this->applyTransforms($rootPath '/' $webRolearray(
  103.                 'DiagnosticsConnectionString' => $diagnosticsConnectionString,
  104.                 'RoleName' => $webRole,
  105.                 'HttpPort' => $httpPort++
  106.             ));        
  107.             $serviceDefinitionIncludes[$webRolefile_get_contents($serviceDefinitionFile);
  108.             $serviceConfigurationIncludes[$webRolefile_get_contents($serviceConfigurationFile);
  109.             @unlink($serviceDefinitionFile);
  110.             @unlink($serviceConfigurationFile);
  111.             
  112.             $this->log('  Configured web role "' $webRole '"...');
  113.  
  114.             $this->log('Created web role "' $webRole '"...');
  115.         }
  116.         
  117.         $workerRoles explode(','$workerRoleNames);
  118.         foreach ($workerRoles as $workerRole{
  119.             if ($workerRole == ''continue;
  120.             
  121.             $this->log('Creating worker role "' $workerRole '"...');
  122.             
  123.             // Copy all files
  124.             $this->createDirectory($rootPath '/' $workerRole);
  125.             $this->copyDirectory($rootPath '/Common'$rootPath '/' $workerRolefalse);
  126.             $this->copyDirectory($rootPath '/CommonWorker'$rootPath '/' $workerRolefalse);
  127.             
  128.             // Configure role
  129.             $this->log('  Configuring worker role "' $workerRole '"...');
  130.             
  131.             $serviceDefinitionFile $rootPath '/' $workerRole '/ServiceDefinition.' $workerRole '.csdef';
  132.             $serviceConfigurationFile $rootPath '/' $workerRole '/ServiceConfiguration.' $workerRole '.cscfg';
  133.             copy($rootPath '/ServiceDefinition.Worker.csdef'$serviceDefinitionFile);
  134.             copy($rootPath '/ServiceConfiguration.Worker.cscfg'$serviceConfigurationFile);
  135.  
  136.             $this->applyTransforms($rootPath '/' $workerRolearray(
  137.                 'DiagnosticsConnectionString' => $diagnosticsConnectionString,
  138.                 'RoleName' => $workerRole
  139.             ));        
  140.             $serviceDefinitionIncludes[$workerRolefile_get_contents($serviceDefinitionFile);
  141.             $serviceConfigurationIncludes[$workerRolefile_get_contents($serviceConfigurationFile);
  142.             @unlink($serviceDefinitionFile);
  143.             @unlink($serviceConfigurationFile);
  144.             
  145.             $this->log('  Configured worker role "' $workerRole '"...');            
  146.             
  147.             $this->log('Created worker role "' $workerRole '"...');
  148.         }
  149.  
  150.         // Apply transforms
  151.         $this->log('Applying transforms...');
  152.         $this->applyTransforms($rootPatharray(
  153.             'DiagnosticsConnectionString' => $diagnosticsConnectionString,
  154.             'ServiceDefinition' => implode("\r\n"$serviceDefinitionIncludes),
  155.             'ServiceConfiguration' => implode("\r\n"$serviceConfigurationIncludes)
  156.         ));
  157.         $this->log('Applied transforms.');
  158.         
  159.         // Delete unnecessary files and folders
  160.         $this->log('Cleanup starting...');
  161.         $this->deleteDirectory($rootPath '/Common');
  162.         $this->deleteDirectory($rootPath '/CommonWeb');
  163.         $this->deleteDirectory($rootPath '/CommonWorker');
  164.         @unlink($rootPath '/ServiceConfiguration.Web.cscfg');
  165.         @unlink($rootPath '/ServiceConfiguration.Worker.cscfg');
  166.         @unlink($rootPath '/ServiceDefinition.Web.csdef');
  167.         @unlink($rootPath '/ServiceDefinition.Worker.csdef');
  168.         $this->log('Cleanup finished.');
  169.         
  170.         // Show "to do" message
  171.         $this->log('');
  172.         $this->log('Your Windows Azure project has been scaffolded.');
  173.     }
  174. }

Documentation generated on Sat, 03 Dec 2011 13:59:27 +0100 by phpDocumentor 1.4.3