Skip to content

Commit 6ecc6d8

Browse files
committed
Added install hyperf script.
1 parent ae10dd8 commit 6ecc6d8

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

installer/OptionalPackages.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ public function __construct(IOInterface $io, Composer $composer, string $project
120120
$this->installerSource = realpath(__DIR__) . '/';
121121
}
122122

123+
public function installHyperfScript()
124+
{
125+
$answer = $this->io->ask('', (string)'');
126+
127+
var_dump($answer);
128+
}
129+
123130
/**
124131
* Create data and cache directories, if not present.
125132
*
@@ -130,7 +137,7 @@ public function setupRuntimeDir(): void
130137
$this->io->write('<info>Setup data and cache dir</info>');
131138
$runtimeDir = $this->projectRoot . '/runtime';
132139

133-
if (! is_dir($runtimeDir)) {
140+
if (!is_dir($runtimeDir)) {
134141
mkdir($runtimeDir, 0775, true);
135142
chmod($runtimeDir, 0775);
136143
}
@@ -249,14 +256,14 @@ public function processAnswer(array $question, $answer): bool
249256
}
250257
// Copy files
251258
if (isset($question['options'][$answer])) {
252-
$force = ! empty($question['force']);
259+
$force = !empty($question['force']);
253260
foreach ($question['options'][$answer]['resources'] as $resource => $target) {
254261
$this->copyResource($resource, $target, $force);
255262
}
256263
}
257264
return true;
258265
}
259-
if ($question['custom-package'] === true && preg_match(self::PACKAGE_REGEX, (string) $answer, $match)) {
266+
if ($question['custom-package'] === true && preg_match(self::PACKAGE_REGEX, (string)$answer, $match)) {
260267
$this->addPackage($match['name'], $match['version'], []);
261268
if (isset($question['custom-package-warning'])) {
262269
$this->io->write(sprintf(' <warning>%s</warning>', $question['custom-package-warning']));
@@ -310,7 +317,7 @@ public function addPackage(string $packageName, string $packageVersion, array $w
310317
}
311318
// Whitelist packages for the component installer
312319
foreach ($whitelist as $package) {
313-
if (! in_array($package, $this->composerDefinition['extra']['zf']['component-whitelist'], true)) {
320+
if (!in_array($package, $this->composerDefinition['extra']['zf']['component-whitelist'], true)) {
314321
$this->composerDefinition['extra']['zf']['component-whitelist'][] = $package;
315322
$this->io->write(sprintf(' - Whitelist package <info>%s</info>', $package));
316323
}
@@ -331,7 +338,7 @@ public function copyResource(string $resource, string $target, bool $force = fal
331338
return;
332339
}
333340
$destinationPath = dirname($this->projectRoot . $target);
334-
if (! is_dir($destinationPath)) {
341+
if (!is_dir($destinationPath)) {
335342
mkdir($destinationPath, 0775, true);
336343
}
337344
$this->io->write(sprintf(' - Copying <info>%s</info>', $target));
@@ -398,20 +405,20 @@ private function askQuestion(array $question, $defaultOption)
398405
: sprintf(' Make your selection <comment>(%s)</comment>: ', $defaultText);
399406
while (true) {
400407
// Ask for user input
401-
$answer = $this->io->ask(implode($ask), (string) $defaultOption);
408+
$answer = $this->io->ask(implode($ask), (string)$defaultOption);
402409
// Handle none of the options
403410
if ($answer === 'n' && $question['required'] !== true) {
404411
return 'n';
405412
}
406413
// Handle numeric options
407-
if (is_numeric($answer) && isset($question['options'][(int) $answer])) {
408-
return (int) $answer;
414+
if (is_numeric($answer) && isset($question['options'][(int)$answer])) {
415+
return (int)$answer;
409416
}
410417
// Search for package
411418
if ($question['custom-package'] === true && preg_match(self::PACKAGE_REGEX, $answer, $match)) {
412419
$packageName = $match['name'];
413420
$packageVersion = $match['version'];
414-
if (! $packageVersion) {
421+
if (!$packageVersion) {
415422
$this->io->write('<error>No package version specified</error>');
416423
continue;
417424
}
@@ -435,7 +442,7 @@ private function askQuestion(array $question, $defaultOption)
435442
*/
436443
private function recursiveRmdir(string $directory): void
437444
{
438-
if (! is_dir($directory)) {
445+
if (!is_dir($directory)) {
439446
return;
440447
}
441448
$rdi = new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS);

installer/Script.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static function install(Event $event)
2424

2525
$installer->setupRuntimeDir();
2626
$installer->removeDevDependencies();
27+
$installer->installHyperfScript();
2728
$installer->promptForOptionalPackages();
2829
$installer->updateRootPackage();
2930
$installer->removeInstallerFromDefinition();

installer/resources/bin/hyperf.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
ini_set('display_errors', 'on');
5+
ini_set('display_startup_errors', 'on');
6+
7+
error_reporting(E_ALL);
8+
date_default_timezone_set('%TIME_ZONE%');
9+
10+
! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
11+
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);
12+
13+
require BASE_PATH . '/vendor/autoload.php';
14+
15+
// Self-called anonymous function that creates its own scope and keep the global namespace clean.
16+
(function () {
17+
/** @var \Psr\Container\ContainerInterface $container */
18+
$container = require BASE_PATH . '/config/container.php';
19+
20+
$application = $container->get(\Hyperf\Contract\ApplicationInterface::class);
21+
$application->run();
22+
})();

0 commit comments

Comments
 (0)