Overview

Namespaces

  • None
  • Peg
    • Cli
      • Commands
    • Config
    • Custom
      • Command
        • Action
          • Generate
          • Parse
      • CommandLine
      • Config
      • Localization
      • Utilities
    • Lib
      • Definitions
        • Element
      • Generator
      • Lexers
      • Plugins
      • Signals
        • Data
          • Definitions
          • Lexers
        • Type
  • PHP

Classes

  • Base
  • ZendPHP
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: /**
 3:  * @author Jefferson González
 4:  * @license MIT
 5:  * @link http://github.com/peg-org/peg-custom Source code.
 6:  */
 7: 
 8: namespace Peg\Custom\Command\Action\Generate;
 9: 
10: use Peg\Custom\Application;
11: use Peg\Custom\CommandLine\Error;
12: 
13: /**
14:  * Declares the base for a parse action that extract and generates definition
15:  * files.
16:  */
17: abstract class Base extends \Peg\Custom\CommandLine\Action
18: {
19:     /**
20:      * Reference to command that called this action.
21:      * @var \Peg\Custom\CommandLine\Command
22:      */
23:     protected $command;
24:     
25:     /**
26:      * Name of the engine for which the source code is going to be generated.
27:      * @var string
28:      */
29:     protected $engine;
30:     
31:     /**
32:      * Flag that indicates if the generator should output messages of its 
33:      * current status.
34:      * @var bool
35:      */
36:     protected $verbose;
37: 
38:     /**
39:      * Your derived class should override this and set the 
40:      * engine name of your generator so it is called apropiately
41:      * when this variable is set.
42:      * @param string $engine Name of the engine.
43:      */
44:     public function __construct($engine)
45:     {
46:         $this->engine = $engine;
47:     }
48: 
49:     /**
50:      * You shouldn't override this method, instead write a Start() implementation.
51:      * @param \Peg\Custom\CommandLine\Command $command
52:      */
53:     public function OnCall(\Peg\Custom\CommandLine\Command $command)
54:     {
55:         if(!Application::ValidExtension())
56:             Error::Show(t("The current directory is not a valid peg managed extension."));
57: 
58:         if(!file_exists(Application::GetCwd() . "/templates"))
59:             Error::Show(t("Template files are missing."));
60: 
61:         if($command->GetOption("engine")->GetValue() == $this->engine)
62:         {
63:             $this->command = $command;
64: 
65:             $this->verbose = $command->GetOption("verbose")->active;
66: 
67:             $this->Start();
68:         }
69:     }
70: 
71:     /**
72:      * Needs to be implemented by classes extending this one in order to
73:      * begin the generator process when the engine matches that of the
74:      * action been called.
75:      */
76:     abstract public function Start();
77: }
PEG Api API documentation generated by ApiGen 2.8.0