-
Notifications
You must be signed in to change notification settings - Fork 1
/
mage-repl.php
executable file
·51 lines (43 loc) · 1.5 KB
/
mage-repl.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Ulrichsg\Getopt;
use Boris\Boris;
$getopt = new Getopt(array(
array('d', 'developer', Getopt::NO_ARGUMENT, 'Disable developer mode using Mage::setIsDeveloperMode', true),
array('p', 'path', Getopt::OPTIONAL_ARGUMENT, 'Optional: Path to your Magento project. Uses current directory by default.', getcwd()),
array('s', 'store', Getopt::OPTIONAL_ARGUMENT, 'Optional: store code used in Mage::app', 'admin'),
array('h', 'help', Getopt::NO_ARGUMENT, 'Shows this help menu.'),
));
$getopt->parse();
if ($getopt->getOption('help') == true) {
$getopt->showHelp();
exit(0);
}
$path = $getopt->getOption('path');
$mageFile = 'app/Mage.php';
if (file_exists($path . '/' . $mageFile) == false) {
echo "Error: Unable to find $mageFile" . PHP_EOL . PHP_EOL;
$getopt->showHelp();
exit(1);
}
umask(0);
chdir($path);
require_once $mageFile;
Mage::setIsDeveloperMode($getopt->getOption('developer'));
$app = Mage::app($getopt->getOption('store'));
restore_error_handler();
restore_exception_handler();
$boris = new Boris('mage> ');
$boris->setLocal(array('app' => $app));
$boris->onStart(function($worker, $scope) {
echo "Welcome to mage-repl.\n\n";
echo "Mage::app() is accessible using \$app.\n";
echo "Loaded store: " . $scope['app']->getStore()->getName() . "\n\n";
});
$boris->onFailure(function($worker, $scope) {
// reconnect to DB
$db = Mage::getSingleton('core/resource')->getConnection('core_read');
$db->closeConnection();
});
$boris->start();