Skip to content
Merged

Fix #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: code-style

on:
push:
branches:
- main
pull_request:

jobs:
code-style:
runs-on: ubuntu-22.04

strategy:
fail-fast: true
matrix:
php: [ 8.2 ]
node-version: [ "20.x" ]

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run pint
run: ./vendor/bin/pint --test
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
"psy/psysh": "*"
},
"minimum-stability": "stable",
"prefer-stable": true
"prefer-stable": true,
"require-dev": {
"laravel/pint": "^1.19"
}
}
71 changes: 69 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

use TweakPHP\Client\Loader;

require __DIR__ . '/vendor/autoload.php';
require __DIR__.'/vendor/autoload.php';

$arguments = $argv;

if (count($arguments) < 3) {
echo 'Invalid arguments' . PHP_EOL;
echo 'Invalid arguments'.PHP_EOL;
exit(1);
}

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

if ($loader === null) {
echo 'Invalid path' . PHP_EOL;
echo 'Invalid path'.PHP_EOL;
exit(1);
}

Expand All @@ -34,8 +34,8 @@ function dd(...$args)
'execute',
];

if (!in_array($arguments[2], $supportedCommands)) {
echo 'Invalid command' . PHP_EOL;
if (! in_array($arguments[2], $supportedCommands)) {
echo 'Invalid command'.PHP_EOL;
exit(1);
}

Expand All @@ -46,13 +46,13 @@ function dd(...$args)
'version' => $loader->version(),
'php_version' => phpversion(),
]);
echo $info . PHP_EOL;
echo $info.PHP_EOL;
break;
case 'execute':
if (count($arguments) < 4) {
echo 'Invalid arguments' . PHP_EOL;
echo 'Invalid arguments'.PHP_EOL;
exit(1);
}
echo $loader->execute(base64_decode($arguments[3])) . PHP_EOL;
echo $loader->execute(base64_decode($arguments[3])).PHP_EOL;
break;
}
}
5 changes: 4 additions & 1 deletion src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
class Loader
{
/**
* @param string $path
* @return null|LoaderInterface
*/
public static function load(string $path)
Expand All @@ -29,6 +28,10 @@ public static function load(string $path)
return new WordPressLoader($path);
}

if (PimcoreLoader::supports($path)) {
return new PimcoreLoader($path);
}

if (ComposerLoader::supports($path)) {
return new ComposerLoader($path);
}
Expand Down
24 changes: 18 additions & 6 deletions src/Loaders/BaseLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,25 @@ abstract class BaseLoader implements LoaderInterface
{
protected Tinker $tinker;

public function init()
public function init(): void
{
$config = new Configuration([
'configFile' => null,
]);
$config->setUpdateCheck(Checker::NEVER);
$config->setRawOutput(true);
$config->setInteractiveMode(Configuration::INTERACTIVE_MODE_DISABLED);
$config->setColorMode(Configuration::COLOR_MODE_DISABLED);
$config->setTheme([
'prompt' => '',
]);
$config->setVerbosity(Configuration::VERBOSITY_QUIET);
$config->setHistoryFile(defined('PHP_WINDOWS_VERSION_BUILD') ? 'null' : '/dev/null');
$config->setRawOutput(false);
if (getenv('KUBERNETES_SERVICE_HOST') || defined('PHP_WINDOWS_VERSION_BUILD')) {
$config->setUsePcntl(false);
}

if (class_exists('Illuminate\Support\Collection') && class_exists('Laravel\Tinker\TinkerCaster')) {
$config->getPresenter()->addCasters([
\Illuminate\Support\Collection::class => 'Laravel\Tinker\TinkerCaster::castCollection',
Expand All @@ -32,15 +45,14 @@ public function init()
\Illuminate\Foundation\Application::class => 'Laravel\Tinker\TinkerCaster::castApplication',
]);
}
$config->setRawOutput(true);

$this->tinker = new Tinker(new CustomOutputModifier(), $config);
$this->tinker = new Tinker(new CustomOutputModifier, $config);
}

public function execute(string $code)
public function execute(string $code): string
{
$output = $this->tinker->execute($code);

echo trim($output);
return trim($output);
}
}
}
16 changes: 3 additions & 13 deletions src/Loaders/ComposerLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,23 @@

class ComposerLoader extends BaseLoader
{
/**
* @param string $path
* @return bool
*/
public static function supports(string $path): bool
{
return file_exists($path . '/vendor/autoload.php');
return file_exists($path.'/vendor/autoload.php');
}

/**
* @param string $path
*/
public function __construct(string $path)
{
require $path . '/vendor/autoload.php';
require $path.'/vendor/autoload.php';
}

public function name(): string
{
return 'Composer Project';
}

/**
* @return string
*/
public function version(): string
{
return "";
return '';
}
}
33 changes: 2 additions & 31 deletions src/Loaders/LaravelLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,27 @@

namespace TweakPHP\Client\Loaders;

use Throwable;

class LaravelLoader extends ComposerLoader
{
private $app;

/**
* @param string $path
* @return bool
*/
public static function supports(string $path): bool
{
return file_exists($path . '/vendor/autoload.php') && file_exists($path . '/bootstrap/app.php');
return file_exists($path.'/vendor/autoload.php') && file_exists($path.'/bootstrap/app.php');
}

/**
* @param string $path
*/
public function __construct(string $path)
{
parent::__construct($path);
$this->app = require_once $path . '/bootstrap/app.php';
$this->app = require_once $path.'/bootstrap/app.php';
$this->app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
$classAliases = require $path . '/vendor/composer/autoload_classmap.php';
$vendorPath = dirname($path . '/vendor/composer/autoload_classmap.php', 2);
foreach ($classAliases as $class => $path) {
if (!str_contains($class, '\\')) {
continue;
}
if (str_starts_with($path, $vendorPath)) {
continue;
}
try {
class_alias($class, class_basename($class));
} catch (Throwable $e) {
}
}
}

/**
* @return string
*/
public function name(): string
{
return 'Laravel';
}

/**
* @return string
*/
public function version(): string
{
return $this->app->version();
Expand Down
21 changes: 2 additions & 19 deletions src/Loaders/LoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,13 @@

interface LoaderInterface
{
/**
* @param string $path
* @return bool
*/
public static function supports(string $path): bool;

/**
* @return string
*/
public function name(): string;

/**
* @return string
*/
public function version(): string;

/**
* @return void
*/
public function init();
public function init(): void;

/**
* @param string $code
* @return void
*/
public function execute(string $code);
public function execute(string $code): string;
}
Loading
Loading