Downloads
Stars
Version
Start Laravel project from scratch.
Run the following command to require package:
composer require laravel-bridge/scratch
Setup when you want to use the package
Require
illuminate/database
andilluminate/events
Method setupDatabaseConfig()
has 3 arguments, the following is signature:
public function setupDatabaseConfig(string $name, array $connection, bool $default = false);
$name
is the database name.$connection
is the database config only.$default
will set the default database if true.Method setupDatabaseConfigs()
has 2 arguments, the following is signature:
public function setupDatabaseConfig(array $connections, string $default = 'default');
$connections
is the all connections config.$default
specify the connection is default.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();
Require
illuminate/view
, requireilluminate/translation
when 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
Require
illuminate/log
andilluminate/events
Method setupLogger()
has 3 arguments, the following is signature:
public function setupLogger(string $name, LoggerInterface $logger, bool $default = false);
$name
is the Log name, and use Facade Log::driver($name)
to specify.$logger
is the instance implemented Psr\Log\LoggerInterface
.$default
will 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());
The configuration will use illuminate/config
package. Following is the priority.
Use withFacades()
to active Facade and register short class:
$app->withFacades();
View::make(); // It's works
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.
Projects:
Libraries: