summaryrefslogtreecommitdiff
path: root/framework/3rdParty/PhpShell/PHP/Shell/Extensions/LoadScript.php
blob: a8c4697d8b9bd18689d74be7c829a50c65f4d3c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php

class PHP_Shell_Extensions_LoadScript implements PHP_Shell_Extension {
    public function register() {
        $cmd = PHP_Shell_Commands::getInstance();

        $cmd->registerCommand('#^r #', $this, 'cmdLoadScript', 'r <filename>', 
            'load a php-script and execute each line');

    }

    public function cmdLoadScript($l) {
        $l = substr($l, 2);

        if (file_exists($l)) {
            $content = file($l);

            $source = array();

            foreach ($content as $line) {
                $line = chop($line);

                if (preg_match('#^<\?php#', $line)) continue;

                $source[] = $line;
            }

            return $source;
        }
        return "";
    }
}