laravel-bridge/scratch
Start Laravel project from scratch.
Installation
Run the following command to require package:
composer require laravel-bridge/scratch
Usage
Setup when you want to use the package
Database
Require
illuminate/databaseandilluminate/events
Method setupDatabaseConfig() has 3 arguments, the following is signature:
public function setupDatabaseConfig(string $name, array $connection, bool $default = false);
$nameis the database name.$connectionis the database config only.$defaultwill set the default database if true.
Method setupDatabaseConfigs() has 2 arguments, the following is signature:
public function setupDatabaseConfig(array $connections, string $default = 'default');
$connectionsis the all connections config.$defaultspecify the connection is default.
Examples
index.php example for Database:
use LaravelBridge\Scratch\Application;
$connections = [
'driver' => 'sqlite',
'database' => __DIR__ . '/sqlite.db',
];
$app = Application::getInstance()
->setupDatabaseConfig('default', $connections, true)
->bootstrap();
Eloquent is easy, too.
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
}
// ---
$user = new User();
$user->username = 'root';
$user->password = 'password';
$user->save();
User::all()->toArray();
View
Require
illuminate/view, requireilluminate/translationwhen need translation.
index.php example for View:
use LaravelBridge\Scratch\Application;
Application::getInstance()
->setupTranslator(__DIR__ . '/lang')
->setupView(__DIR__, __DIR__ . '/compiled')
->withFacades()
->bootstrap();
echo View::make('view', ['rows' => [1, 2, 3]]);
Template example view.blade.php:
@foreach ($rows as $row)
{{ $row }}
@endforeach
Logging
Require
illuminate/logandilluminate/events
Method setupLogger() has 3 arguments, the following is signature:
public function setupLogger(string $name, LoggerInterface $logger, bool $default = false);
$nameis the Log name, and use FacadeLog::driver($name)to specify.$loggeris the instance implementedPsr\Log\LoggerInterface.$defaultwill set the default log driver if true.
Here is a testing example:
$spy = new TestHandler();
$logger = new Monolog\Logger('test');
$logger->pushHandler($spy);
$this->target->setupLogger('test', $logger, true)
->bootstrap();
Log::info('log_test');
$this->assertTrue($spy->hasInfoRecords());
Configuration
The configuration will use illuminate/config package. Following is the priority.
- Setup method config or setup step
- Configuration Loader or bootstrap step
Facade
Use withFacades() to active Facade and register short class:
$app->withFacades();
View::make(); // It's works
Bootstrap
Bootstrap is a lifecycle in Laravel Kernel. The following is bootstrapper order.
\Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables::class
\Illuminate\Foundation\Bootstrap\LoadConfiguration::class
\Illuminate\Foundation\Bootstrap\HandleExceptions::class
\Illuminate\Foundation\Bootstrap\RegisterFacades::class
\Illuminate\Foundation\Bootstrap\RegisterProviders::class
\Illuminate\Foundation\Bootstrap\BootProviders::class
In Scratch application, we can load config functionally. and use withFacades() to register Facade first. finally, call ServiceProvider::register() on every provider when call bootstrap(). Next, call ServiceProvider::boot() on every provider, just like Laravel Kernel.
bootstrap() has an argument $withAllLaravelProviders, register all laravel provider when true. Also, It's default true. However, use withoutLaravelProvider() if you don't want use some Laravel providers.
Example Projects or Libraries
Projects:
Libraries:
Thanks
- Idea by @recca0120
- Logo by @ycs77
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 1.7.0 | ^7.1 | | ^5.6 | | MIT | |
| 1.6.0 | ^7.1 | ^5.6 | | MIT | |
| v1.5.0 | >=7.1 | ^5.6 | | MIT | |
| v1.4.0 | >=7.1 | ^5.6 | | MIT | |
| v1.3.0 | >=7.1 | ^5.6 | | MIT | |
| v1.2.0 | >=7.1 | ^5.6 | | MIT | |
| v1.1.0 | >=7.1 | ^5.6 | | MIT | |
| v1.0.1 | >=7.1 | ^5.6 | | MIT | |
| v1.0.0 | >=7.1 | ^5.6 | | MIT | |
| v0.9.2 | >=7.1 | ^5.6 | | MIT | |
| v0.9.1 | >=7.1 | ^5.6 | | MIT | |
| v0.9.0 | >=7.1 | ^5.6 | | MIT | |
| v0.8.1 | >=7.1 | ^5.6 | | MIT | |
| v0.8.0 | >=7.1 | ^5.6 | | MIT | |
| v0.7.0 | >=7.1 | ^5.6 | | MIT | |
| v0.6.0 | >=7.1 | ^5.6 | | MIT | |
| v0.5.2 | >=7.1 | ^5.6 | | MIT | |
| v0.5.1 | >=7.1 | ^5.6 | | MIT | |
| v0.5.0 | >=7.1 | ^5.6 | | MIT | |
| v0.4.1 | >=7.1 | ^5.6 | | MIT | |
| v0.4.0 | >=7.1 | ^5.6 | | MIT | |
| v0.3.0 | >=7.1 | ^5.6 | | MIT | |
| v0.2.0 | >=7.1 | ^5.6 | | MIT | |
| v0.1.4 | >=7.1 | ^5.6 | | MIT | |
| v0.1.3 | >=7.1 | ^5.6 | | MIT | |
| v0.1.2 | >=7.1 | ^5.6 | | MIT | |
| v0.1.1 | >=7.1 | ^5.6 | | MIT | |
| v0.1.0 | >=7.1 | ^5.6 | | MIT |