1

Based on this answer to a very similar question: How can I bootstrap Magento 2 in a test.php script?, specifically https://magento.stackexchange.com/a/76382,

when I run php abstract.php, I get the following error:

PHP Fatal error: Interface 'Magento\Framework\AppInterface' not found in /var/www/html/scripts/abstract.php on line 14

It's probably very basic, please forgive me, but can anyone point me in the right direction?

scripts/abstract.php, from the above link, looks like

<?php
use \Magento\Framework\AppInterface as AppInterface;
use \Magento\Framework\App\Http as Http;

use Magento\Framework\ObjectManager\ConfigLoaderInterface;
use Magento\Framework\App\Request\Http as RequestHttp;
use Magento\Framework\App\Response\Http as ResponseHttp;
use Magento\Framework\Event;
use Magento\Framework\Filesystem;
use Magento\Framework\App\AreaList as AreaList;
use Magento\Framework\App\State as State;

abstract class AbstractApp implements AppInterface
{
    public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectManager,
        Event\Manager $eventManager,
        AreaList $areaList,
        RequestHttp $request,
        ResponseHttp $response,
        ConfigLoaderInterface $configLoader,
        State $state,
        Filesystem $filesystem,
        \Magento\Framework\Registry $registry
    ) {
        $this->_objectManager = $objectManager;
        $this->_eventManager = $eventManager;
        $this->_areaList = $areaList;
        $this->_request = $request;
        $this->_response = $response;
        $this->_configLoader = $configLoader;
        $this->_state = $state;
        $this->_filesystem = $filesystem;
        $this->registry = $registry;
    }

    public function launch()
    {
        $this->run();
        return $this->_response;
    }

    abstract public function run();

    public function catchException(\Magento\Framework\App\Bootstrap $bootstrap, \Exception $exception)
    {
        return false;
    }
}
1

abstract.php is not supposed to be run by itself. There's nothing in that file to load Magento or its autoloader, and the class is declared abstract (you can't use it directly). It's failing because there's a class name PHP doesn't know what to do with by itself.

In the answer you linked, there is a second script scripts/delete-category.php demonstrating how to actually use it. You need to create that second file, and then run that script (php scripts/delete-category.php). You can change the name and contents of this one's run() method to fit your needs.

That should get you up and running.

That being said, I just submitted another approach to that question. It's a little more involved than the standalone files you're trying (you need an actual module), but it's more proper for Magento. See: https://magento.stackexchange.com/a/102901/1905

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.