-
-
Notifications
You must be signed in to change notification settings - Fork 453
Expand file tree
/
Copy pathapi.php
More file actions
71 lines (57 loc) · 2.1 KB
/
api.php
File metadata and controls
71 lines (57 loc) · 2.1 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* @copyright For copyright and license information, read the COPYING.txt file.
* @link /COPYING.txt
* @license Open Software License (OSL 3.0)
* @package Mage
*/
$magentoRootDir = getcwd();
$bootstrapFilename = $magentoRootDir . '/app/bootstrap.php';
$mageFilename = $magentoRootDir . '/app/Mage.php';
if (!file_exists($bootstrapFilename)) {
echo 'Bootstrap file not found';
exit;
}
if (!file_exists($mageFilename)) {
echo 'Mage file not found';
exit;
}
require $bootstrapFilename;
require $mageFilename;
if (!Mage::isInstalled()) {
echo 'Application is not installed yet, please complete install wizard first.';
exit;
}
Mage::$headersSentThrowsException = false;
Mage::init('admin');
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_ADMINHTML, Mage_Core_Model_App_Area::PART_EVENTS);
// query parameter "type" is set by .htaccess rewrite rule
$apiAlias = Mage::app()->getRequest()->getParam('type');
// check request could be processed by API2
if (in_array($apiAlias, Mage_Api2_Model_Server::getApiTypes())) {
// emulate index.php entry point for correct URLs generation in API
Mage::register('custom_entry_point', true);
/** @var Mage_Api2_Model_Server $server */
$server = Mage::getSingleton('api2/server');
$server->run();
} else {
/** @var Mage_Api_Model_Server $server */
$server = Mage::getSingleton('api/server');
$adapterCode = $apiAlias ? $server->getAdapterCodeByAlias($apiAlias) : 'default';
// if no adapters found in aliases - find it by default, by code
if (null === $adapterCode) {
$adapterCode = $apiAlias;
}
try {
$server->initialize($adapterCode);
// emulate index.php entry point for correct URLs generation in API
Mage::register('custom_entry_point', true);
$server->run();
Mage::app()->getResponse()->sendResponse();
} catch (Exception $exception) {
Mage::logException($exception);
echo $exception->getMessage();
exit;
}
}