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

Namespaces

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

Classes

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