diff --git a/README.md b/README.md index 42ff76f..98a12d5 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,7 @@ process exits with that status. The client detects the project type automatically: - Laravel: `vendor/autoload.php` and `bootstrap/app.php` +- Magento: `bin/magento` - Symfony: `vendor/autoload.php`, `symfony.lock`, and `src/Kernel.php` - WordPress: `wp-load.php` - Pimcore: `vendor/pimcore/pimcore` @@ -147,6 +148,10 @@ Examples: code=$(printf '%s' 'return App\Models\User::query()->latest()->first();' | base64) php client.phar /path/to/laravel execute "$code" +# Magento +code=$(printf '%s' 'echo Magento\Framework\App\ObjectManager::getInstance()->get(Magento\Catalog\Model\ProductRepository::class)->getById(1)->getName();' | base64) +php client.phar /path/to/magento execute "$code" + # WordPress code=$(printf '%s' 'return get_option("blogname");' | base64) php client.phar /path/to/wordpress execute "$code" diff --git a/src/Loader.php b/src/Loader.php index 6eab317..3fc8005 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -5,6 +5,7 @@ use TweakPHP\Client\Loaders\ComposerLoader; use TweakPHP\Client\Loaders\LaravelLoader; use TweakPHP\Client\Loaders\LoaderInterface; +use TweakPHP\Client\Loaders\MagentoLoader; use TweakPHP\Client\Loaders\PimcoreLoader; use TweakPHP\Client\Loaders\PlainPhpLoader; use TweakPHP\Client\Loaders\SymfonyLoader; @@ -29,6 +30,10 @@ public static function load(string $path, ?string $encodedLoader = null) return new LaravelLoader($path); } + if (MagentoLoader::supports($path)) { + return new MagentoLoader($path); + } + if (SymfonyLoader::supports($path)) { return new SymfonyLoader($path); } diff --git a/src/Loaders/MagentoLoader.php b/src/Loaders/MagentoLoader.php new file mode 100644 index 0000000..2b0c369 --- /dev/null +++ b/src/Loaders/MagentoLoader.php @@ -0,0 +1,40 @@ +get(ProductMetadataInterface::class); + + return $metadata->getEdition().' '.$metadata->getVersion(); + } +} diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php index 34c6f97..f5ffd9b 100644 --- a/tests/LoaderTest.php +++ b/tests/LoaderTest.php @@ -28,6 +28,7 @@ public static function kernel() {} use TweakPHP\Client\Loader; use TweakPHP\Client\Loaders\ComposerLoader; use TweakPHP\Client\Loaders\LaravelLoader; + use TweakPHP\Client\Loaders\MagentoLoader; use TweakPHP\Client\Loaders\PimcoreLoader; use TweakPHP\Client\Loaders\PlainPhpLoader; use TweakPHP\Client\Loaders\SymfonyLoader; @@ -101,6 +102,38 @@ public function basePath() { $this->assertArrayHasKey('Illuminate\Support\Collection', $casters); } + public function test_magento_loader_detection_and_boot() + { + mkdir($this->tempDir.'/app', 0777, true); + mkdir($this->tempDir.'/bin', 0777, true); + mkdir($this->tempDir.'/vendor', 0777, true); + touch($this->tempDir.'/bin/magento'); + file_put_contents($this->tempDir.'/vendor/autoload.php', 'tempDir.'/app/bootstrap.php', $bootstrapMock); + + $this->assertTrue(MagentoLoader::supports($this->tempDir)); + + $loader = Loader::load($this->tempDir); + $this->assertInstanceOf(MagentoLoader::class, $loader); + $this->assertEquals('Magento', $loader->name()); + $this->assertEquals('Magento Community 2.4.9', $loader->version()); + } + public function test_symfony_loader_detection_and_boot() { mkdir($this->tempDir.'/vendor', 0777, true);