Overview

Namespaces

  • NetBazzlineZfCliGenerator
    • Controller
      • Console
    • Service
      • ProcessPipe
        • Filter
        • Transformer

Classes

  • NetBazzlineZfCliGenerator\Controller\Console\IndexController
  • NetBazzlineZfCliGenerator\Controller\Console\IndexControllerFactory
  • NetBazzlineZfCliGenerator\Service\GenerateCliContentFactory
  • NetBazzlineZfCliGenerator\Service\GenerateConfigurationContentFactory
  • NetBazzlineZfCliGenerator\Service\ProcessPipe\Filter\RemoveColorsAndModuleHeadlines
  • NetBazzlineZfCliGenerator\Service\ProcessPipe\Filter\RemoveFirstLinesAndLastLine
  • NetBazzlineZfCliGenerator\Service\ProcessPipe\Filter\RemoveIndexDotPhpFromLines
  • NetBazzlineZfCliGenerator\Service\ProcessPipe\Transformer\DumpCliContent
  • NetBazzlineZfCliGenerator\Service\ProcessPipe\Transformer\DumpConfigurationContent
  • NetBazzlineZfCliGenerator\Service\ProcessPipe\Transformer\FetchApplicationOutput
  • NetBazzlineZfCliGenerator\Service\ProcessPipe\Transformer\ParseToConfiguration
  • Overview
  • Namespace
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 
<?php
/**
 * @author stev leibelt <artodeto@bazzline.net>
 * @since 2015-07-08
 */

namespace NetBazzlineZfCliGenerator\Controller\Console;

use Exception;
use Net\Bazzline\Component\ProcessPipe\PipeInterface;
use NetBazzlineZfCliGenerator\Service\ProcessPipe\Transformer\DumpCliContent;
use ZfConsoleHelper\Controller\Console\AbstractConsoleController;

class IndexController extends AbstractConsoleController
{
    /** @var PipeInterface */
    private $generateCli;

    /** @var PipeInterface */
    private $generateConfiguration;

    /** @var string */
    private $pathToApplication;

    /** @var string */
    private $pathToAutoload;

    /** @var string */
    private $pathToCli;

    /** @var string */
    private $pathToConfiguration;

    /** @var string */
    private $prefix;

    /**
     * @param PipeInterface $processPipe
     */
    public function injectGenerateCliProcessPipe(PipeInterface $processPipe)
    {
        $this->generateCli = $processPipe;
    }

    /**
     * @param PipeInterface $processPipe
     */
    public function injectGenerateConfigurationProcessPipe(PipeInterface $processPipe)
    {
        $this->generateConfiguration = $processPipe;
    }

    /**
     * @param string $path
     */
    public function injectPathToApplication($path)
    {
        $this->pathToApplication = $path;
    }

    /**
     * @param string $path
     */
    public function injectPathToAutoload($path)
    {
        $this->pathToAutoload = $path;
    }

    /**
     * @param string $path
     */
    public function injectPathToCli($path)
    {
        $this->pathToCli = $path;
    }

    /**
     * @param string $path
     */
    public function injectPathToConfiguration($path)
    {
        $this->pathToConfiguration = $path;
    }

    /**
     * @param string $prefix
     */
    public function injectPrefix($prefix)
    {
        $this->prefix = $prefix;
    }

    public function configurationAction()
    {
        //begin of dependencies
        $console                = $this->getConsole();
        $pathToApplication      = $this->pathToApplication;
        $pathToConfiguration    = $this->pathToConfiguration;
        $processPipe            = $this->generateConfiguration;
        //end of dependencies

        try {
            $this->throwExceptionIfNotCalledInsideAnCliEnvironment();

            //@todo replace by something form zend
            $content = $processPipe->execute($pathToApplication);
            $this->tryToWriteContent($pathToConfiguration, $content);
            $console->writeLine('generated configuration in path: "' . $pathToConfiguration . '"');
        } catch (Exception $exception) {
            $this->handleException($exception);
        }
    }

    public function cliAction()
    {
        //begin of dependencies
        $console                = $this->getConsole();
        $pathToApplication      = $this->pathToApplication;
        $pathToAutoload         = $this->pathToAutoload;
        $pathToConfiguration    = $this->pathToConfiguration;
        $pathToCli              = $this->pathToCli;
        $prefix                 = $this->prefix;
        $processPipe            = $this->generateCli;
        //end of dependencies

        try {
            $this->throwExceptionIfNotCalledInsideAnCliEnvironment();

            //workflow
            //  generate cli file using the template
            //  this file also contains the closure used in the configuration to execute the code
            $input                  = array(
                DumpCliContent::INPUT_KEY_PATH_TO_APPLICATION   => $pathToApplication,
                DumpCliContent::INPUT_KEY_PATH_TO_AUTOLOAD      => $pathToAutoload,
                DumpCliContent::INPUT_KEY_PATH_TO_CLI           => $pathToCli,
                DumpCliContent::INPUT_KEY_PATH_TO_CONFIGURATION => $pathToConfiguration,
                DumpCliContent::INPUT_KEY_PREFIX_CLI            => $prefix
            );
            //we need to make sure the file exist
            if (!file_exists($pathToCli)) {
                $this->tryToWriteContent($pathToCli, '');
            }
            $content = $processPipe->execute($input);
            $this->tryToWriteContent($pathToCli, $content);
            chmod($pathToCli, 0755);
            $console->writeLine('generated cli in path: "' . $pathToCli . '"');
        } catch (Exception $exception) {
            $this->handleException($exception);
        }
    }

    /**
     * @return bool
     */
    protected function beVerbose()
    {
        return $this->hasBooleanParameter('v', 'verbose');
    }

    /**
     * @param string $path
     * @param mixed $content
     * @throws Exception
     */
    private function tryToWriteContent($path, $content)
    {
        $contentCouldBeWritten  = (file_put_contents($path, $content) !== false);

        if (!$contentCouldBeWritten) {
            throw new Exception(
                'could not write to path "' . $path . '"'
            );
        }
    }
}
PHP Command Line Generator Module for Zend Framework 2 by bazzline.net API documentation generated by ApiGen