├── .gitignore
├── LICENSE
├── README.md
├── bin
└── laravel-coderunner
├── composer.json
└── src
└── boot
└── laravel.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor/
2 | /laravel/
3 | composer.lock
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Levan Velijanashvili
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Laravel CodeRunner
2 | [](https://packagist.org/packages/stichoza/laravel-coderunner) [](https://packagist.org/packages/stichoza/laravel-coderunner) [](https://packagist.org/packages/stichoza/laravel-coderunner) [](https://paypal.me/stichoza)
3 |
4 | Add Laravel support to **[CodeRunner](https://coderunnerapp.com)** (Tinker in CodeRunner).
5 |
6 |
7 |
8 | ## Installation
9 |
10 | Install this package globally via [Composer](https://getcomposer.org/).
11 |
12 | ```bash
13 | composer global require stichoza/laravel-coderunner
14 | ```
15 | And initialize default laravel app (optional).
16 | ```bash
17 | laravel-coderunner install-default
18 | ```
19 |
20 | ## Usage
21 |
22 | ### Add Laravel in CodeRunner langauges
23 |
24 | 1. Go to CodeRunner preferences.
25 | 1. Navigate to Languages tab.
26 | 1. Right-click on `PHP` and select Duplicate.
27 | 1. Name new language `Laravel`.
28 | 1. Write following in the "Run Command" field:
29 |
30 | ```bash
31 | laravel-coderunner $filename
32 | ```
33 |
34 |

35 |
36 | > **Note**
37 | > If you have composer installed correctly in your system, [vendor binaries](https://getcomposer.org/doc/articles/vendor-binaries.md) would be already added in your `.profile` or `.bash_profile`. If not, add it to your profile paths, or otherwise go to CodeRunner preferences, navigate to Advanced tab and add binary path (e.g. `/Users/YOUR_USERNAME/.composer/vendor/bin`) to `PATH` shell variable:
38 |
39 | 
40 |
41 | ### Running in default laravel app
42 |
43 | Default laravel app is already installed via `laravel-coderunner install-default` command. If you want to reset the default app, you can run:
44 | ```bash
45 | laravel-coderunner reset-default
46 | ```
47 |
48 | ### Running in specific project
49 | By default, the code is evaluated in default Laravel installation described above. Follow this steps if you want to run code in different project:
50 |
51 | 1. Assuming you already have Laravel available in CodeRunner, click "Run Settings..." button right next to Run and Stop buttons.
52 | 1. Enter **absolute** path to your project in Arguments field.
53 |
54 | 
55 |
--------------------------------------------------------------------------------
/bin/laravel-coderunner:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | \e[2;32m" . LARAVEL_CODERUNNER_INSTALL_LARAVEL . "\e[0m" . PHP_EOL;
17 | shell_exec(LARAVEL_CODERUNNER_INSTALL_LARAVEL);
18 | die('Done.' . PHP_EOL);
19 | }
20 |
21 | /*
22 | * Variable for laravel-coderunner configuration
23 | */
24 | $laravelCodeRunner = [
25 | 'laravel_version' => null,
26 | ];
27 |
28 | /*
29 | * Build path to composer.lock
30 | */
31 | $laravelCodeRunner['composer_path'] = LARAVEL_CODERUNNER_PROJECT_PATH . '/composer.lock';
32 |
33 | if (file_exists($laravelCodeRunner['composer_path'])) {
34 | try {
35 | /*
36 | * Read and decode composer.lock
37 | */
38 | $laravelCodeRunner['composer_lock'] = json_decode(file_get_contents($laravelCodeRunner['composer_path']), true);
39 | } catch (Exception $e) {
40 | die('Unable to read contents of composer.lock for project.' . PHP_EOL);
41 | }
42 |
43 | /*
44 | * Iterate over installed packages to find laravel/framework installation
45 | */
46 | foreach ($laravelCodeRunner['composer_lock']['packages'] ?? [] as $laravelCodeRunnerPackage) {
47 | if ($laravelCodeRunnerPackage['name'] === 'laravel/framework') {
48 | $laravelCodeRunner['laravel_version'] = preg_replace('/[^0-9\.]/', '', $laravelCodeRunnerPackage['version']);
49 | break;
50 | }
51 | }
52 |
53 | /*
54 | * Check laravel installation
55 | */
56 | if (!$laravelCodeRunner['laravel_version']) {
57 | die('Unable to locate laravel installation in path.' . PHP_EOL);
58 | }
59 | } else {
60 | die('Unable to locate composer.lock for project.' . PHP_EOL);
61 | }
62 |
63 | /*
64 | * Check laravel version and boot application accordingly
65 | */
66 | if (version_compare($laravelCodeRunner['laravel_version'], '5.5.0', '>=')) {
67 | require_once __DIR__.'/../src/boot/laravel.php';
68 | } else {
69 | die('Laravel ' . $laravelCodeRunner['laravel_version'] . ' not supported' . PHP_EOL);
70 | }
71 |
72 | /*
73 | * Run coderunner script
74 | */
75 | if (substr($argv[1], 0, 1) === '/') {
76 | require_once $argv[1];
77 | } else {
78 | require_once trim(shell_exec('pwd')) . '/' . $argv[1];
79 | }
80 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "stichoza/laravel-coderunner",
3 | "description": "Add Laravel support to CodeRunner",
4 | "keywords": ["laravel", "coderunner", "mac", "tinker", "tinkerwell", "psy", "shell"],
5 | "license": "MIT",
6 | "type": "library",
7 | "bin": [
8 | "bin/laravel-coderunner"
9 | ],
10 | "authors": [
11 | {
12 | "name": "Levan Velijanashvili",
13 | "email": "me@stichoza.com"
14 | }
15 | ],
16 | "require": {
17 | "php": "^7.2|^8.0"
18 | },
19 | "scripts": {
20 | "install-laravel": [
21 | "rm -rf laravel",
22 | "@composer create-project --prefer-dist laravel/laravel laravel"
23 | ],
24 | "post-package-install": "@install-laravel",
25 | "post-package-update": "@install-laravel"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/boot/laravel.php:
--------------------------------------------------------------------------------
1 | make(Illuminate\Contracts\Http\Kernel::class);
10 |
11 | $response = $kernel->handle(
12 | $request = Illuminate\Http\Request::capture()
13 | );
--------------------------------------------------------------------------------