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

Source for file Scaffolder.php

Documentation is available at Scaffolder.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_Console
  30.  * @subpackage Exception
  31.  * @version    $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
  32.  * @copyright  Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  33.  * @license    http://phpazure.codeplex.com/license
  34.  */
  35.  
  36. /**
  37.  * @see Microsoft_AutoLoader
  38.  */
  39. require_once dirname(__FILE__'/../../AutoLoader.php';
  40.  
  41. /**
  42.  * Scaffold commands
  43.  * 
  44.  * @category   Microsoft
  45.  * @package    Microsoft_WindowsAzure_CommandLine
  46.  * @copyright  Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  47.  * @license    http://phpazure.codeplex.com/license
  48.  * 
  49.  * @command-handler scaffolder
  50.  * @command-handler-description Windows Azure Package commands
  51.  * @command-handler-header Windows Azure SDK for PHP
  52.  * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  53.  * @command-handler-footer
  54.  * @command-handler-footer All commands support the --ConfigurationFile or -F parameter.
  55.  * @command-handler-footer The parameter file is a simple INI file carrying one parameter
  56.  * @command-handler-footer value per line. It accepts the same parameters as one can
  57.  * @command-handler-footer use from the command line command.
  58.  */
  59.     extends Microsoft_Console_Command
  60. {    
  61.     /**
  62.      * Runs a scaffolder and creates a Windows Azure project structure which can be customized before packaging.
  63.      * 
  64.      * @command-name Run
  65.      * @command-description Runs a scaffolder and creates a Windows Azure project structure which can be customized before packaging.
  66.      * 
  67.      * @command-parameter-for $path Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --OutputPath|-out Required. The path to create the Windows Azure project structure.
  68.      * @command-parameter-for $scaffolder Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Scaffolder|-s Optional. The path to the scaffolder to use. Defaults to Scaffolders/DefaultScaffolder.phar
  69.      */
  70.     public function runCommand($path$scaffolder$argv)
  71.     {
  72.         // Default parameter value
  73.         if (is_null($scaffolder|| $scaffolder == ''{
  74.             $scaffolder 'DefaultScaffolder';
  75.         }
  76.         
  77.         // Locate scaffolder
  78.         $scaffolderFile realpath($scaffolder);
  79.         if (!is_file($scaffolderFile)) {
  80.             $scaffolderFile realpath(dirname(__FILE__'/../../../../scaffolders/' str_replace('.phar'''$scaffolder'.phar');
  81.         }
  82.         
  83.         // Verify scaffolder
  84.         if (!is_file($scaffolderFile)) {
  85.             throw new Microsoft_Console_Exception('Could not locate the given scaffolder: ' $scaffolder);
  86.         }
  87.         
  88.         // Include scaffolder
  89.         require_once $scaffolderFile;
  90.         $scaffolderClass str_replace('.phar'''basename($scaffolderFile));
  91.         if (!class_exists($scaffolderClass)) {
  92.             $scaffolderClass str_replace('-''_'str_replace('.''_'$scaffolderClass));
  93.             if (!class_exists($scaffolderClass)) {
  94.                 $scaffolderClass substr($scaffolderClass0strpos($scaffolderClass'_'));
  95.                 if (!class_exists($scaffolderClass)) {
  96.                     throw new Microsoft_Console_Exception('Could not locate a class named ' $scaffolderClass ' in the given scaffolder: ' $scaffolder '. Make sure the scaffolder package contains a file named index.php and contains a class named Scaffolder.');
  97.                 }
  98.             }
  99.         }
  100.         
  101.         // Add command parameters
  102.         array_unshift($argv'--OutputPath=' $path);
  103.         array_unshift($argv'--Phar=' $scaffolderFile);
  104.         array_unshift($argv'Run');
  105.         array_unshift($argv$scaffolderClass);
  106.  
  107.         // Run scaffolder
  108.         Microsoft_Console_Command::bootstrap($argv);
  109.         
  110.         // Echo output path
  111.         echo "$scaffolderClass finished at location: $path\r\n";
  112.     }
  113.     
  114.     /**
  115.      * Shows help information for a specific scaffolder.
  116.      * 
  117.      * @command-name Help
  118.      * @command-description Shows help information for a specific scaffolder.
  119.      * 
  120.      * @command-parameter-for $scaffolder Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Scaffolder|-s Optional. The path to the scaffolder to use. Defaults to Scaffolders/DefaultScaffolder.phar
  121.      */
  122.     public function scaffolderhelpCommand($scaffolder$argv)
  123.     {
  124.         // Default parameter value
  125.         if (is_null($scaffolder|| $scaffolder == ''{
  126.             $scaffolder 'DefaultScaffolder';
  127.         }
  128.         
  129.         // Locate scaffolder
  130.         $scaffolderFile realpath($scaffolder);
  131.         if (!is_file($scaffolderFile)) {
  132.             $scaffolderFile realpath(dirname(__FILE__'/../../../../scaffolders/' str_replace('.phar'''$scaffolder'.phar');
  133.         }
  134.         
  135.         // Verify scaffolder
  136.         if (!is_file($scaffolderFile)) {
  137.             throw new Microsoft_Console_Exception('Could not locate the given scaffolder: ' $scaffolder);
  138.         }
  139.         
  140.         // Include scaffolder
  141.         require_once $scaffolderFile;
  142.         $scaffolderClass str_replace('.phar'''basename($scaffolderFile));
  143.         if (!class_exists($scaffolderClass)) {
  144.             $scaffolderClass str_replace('-''_'str_replace('.''_'$scaffolderClass));
  145.             if (!class_exists($scaffolderClass)) {
  146.                 $scaffolderClass substr($scaffolderClass0strpos($scaffolderClass'_'));
  147.                 if (!class_exists($scaffolderClass)) {
  148.                     throw new Microsoft_Console_Exception('Could not locate a class named ' $scaffolderClass ' in the given scaffolder: ' $scaffolder '. Make sure the scaffolder package contains a file named index.php and contains a class named Scaffolder.');
  149.                 }
  150.             }
  151.         }
  152.         
  153.         // Add command parameters
  154.         array_unshift($argv'-h');
  155.         array_unshift($argv$scaffolderClass);
  156.                 
  157.         // Run scaffolder
  158.         Microsoft_Console_Command::bootstrap($argv);
  159.     }
  160.         
  161.     /**
  162.      * Builds a scaffolder from a given path.
  163.      * 
  164.      * @command-name Build
  165.      * @command-description Builds a scaffolder from a given path.
  166.      * 
  167.      * @command-parameter-for $rootPath Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --InputPath|-in Required. The path to package into a scaffolder.
  168.      * @command-parameter-for $scaffolderFile Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --OutputFile|-out Required. The filename of the scaffolder.
  169.      */
  170.     public function buildCommand($rootPath$scaffolderFile)
  171.     {
  172.         $archive new Phar($scaffolderFile);
  173.         $archive->buildFromIterator(
  174.             new RecursiveIteratorIterator(
  175.                 new SourceControlFilteredRecursiveFilterIterator(
  176.                     new RecursiveDirectoryIterator(realpath($rootPath)))),
  177.         realpath($rootPath));
  178.         
  179.         echo $scaffolderFile;
  180.     }
  181. }
  182.  
  183.     extends RecursiveFilterIterator {
  184.     public static $filters array('.svn''.git');
  185.  
  186.     public function accept({
  187.         return !in_array(
  188.         $this->current()->getFilename()self::$filterstrue);
  189.     }
  190. }

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