Skip to content

Commit bb9c17e

Browse files
authoredDec 31, 2021
优化代码 (#240)
1 parent 8ee5c60 commit bb9c17e

File tree

5 files changed

+84
-9
lines changed

5 files changed

+84
-9
lines changed
 

‎composer.json

+16-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"require": {},
77
"require-dev": {
88
"yurunsoft/ide-helper": "~1.0",
9-
"swoole/ide-helper": "^4.7"
9+
"swoole/ide-helper": "^4.7",
10+
"phpunit/phpunit": ">=9"
1011
},
1112
"autoload": {
1213
"psr-4": {
@@ -16,10 +17,21 @@
1617
"autoload-dev": {
1718
"psr-4": {
1819
"QueueApp\\": "example/",
19-
"Imi\\Queue\\Test\\": "tests/"
20-
}
20+
"Imi\\Queue\\Test\\": "tests/",
21+
"Imi\\Queue\\Dev\\": "dev/"
22+
},
23+
"files": [
24+
"../../../vendor/autoload.php",
25+
"../../../dev/try-include-swoole.php",
26+
"../workerman/vendor/autoload.php"
27+
]
28+
},
29+
"scripts": {
30+
"pre-install-cmd": "Imi\\Queue\\Dev\\Dev::preUpdate",
31+
"pre-update-cmd": "Imi\\Queue\\Dev\\Dev::preUpdate",
32+
"post-install-cmd": "Imi\\Queue\\Dev\\Dev::postUpdate",
33+
"post-update-cmd": "Imi\\Queue\\Dev\\Dev::postUpdate"
2134
},
22-
"scripts": {},
2335
"extra": {
2436
"ide-helper": {
2537
"list": [

‎dev/Dev.php

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Imi\Queue\Dev;
6+
7+
use Composer\Package\Link;
8+
use Composer\Script\Event;
9+
use Composer\Semver\Constraint\Constraint;
10+
11+
class Dev
12+
{
13+
// @phpstan-ignore-next-line
14+
public static function preUpdate(Event $event): void
15+
{
16+
$dir = \dirname(__DIR__);
17+
// @phpstan-ignore-next-line
18+
$package = $event->getComposer()->getPackage();
19+
$requires = $package->getRequires();
20+
foreach ($requires as $name => &$require)
21+
{
22+
if ('imiphp/' !== substr($name, 0, 7) || !is_dir(\dirname($dir) . '/' . substr($name, 11)))
23+
{
24+
continue;
25+
}
26+
// @phpstan-ignore-next-line
27+
$require = new Link($require->getSource(), $require->getTarget(), new Constraint('>', '0'), $require->getDescription());
28+
}
29+
$package->setRequires($requires);
30+
31+
$requires = $package->getDevRequires();
32+
foreach ($requires as $name => &$require)
33+
{
34+
if ('imiphp/' !== substr($name, 0, 7) || !is_dir(\dirname($dir) . '/' . substr($name, 11)))
35+
{
36+
continue;
37+
}
38+
// @phpstan-ignore-next-line
39+
$require = new Link($require->getSource(), $require->getTarget(), new Constraint('>', '0'), $require->getDescription());
40+
}
41+
$package->setDevRequires($requires);
42+
}
43+
44+
// @phpstan-ignore-next-line
45+
public static function postUpdate(Event $event): void
46+
{
47+
$dir = \dirname(__DIR__);
48+
49+
// @phpstan-ignore-next-line
50+
$package = $event->getComposer()->getPackage();
51+
$requires = array_merge($package->getRequires(), $package->getDevRequires());
52+
foreach ($requires as $name => $require)
53+
{
54+
$componentDir = \dirname($dir) . '/' . substr($name, 11);
55+
if ('imiphp/' !== substr($name, 0, 7) || !is_dir($componentDir))
56+
{
57+
continue;
58+
}
59+
60+
$path = "{$dir}/vendor/{$name}";
61+
$cmd = "rm -rf {$path} && ln -s -f {$componentDir} {$path}";
62+
echo '[cmd] ', $cmd, \PHP_EOL;
63+
echo shell_exec($cmd), \PHP_EOL;
64+
}
65+
}
66+
}

‎example/bin/imi-swoole

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env php
22
<?php
3-
require_once dirname(__DIR__, 2) . '/vendor/' . 'autoload.php';
4-
require_once dirname(__DIR__, 5) . '/vendor/' . 'autoload.php';
3+
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
54

65
\Imi\App::setDebug(true);
76

‎example/bin/imi-workerman

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env php
22
<?php
3-
require_once dirname(__DIR__, 2) . '/vendor/' . 'autoload.php';
4-
require_once dirname(__DIR__, 5) . '/vendor/' . 'autoload.php';
3+
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
54

65
\Imi\App::setDebug(true);
76

‎tests/bootstrap.php

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
declare(strict_types=1);
44

5-
require \dirname(__DIR__, 4) . '/vendor/autoload.php';
65
require \dirname(__DIR__) . '/vendor/autoload.php';
76

87
ini_set('date.timezone', date_default_timezone_get());

0 commit comments

Comments
 (0)
Please sign in to comment.