Skip to content

Commit 6021d88

Browse files
authored
Merge pull request #10 from tweakphp/fix
fix windows & kubernetes
2 parents e2e50b0 + 99fa9e9 commit 6021d88

File tree

15 files changed

+192
-144
lines changed

15 files changed

+192
-144
lines changed

.github/workflows/code-style.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: code-style
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
code-style:
11+
runs-on: ubuntu-22.04
12+
13+
strategy:
14+
fail-fast: true
15+
matrix:
16+
php: [ 8.2 ]
17+
node-version: [ "20.x" ]
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.php }}
26+
27+
- name: Cache Composer packages
28+
id: composer-cache
29+
uses: actions/cache@v2
30+
with:
31+
path: vendor
32+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
33+
restore-keys: |
34+
${{ runner.os }}-php-
35+
36+
- name: Install dependencies
37+
if: steps.composer-cache.outputs.cache-hit != 'true'
38+
run: composer install --prefer-dist --no-progress --no-suggest
39+
40+
- name: Run pint
41+
run: ./vendor/bin/pint --test

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
"psy/psysh": "*"
1919
},
2020
"minimum-stability": "stable",
21-
"prefer-stable": true
21+
"prefer-stable": true,
22+
"require-dev": {
23+
"laravel/pint": "^1.19"
24+
}
2225
}

composer.lock

Lines changed: 69 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
use TweakPHP\Client\Loader;
44

5-
require __DIR__ . '/vendor/autoload.php';
5+
require __DIR__.'/vendor/autoload.php';
66

77
$arguments = $argv;
88

99
if (count($arguments) < 3) {
10-
echo 'Invalid arguments' . PHP_EOL;
10+
echo 'Invalid arguments'.PHP_EOL;
1111
exit(1);
1212
}
1313

@@ -23,7 +23,7 @@ function dd(...$args)
2323
$loader = Loader::load($arguments[1]);
2424

2525
if ($loader === null) {
26-
echo 'Invalid path' . PHP_EOL;
26+
echo 'Invalid path'.PHP_EOL;
2727
exit(1);
2828
}
2929

@@ -34,8 +34,8 @@ function dd(...$args)
3434
'execute',
3535
];
3636

37-
if (!in_array($arguments[2], $supportedCommands)) {
38-
echo 'Invalid command' . PHP_EOL;
37+
if (! in_array($arguments[2], $supportedCommands)) {
38+
echo 'Invalid command'.PHP_EOL;
3939
exit(1);
4040
}
4141

@@ -46,13 +46,13 @@ function dd(...$args)
4646
'version' => $loader->version(),
4747
'php_version' => phpversion(),
4848
]);
49-
echo $info . PHP_EOL;
49+
echo $info.PHP_EOL;
5050
break;
5151
case 'execute':
5252
if (count($arguments) < 4) {
53-
echo 'Invalid arguments' . PHP_EOL;
53+
echo 'Invalid arguments'.PHP_EOL;
5454
exit(1);
5555
}
56-
echo $loader->execute(base64_decode($arguments[3])) . PHP_EOL;
56+
echo $loader->execute(base64_decode($arguments[3])).PHP_EOL;
5757
break;
58-
}
58+
}

src/Loader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
class Loader
1313
{
1414
/**
15-
* @param string $path
1615
* @return null|LoaderInterface
1716
*/
1817
public static function load(string $path)
@@ -29,6 +28,10 @@ public static function load(string $path)
2928
return new WordPressLoader($path);
3029
}
3130

31+
if (PimcoreLoader::supports($path)) {
32+
return new PimcoreLoader($path);
33+
}
34+
3235
if (ComposerLoader::supports($path)) {
3336
return new ComposerLoader($path);
3437
}

src/Loaders/BaseLoader.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@ abstract class BaseLoader implements LoaderInterface
1111
{
1212
protected Tinker $tinker;
1313

14-
public function init()
14+
public function init(): void
1515
{
1616
$config = new Configuration([
1717
'configFile' => null,
1818
]);
1919
$config->setUpdateCheck(Checker::NEVER);
20+
$config->setRawOutput(true);
21+
$config->setInteractiveMode(Configuration::INTERACTIVE_MODE_DISABLED);
22+
$config->setColorMode(Configuration::COLOR_MODE_DISABLED);
23+
$config->setTheme([
24+
'prompt' => '',
25+
]);
26+
$config->setVerbosity(Configuration::VERBOSITY_QUIET);
27+
$config->setHistoryFile(defined('PHP_WINDOWS_VERSION_BUILD') ? 'null' : '/dev/null');
28+
$config->setRawOutput(false);
29+
if (getenv('KUBERNETES_SERVICE_HOST') || defined('PHP_WINDOWS_VERSION_BUILD')) {
30+
$config->setUsePcntl(false);
31+
}
32+
2033
if (class_exists('Illuminate\Support\Collection') && class_exists('Laravel\Tinker\TinkerCaster')) {
2134
$config->getPresenter()->addCasters([
2235
\Illuminate\Support\Collection::class => 'Laravel\Tinker\TinkerCaster::castCollection',
@@ -32,15 +45,14 @@ public function init()
3245
\Illuminate\Foundation\Application::class => 'Laravel\Tinker\TinkerCaster::castApplication',
3346
]);
3447
}
35-
$config->setRawOutput(true);
3648

37-
$this->tinker = new Tinker(new CustomOutputModifier(), $config);
49+
$this->tinker = new Tinker(new CustomOutputModifier, $config);
3850
}
3951

40-
public function execute(string $code)
52+
public function execute(string $code): string
4153
{
4254
$output = $this->tinker->execute($code);
4355

44-
echo trim($output);
56+
return trim($output);
4557
}
46-
}
58+
}

src/Loaders/ComposerLoader.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,23 @@
44

55
class ComposerLoader extends BaseLoader
66
{
7-
/**
8-
* @param string $path
9-
* @return bool
10-
*/
117
public static function supports(string $path): bool
128
{
13-
return file_exists($path . '/vendor/autoload.php');
9+
return file_exists($path.'/vendor/autoload.php');
1410
}
1511

16-
/**
17-
* @param string $path
18-
*/
1912
public function __construct(string $path)
2013
{
21-
require $path . '/vendor/autoload.php';
14+
require $path.'/vendor/autoload.php';
2215
}
2316

2417
public function name(): string
2518
{
2619
return 'Composer Project';
2720
}
2821

29-
/**
30-
* @return string
31-
*/
3222
public function version(): string
3323
{
34-
return "";
24+
return '';
3525
}
3626
}

src/Loaders/LaravelLoader.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,27 @@
22

33
namespace TweakPHP\Client\Loaders;
44

5-
use Throwable;
6-
75
class LaravelLoader extends ComposerLoader
86
{
97
private $app;
108

11-
/**
12-
* @param string $path
13-
* @return bool
14-
*/
159
public static function supports(string $path): bool
1610
{
17-
return file_exists($path . '/vendor/autoload.php') && file_exists($path . '/bootstrap/app.php');
11+
return file_exists($path.'/vendor/autoload.php') && file_exists($path.'/bootstrap/app.php');
1812
}
1913

20-
/**
21-
* @param string $path
22-
*/
2314
public function __construct(string $path)
2415
{
2516
parent::__construct($path);
26-
$this->app = require_once $path . '/bootstrap/app.php';
17+
$this->app = require_once $path.'/bootstrap/app.php';
2718
$this->app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
28-
$classAliases = require $path . '/vendor/composer/autoload_classmap.php';
29-
$vendorPath = dirname($path . '/vendor/composer/autoload_classmap.php', 2);
30-
foreach ($classAliases as $class => $path) {
31-
if (!str_contains($class, '\\')) {
32-
continue;
33-
}
34-
if (str_starts_with($path, $vendorPath)) {
35-
continue;
36-
}
37-
try {
38-
class_alias($class, class_basename($class));
39-
} catch (Throwable $e) {
40-
}
41-
}
4219
}
4320

44-
/**
45-
* @return string
46-
*/
4721
public function name(): string
4822
{
4923
return 'Laravel';
5024
}
5125

52-
/**
53-
* @return string
54-
*/
5526
public function version(): string
5627
{
5728
return $this->app->version();

src/Loaders/LoaderInterface.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,13 @@
44

55
interface LoaderInterface
66
{
7-
/**
8-
* @param string $path
9-
* @return bool
10-
*/
117
public static function supports(string $path): bool;
128

13-
/**
14-
* @return string
15-
*/
169
public function name(): string;
1710

18-
/**
19-
* @return string
20-
*/
2111
public function version(): string;
2212

23-
/**
24-
* @return void
25-
*/
26-
public function init();
13+
public function init(): void;
2714

28-
/**
29-
* @param string $code
30-
* @return void
31-
*/
32-
public function execute(string $code);
15+
public function execute(string $code): string;
3316
}

0 commit comments

Comments
 (0)