AloFramework documentation
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Alo
    • Cache
    • CLI
    • Controller
    • Db
    • Exception
    • FileSystem
    • Session
    • Statics
    • Test
    • Validators
    • Windows
  • Controller
  • None
  • PHP

Classes

  • Downloader
  • IO
 1 <?php
 2 
 3    namespace Alo\CLI;
 4 
 5    if(!defined('GEN_START')) {
 6       http_response_code(404);
 7       die();
 8    }
 9 
10    /**
11     * Handles input & output
12     *
13     * @author Art <a.molcanovas@gmail.com>
14     */
15    abstract class IO {
16 
17       /**
18        * Arguments passed on to PHP excl the first (file name)
19        *
20        * @var array
21        */
22       public static $argv;
23 
24       /**
25        * Clears previous output
26        *
27        * @author Art <a.molcanovas@gmail.com>
28        *
29        * @param int $lines Amount of empty lines to output
30        */
31       static function echo_lines($lines = 100) {
32          $l     = "";
33          $lines = (int)$lines;
34 
35          for($i = 0; $i < $lines; $i++) {
36             $l .= PHP_EOL;
37          }
38 
39          echo $l;
40       }
41 
42       /**
43        * Opens a file using the default program. Works on Windows Linux as long as xdg-utils are installed.
44        *
45        * @author Art <a.molcanovas@gmail.com>
46        *
47        * @param string $path File path.
48        */
49       static function open_file_default($path) {
50          if(server_is_windows()) {
51             shell_exec('start "' . $path . '"');
52          } else {
53             shell_exec('xdg-open "' . $path . '"');
54          }
55       }
56 
57       /**
58        * Reads a line of user input. Windows does not have readline() so a cross-platform solution is required.
59        *
60        * @author Art <a.molcanovas@gmail.com>
61        *
62        * @param string $prompt Prompt message
63        *
64        * @return string
65        */
66       static function readline($prompt = null) {
67          if($prompt) {
68             echo $prompt;
69          }
70 
71          $r = trim(strtolower(stream_get_line(STDIN, PHP_INT_MAX, PHP_EOL)));
72          echo PHP_EOL;
73 
74          return $r;
75       }
76 
77    }
78 
79    IO::$argv = get($_SERVER['argv']);
80    if(is_array(IO::$argv)) {
81       array_shift(IO::$argv);
82    } else {
83       IO::$argv = [];
84    }
AloFramework documentation API documentation generated by ApiGen 2.8.0