Frames

0
1<?php
2
3namespace TinyPixel\AcornDB\Providers;
4
5use Roots\Acorn\ServiceProvider;
6use Illuminate\Database\Eloquent\Factory as EloquentFactory;
7use Faker\Generator as FakerGenerator;
8use TinyPixel\Support\Util;
9
10/**
11 * Acorn database service provider
12 *
13 * @author Kelly Mears <kelly@tinypixel.dev>
14 * @license MIT
15 * @since 1.0.0
16 *
17 * @package AcornDB
18 * @subpackage Providers
19 **/
20class PackageServiceProvider extends ServiceProvider
21{
22 /**
23 * Console commands
24 *
25 * @var array
26 */
27 public $commands = [
28 'TinyPixel\AcornDB\Console\Commands\Migrate\FreshCommand',
29 'TinyPixel\AcornDB\Console\Commands\Migrate\InstallCommand',
30 'TinyPixel\AcornDB\Console\Commands\Migrate\MakeCommand',
31 'TinyPixel\AcornDB\Console\Commands\Migrate\MigrateCommand',
32 'TinyPixel\AcornDB\Console\Commands\Migrate\RefreshCommand',
33 'TinyPixel\AcornDB\Console\Commands\Migrate\ResetCommand',
34 'TinyPixel\AcornDB\Console\Commands\Migrate\RollbackCommand',
35 'TinyPixel\AcornDB\Console\Commands\Migrate\StatusCommand',
36 'TinyPixel\AcornDB\Console\Commands\Seeds\SeedCommand',
37 'TinyPixel\AcornDB\Console\Commands\Seeds\SeederMakeCommand',
38 'TinyPixel\AcornDB\Console\Commands\Factories\FactoryMakeCommand',
39 ];
40
41 public function register()
42 {
43 $this->app->bind('tinypixel.util', function ($app) {
44 return Util::getInstance()->container['util'];
45 });
46 }
47
48 public function boot()
49 {
50 $this->publishes([
51 __DIR__ . '/../../publishes/Model' => $this->modelDirectory(),
52 __DIR__ . '/../../publishes/config/database.php' => $this->app->configPath('database.php'),
53 __DIR__ . '/../../publishes/database' => $this->app->basePath('database'),
54 ], 'Acorn Database');
55
56 $this->commands($this->commands);
57
58 $this->registerFrom($this->app->basePath('database/seeds'));
59 }
60
61 /**
62 * Return the App/Model directory
63 */
64 protected function modelDirectory()
65 {
66 return $this->app->basePath($this->appDirectory() . '/Model');
67 }
68
69 /**
70 * Return the App directory.
71 */
72 protected function appDirectory()
73 {
74 return substr(strtolower($this->app->getNamespace()), 0, -1);
75 }
76
77 /**
78 * Register database seeders
79 *
80 * @param string $path
81 * @return void
82 **/
83 protected function registerFrom(string $path) : void
84 {
85 foreach (glob("$path/*.php") as $filename) {
86 require $filename;
87 }
88 }
89}
90