简体   繁体   English

从 php 应用程序构建 phar 文件时我需要考虑什么使用像 laravel 这样的 php 框架

[英]what i need to consider when building phar file from php application use php framework like laravel

I am php developer use laravel-4 as framework for building web applications , in the last few days I wanted to create phar file from my web application created on laravel framework .我是 php 开发人员,使用 laravel-4 作为构建 web 应用程序的框架,在过去的几天里,我想从在 laravel 框架上创建的 web 应用程序创建 phar 文件。

I searched in the web for tools build php archive files (.phar) and I found PHP box , this tool is very good and use json configuration file for building the phar files but i could not use it for creating my phar files because there is many considerations when creating phar file from a web application use a framework like laravel .我在网上搜索了工具 build php archive files (.phar),我找到了PHP box ,这个工具非常好,使用 json 配置文件来构建 phar 文件,但我无法使用它来创建我的 phar 文件,因为有从 web 应用程序创建 phar 文件时的许多注意事项使用像 laravel 这样的框架。 my questions are :我的问题是:

laravel use composer autoloader as auto loading mechanism laravel 使用 composer autoloader 作为自动加载机制

1- how to handle composer auto loading mechanism ? 1-如何处理composer自动加载机制?

2- how to handle the framework bootstrapping process ? 2-如何处理框架引导过程? 'like laravel' '像laravel'

3- what i need to make the browser read my index page from inside the phar file ? 3- 我需要什么才能让浏览器从 phar 文件中读取我的索引页?

4- how to use framework command line tools from the phar file ? 4- 如何使用 phar 文件中的框架命令行工具? 'like laravel-artisan' '像laravel-工匠'

You might use composer.json in your application and require box there.您可以在应用程序中使用 composer.json 并在那里使用 require 框。 When your application runs on laravel, you know that your bootstrap works and would also work inside a phar.当你的应用程序在 laravel 上运行时,你知道你的引导程序可以工作并且也可以在 phar 中工作。

I believe Box brings a lot of the composer autloading stuff itself, so you won't run into trouble with it.我相信 Box 本身带来了很多作曲家自动加载的东西,所以你不会遇到麻烦。 I think the class_map gets included automatically.我认为 class_map 会自动包含在内。

One thing to consider is, that configuration details must be passed in!需要考虑的一件事是,必须传入配置细节!

In general, you need to "forward" to your application, which is inside the phar, like so:通常,您需要“转发”到您的应用程序,它位于 phar 内部,如下所示:

<?php
require_once "phar://myapp.phar/frontcontroller.php"; // maybe index.php
$config = array('dsn' => 'database-config');
Application::run($config);

Also accessing a PHAR in a PHAR is a problem!在 PHAR 中访问 PHAR 也是一个问题!

You can't access a PHAR packaged in a PHAR directly.您不能直接访问打包在 PHAR 中的 PHAR。 Firstly you need to extract the packaged PHAR, secondly do the forwarding call and pass the CLI commands along.首先,您需要提取打包的 PHAR,其次进行转发调用并传递 CLI 命令。 Problem solved here: https://stackoverflow.com/a/13537329/1163786问题在这里解决: https : //stackoverflow.com/a/13537329/1163786

Full Example完整示例

box.json.dist box.json.dist

{
  "main": "bootstrap.php",
  "output": "application.phar",
  "compactors": ["Herrera\\Box\\Compactor\\Composer"],
  "chmod": "0755",
  "directories": ["src/"],
  "stub": true
}

bootstrap.php引导程序

<?php
require 'vendor/autoload.php'; //<-- this is autoload.php generated by Composer

use MyApp\Application;

$config = parse_ini_file(__DIR__.'/config.ini');

$app = new Application();
$app->run($config);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM