Skip to content

Commit

Permalink
Minor refactor of public/api.php
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed Oct 15, 2024
1 parent 7301407 commit 8c81cdc
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions public/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}

if (!Mage::isInstalled()) {
echo 'Application is not installed yet, please complete install wizard first.';
echo 'Application is not installed yet.';
exit;
}

Expand All @@ -42,31 +42,31 @@
Mage::register('custom_entry_point', true);
/** @var Mage_Api2_Model_Server $server */
$server = Mage::getSingleton('api2/server');

$server->run();
exit;
}

/* @var $server Mage_Api_Model_Server */
$server = Mage::getSingleton('api/server');
if (!$apiAlias) {
$adapterCode = 'default';
} else {
/* @var $server Mage_Api_Model_Server */
$server = Mage::getSingleton('api/server');
if (!$apiAlias) {
$adapterCode = 'default';
} else {
$adapterCode = $server->getAdapterCodeByAlias($apiAlias);
}
// 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();
$adapterCode = $server->getAdapterCodeByAlias($apiAlias);
}

Mage::app()->getResponse()->sendResponse();
} catch (Exception $e) {
Mage::logException($e);
// if no adapters found in aliases - find it by default, by code
if ($adapterCode === null) {
$adapterCode = $apiAlias;
}

echo $e->getMessage();
exit;
}
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 $e) {
Mage::logException($e);
echo $e->getMessage();
exit;
}

2 comments on commit 8c81cdc

@justinbeaty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fballiano I was thinking about this file the other day. Are the files in app/code/Mage/Api/Controller and app/code/Mage/Api/controllers needed any more? They have the frontname api but it seems that this file takes over all requests to example.com/api. I had planned to investigate, but since you're already here, you might check it out.

@fballiano
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they're needed for SOAP, which doesn't have to use api.php, am I missing something?

But I'd say that it would be nice to:

  • integrate api.php into index.php
  • force all API request through that part of code avoiding the old heavyweight calls to API through index.php

Please sign in to comment.