modulusphp/upstart

点燃您的应用

0.1 2019-12-28 06:58 UTC

README

该组件负责启动Craftsman和您的Modulus应用。

安装

此包将自动与Modulus框架一起安装。

注意:Upstart在Modulus的旧版本中没有配置

composer require modulusphp/upstart

配置

要开始,请在bootstrap目录中添加一个app.php文件,内容如下

<?php

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer has classes that we need to get our application running, all
| we need to do is just load it onto our script and we should be good to
| go!
|
*/

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

/*
|--------------------------------------------------------------------------
| Craft The Application
|--------------------------------------------------------------------------
|
| We first need to create a new instance of the application. Modulus
| will configure services that are needed by the rest of the application
| for you.
|
*/

$app = Modulus\Upstart\Application::boot(realpath(__DIR__ . '/../'));

$app->make(new Modulus\Upstart\Boot\BugsnagHandler);

$app->make(new Modulus\Upstart\Boot\WhoopsHandler);

$app->make(new Modulus\Upstart\Boot\EloquentHandler);

$app->make(
  new Modulus\Upstart\Boot\ApplicationServices([
    'httpFoundation' => App\Http\HttpFoundation::class,
    'handler' => App\Exceptions\Handler::class,
    'routerResolver' => App\Resolvers\RouterResolver::class,
    'appServiceResolver' => App\Resolvers\AppServiceResolver::class
  ])
);

/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| Once the services have been loaded in the config, we will then return
| the instance of the application.
|
*/

return $app;

确保以下类被扩展

现在,转到public/index.php并替换内容为

<?php

/**
 * Modulus - A cool API Framework for PHP
 *
 * @package Modulus
 * @author  Donald Pakkies <donaldpakkies@gmail.com>
 */

define('MODULUS_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| Before we can run the application, we will need to get it from the
| bootstrap, after getting it, we will be able to build a response and
| send it back to the browser.
|
*/

$app = require('../bootstrap/app.php');

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Now that we have required the application and have added our configs,
| we can send a response back to the browser. To get the response, we
| basically just need to pass our application instance to the response
| make method. So let's try it and see what we get!
|
*/

return Modulus\Upstart\Response::make($app);

完成上述操作后,更新craftsman

#!/usr/bin/env php
<?php

/**
 * Modulus - A cool API Framework for PHP
 *
 * @package  Modulus
 * @author   Donald Pakkies <donaldpakkies@gmail.com>
 */

define('MODULUS_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| Before we can run the application, we will need to get it from the
| bootstrap, after getting it, we will be able to build a response and
| send it back to the browser.
|
*/

/** @var \Modulus\Upstart\Application $app */
$app = require('bootstrap/app.php');

/*
|--------------------------------------------------------------------------
| Register Craftsman
|--------------------------------------------------------------------------
|
| Since we are running our application through the cli, we need to
| register a couple of commands so they can be used through the terminal.
| To get started, we just need to pass our kernel class to the console
| method. And that's pretty much it!
|
*/

$app->console(App\Console\Kernel::class);

/*
|--------------------------------------------------------------------------
| Run Craftsman
|--------------------------------------------------------------------------
|
| To get craftsman to run, we just need to pass it to the response make
| make method, "make" will return a response back to the terminal. So
| let's see if this works.
|
*/

return Modulus\Upstart\Response::make($app);

就是这样,您的应用已经点燃!。

让一切正常工作

由于我们正在用upstart替换旧的框架核心,我们需要确保我们的代码库有必要的代码。

应用服务

<?php

namespace App\Resolvers;

use Modulus\Upstart\Service;

class AppServiceResolver extends Service
{
  /**
   * Register application services
   *
   * @return void
   */
  protected function boot() : void
  {
    //
  }
}

路由服务

<?php

namespace App\Resolvers;

use Modulus\Upstart\Resolvers\Router\Service;

class RouterResolver extends Service
{
  /**
   * Redirect route after authentication
   *
   * @var string
   */
  public const HOME = '/';

  /**
   * Register application routes
   *
   * @return void
   */
  protected function boot() : void
  {
    $this->apiRoutes();
    $this->webRoutes();
  }

  /**
   * Load api routes
   *
   * @param object $app
   * @return void
   */
  protected function apiRoutes() : void
  {
    $this->route->make(base_path('routes/api.php'))
        ->middleware('api')
        ->prefix('api')
        ->register();
  }

  /**
   * Load web routes
   *
   * @return void
   */
  protected function webRoutes() : void
  {
    $this->route->make(base_path('routes/web.php'))
        ->middleware('web')
        ->register();
  }
}

安全

如果您发现任何与安全相关的问题,请通过电子邮件donaldpakkies@gmail.com联系,而不是使用问题跟踪器。

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件