Skip to content

Commit a1a4738

Browse files
committed
Add MAML recipes
1 parent 5a37745 commit a1a4738

10 files changed

Lines changed: 552 additions & 71 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
],
4242
"require": {
4343
"php": "^8.3",
44+
"maml/maml": "^3.0",
4445
"symfony/console": "^7.4.0 || ^8.0.0",
4546
"symfony/process": "^7.4.0 || ^8.0.0",
4647
"symfony/yaml": "^7.4.0 || ^8.0.0"

src/Deployer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Deployer\Host\Host;
2525
use Deployer\Host\HostCollection;
2626
use Deployer\Host\Localhost;
27-
use Deployer\Importer\Importer;
27+
use Deployer\Import\Import;
2828
use Deployer\Logger\Handler\FileHandler;
2929
use Deployer\Logger\Handler\NullHandler;
3030
use Deployer\Logger\Logger;
@@ -61,7 +61,7 @@
6161
* @property Logger $logger
6262
* @property Collection $fail
6363
* @property InputDefinition $inputDefinition
64-
* @property Importer $importer
64+
* @property Import $importer
6565
*/
6666
class Deployer extends Container
6767
{
@@ -158,7 +158,7 @@ public function __construct(Application $console)
158158
);
159159
};
160160
$this['importer'] = function () {
161-
return new Importer();
161+
return new Import();
162162
};
163163

164164
self::$instance = $this;

src/Exception/SchemaException.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* (c) Anton Medvedev <anton@medv.io>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Deployer\Exception;
12+
13+
class SchemaException extends \RuntimeException {}

src/Import/Import.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* (c) Anton Medvedev <anton@medv.io>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Deployer\Import;
12+
13+
use Deployer\Exception\Exception;
14+
15+
class Import
16+
{
17+
/**
18+
* @param string|string[] $paths
19+
* @throws Exception
20+
*/
21+
public static function import(mixed $paths): void
22+
{
23+
if (!is_array($paths)) {
24+
$paths = [$paths];
25+
}
26+
foreach ($paths as $path) {
27+
if (preg_match('/\.php$/i', $path)) {
28+
// Prevent variable leak into deploy.php file
29+
call_user_func(function () use ($path) {
30+
// Reorder autoload stack
31+
$originStack = spl_autoload_functions();
32+
33+
require $path;
34+
35+
$newStack = spl_autoload_functions();
36+
if ($originStack[0] !== $newStack[0]) {
37+
foreach (array_reverse($originStack) as $loader) {
38+
spl_autoload_unregister($loader);
39+
spl_autoload_register($loader, true, true);
40+
}
41+
}
42+
});
43+
} elseif (preg_match('/\.maml$/i', $path)) {
44+
$recipe = new MamlRecipe($path);
45+
$recipe->run();
46+
} elseif (preg_match('/\.ya?ml$/i', $path)) {
47+
YamlRecipe::exec($path);
48+
} else {
49+
throw new Exception("Unknown file format: $path");
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)