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

Namespaces

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