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

Functions

  • peg_custom_autoloader
  • t
  • Overview
  • Namespace
  • Function
  • Tree
  • Todo
 1: <?php
 2: /**
 3:  * Basic cli implementation used for testing and development of the library. 
 4:  * If your are planning to use peg please use http://github.com/peg-org/peg-cli 
 5:  * which is the official and fully featured cli interface of the project.
 6:  *
 7:  * @author Jefferson González
 8:  * @license MIT
 9:  * @link http://github.com/peg-org/peg-custom Source code.
10:  */
11: 
12: // Set the path to peg files by using environment variables if available,
13: // if not, it uses current path
14: 
15: $autoload = __DIR__ . '/vendor/autoload.php';
16: if(!file_exists($autoload)) {
17:     die('Please install composer from https://getcomposer.org and run composer install');
18: }
19: 
20: require $autoload;
21: 
22: if(isset($_SERVER["PEG_SKELETON_PATH"]))
23:     define("PEG_SKELETON_PATH", $_SERVER["PEG_SKELETON_PATH"]);
24: else
25:     define("PEG_SKELETON_PATH", __DIR__ . "/vendor/peg-org/peg-src/skeleton");
26: 
27: if(isset($_SERVER["PEG_LIBRARY_PATH"]))
28:     define("PEG_LIBRARY_PATH", $_SERVER["PEG_LIBRARY_PATH"]);
29: else
30:     define("PEG_LIBRARY_PATH", __DIR__ . "/");
31: 
32: if(isset($_SERVER["PEG_LOCALE_PATH"]))
33:     define("PEG_LOCALE_PATH", $_SERVER["PEG_LOCALE_PATH"]);
34: else
35:     define("PEG_LOCALE_PATH", __DIR__ . "/locale");
36: 
37: 
38: if(!file_exists(PEG_LIBRARY_PATH . "src"))
39:     throw new Exception("Peg lib path not found.");
40: 
41: if(!file_exists(PEG_SKELETON_PATH))
42:     throw new Exception("Peg skeleton files path not found.");
43: 
44: // Register class auto-loader
45: function peg_custom_autoloader($class_name)
46: {
47:     $file = str_replace("\\", "/", $class_name) . ".php";
48:     $file = str_replace("Peg/Custom/", "", $file);
49: 
50:     include(PEG_LIBRARY_PATH . "src/" . $file);
51: }
52: 
53: spl_autoload_register("peg_custom_autoloader");
54: 
55: // Register global function for translating and to facilitate automatic
56: // generation of po files.
57: function t($text)
58: {
59:     static $language_object;
60: 
61:     if(!$language_object)
62:     {
63:         $language_object = new Peg\Custom\Localization\Language(PEG_LOCALE_PATH);
64:     }
65: 
66:     return $language_object->Translate($text);
67: }
68: 
69: // Set a default timezone to prevent warnings
70: date_default_timezone_set("UTC");
71: 
72: // Initialize the application
73: Peg\Custom\Application::Initialize();
74: 
75: // Retrieve a reference of main command line parser
76: $parser = Peg\Custom\Application::GetCLIParser();
77: 
78: // Start the command line parser
79: $parser->Start($argc, $argv);
80: 
PEG Api API documentation generated by ApiGen 2.8.0