Skip to content

Commit 8b84ddc

Browse files
committed
Пост-инсталльная команда композера для копирования консольной команды в DOCUMENT_ROOT . /bin.
1 parent 9e748fb commit 8b84ddc

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

bin/console renamed to bin/module

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use Symfony\Component\Filesystem\Filesystem;
99

1010
@set_time_limit(0);
1111

12-
$_SERVER['DOCUMENT_ROOT'] = __DIR__. DIRECTORY_SEPARATOR . '../../../..';
12+
$_SERVER['DOCUMENT_ROOT'] = __DIR__ . DIRECTORY_SEPARATOR . '../../../..';
1313
$GLOBALS['DOCUMENT_ROOT'] = $_SERVER['DOCUMENT_ROOT'];
1414

1515
$autoloadPath = $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,13 @@
2121
},
2222
"autoload": {
2323
"psr-4": {"ProklUng\\ModuleGenerator\\": "src"}
24+
},
25+
"scripts": {
26+
"post-update-cmd": [
27+
"ProklUng\\ComposerScript\\InstallUpdateHandler::doInstall"
28+
],
29+
"post-install-cmd": [
30+
"ProklUng\\ComposerScript\\InstallUpdateHandler::doInstall"
31+
]
2432
}
2533
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace ProklUng\ModuleGenerator\ComposerScript;
4+
5+
use Composer\Script\Event;
6+
use InvalidArgumentException;
7+
use Symfony\Component\Filesystem\Exception\IOException;
8+
use Symfony\Component\Filesystem\Filesystem;
9+
10+
/**
11+
* Class InstallUpdateHandler
12+
* @package Local\ComposerScript
13+
*/
14+
class InstallUpdateHandler
15+
{
16+
/**
17+
* @param Event $event
18+
*
19+
* @throws InvalidArgumentException
20+
*/
21+
public static function doInstall(Event $event): void
22+
{
23+
$io = $event->getIO();
24+
25+
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir');
26+
27+
$projectRoot = realpath($vendorDir. '/../');
28+
29+
if (!is_dir($projectRoot) || !is_readable($projectRoot) || !is_writable($projectRoot)) {
30+
$io->write(
31+
\sprintf(
32+
'<error>Directory "%s" is not writable. Aborting</error>',
33+
$projectRoot
34+
)
35+
);
36+
37+
return;
38+
}
39+
40+
$filesystem = new Filesystem();
41+
try {
42+
$filesystem->mirror(
43+
__DIR__.'/bin/',
44+
$projectRoot . '/bin/'
45+
);
46+
} catch (IOException $e) {
47+
$io->write('<error>Error copy command for generate modules : ' . $e->getMessage() . '</error>');
48+
}
49+
50+
$io->write('Console command for generate modules successfully installed.');
51+
}
52+
}

0 commit comments

Comments
 (0)