123456789101112131415161718192021222324252627282930313233 |
- <!DOCTYPE html>
- <html lang="en" dir="ltr">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <title>Introduction to project structure | static-php-cli</title>
- <meta name="description" content="Build single static PHP binary, with PHP project together, with popular extensions included.">
- <meta name="generator" content="VitePress v1.2.3">
- <link rel="preload stylesheet" href="/assets/style.DdViOfjJ.css" as="style">
-
- <script type="module" src="/assets/app.D3H8Y1BO.js"></script>
- <link rel="preload" href="/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
- <link rel="modulepreload" href="/assets/chunks/framework.gjrnbxUT.js">
- <link rel="modulepreload" href="/assets/chunks/theme.5IQMzWyn.js">
- <link rel="modulepreload" href="/assets/en_develop_structure.md.BA5PDIse.lean.js">
- <script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
- <script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
- </head>
- <body>
- <div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-ccf7ddec><div class="wrapper" data-v-ccf7ddec><div class="container" data-v-ccf7ddec><div class="title" data-v-ccf7ddec><div class="VPNavBarTitle has-sidebar" data-v-ccf7ddec data-v-ab179fa1><a class="title" href="/en/" data-v-ab179fa1><!--[--><!--]--><!----><span data-v-ab179fa1>static-php-cli</span><!--[--><!--]--></a></div></div><div class="content" data-v-ccf7ddec><div class="content-body" data-v-ccf7ddec><!--[--><!--]--><div class="VPNavBarSearch search" data-v-ccf7ddec><!----></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-ccf7ddec data-v-7f418b0f><span id="main-nav-aria-label" class="visually-hidden" data-v-7f418b0f>Main Navigation</span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/guide/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>Guide</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/develop/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>Advanced</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/contributing/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>Contributing</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/faq/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>FAQ</span><!--]--></a><!--]--><!--]--></nav><div class="VPFlyout VPNavBarTranslations translations" data-v-ccf7ddec data-v-88af2de4 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="Change language" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><span class="vpi-languages option-icon" data-v-b6c34ac9></span><!----><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-e7ea1737><!----><!--[--><!--[--><div class="items" data-v-88af2de4><p class="title" data-v-88af2de4>English</p><!--[--><div class="VPMenuLink" data-v-88af2de4 data-v-43f1e123><a class="VPLink link" href="/zh/develop/structure.html" data-v-43f1e123><!--[-->简体中文<!--]--></a></div><!--]--></div><!--]--><!--]--></div></div></div><div class="VPNavBarAppearance appearance" data-v-ccf7ddec data-v-e6aabb21><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-e6aabb21 data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-ccf7ddec data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/crazywhalecc/static-php-cli" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-ccf7ddec data-v-d0bd9dde data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-e7ea1737><!----><!--[--><!--[--><div class="group translations" data-v-d0bd9dde><p class="trans-title" data-v-d0bd9dde>English</p><!--[--><div class="VPMenuLink" data-v-d0bd9dde data-v-43f1e123><a class="VPLink link" href="/zh/develop/structure.html" data-v-43f1e123><!--[-->简体中文<!--]--></a></div><!--]--></div><div class="group" data-v-d0bd9dde><div class="item appearance" data-v-d0bd9dde><p class="label" data-v-d0bd9dde>Appearance</p><div class="appearance-action" data-v-d0bd9dde><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-d0bd9dde data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div></div></div><div class="group" data-v-d0bd9dde><div class="item social-links" data-v-d0bd9dde><div class="VPSocialLinks social-links-list" data-v-d0bd9dde data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/crazywhalecc/static-php-cli" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-ccf7ddec data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-ccf7ddec><div class="divider-line" data-v-ccf7ddec></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>Return to top</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-575e6a36><div class="curtain" data-v-575e6a36></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-575e6a36><span class="visually-hidden" id="sidebar-aria-label" data-v-575e6a36> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 has-active" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>Development</h2><!----></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/develop/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Get Started</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/develop/structure.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Project Structure</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/develop/php-src-changes.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>PHP Source Modification</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>Module</h2><!----></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/develop/doctor-module.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Doctor </p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/develop/source-module.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Source</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>Extra</h2><!----></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/develop/system-build-tools.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Compilation Tools</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>On this page</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _en_develop_structure" data-v-39a288b8><div><h1 id="introduction-to-project-structure" tabindex="-1">Introduction to project structure <a class="header-anchor" href="#introduction-to-project-structure" aria-label="Permalink to "Introduction to project structure""></a></h1><p>static-php-cli mainly contains three logical components: sources, dependent libraries, and extensions. These components contains 4 configuration files: <code>source.json</code>, <code>pkg.json</code>, <code>lib.json</code>, and <code>ext.json</code>.</p><p>A complete process for building standalone static PHP is:</p><ol><li>Use the source download module <code>Downloader</code> to download specified or all source codes. These sources include PHP source code, dependent library source code, and extension source code.</li><li>Use the source decompression module <code>SourceExtractor</code> to decompress the downloaded sources to the compilation directory.</li><li>Use the dependency tool to calculate the dependent extensions and dependent libraries of the currently added extension, and then compile each library that needs to be compiled in the order of dependencies.</li><li>After building each dependent library using <code>Builder</code> under the corresponding operating system, install it to the <code>buildroot</code> directory.</li><li>If external extensions are included (the source code does not contain extensions within PHP), copy the external extensions to the <code>source/php-src/ext/</code> directory.</li><li>Use <code>Builder</code> to build the PHP source code and build target to the <code>buildroot</code> directory.</li></ol><p>The project is mainly divided into several folders:</p><ul><li><code>bin/</code>: used to store program entry files, including <code>bin/spc</code>, <code>bin/spc-alpine-docker</code>, <code>bin/setup-runtime</code>.</li><li><code>config/</code>: Contains all the extensions and dependent libraries supported by the project, as well as the download link and download methods of these sources. It is divided into files: <code>lib.json</code>, <code>ext.json</code>, <code>source.json</code>, <code>pkg.json</code>, <code>pre-built.json</code> .</li><li><code>src/</code>: The core code of the project, including the entire framework and commands for compiling various extensions and libraries.</li><li><code>vendor/</code>: The directory that Composer depends on, you do not need to make any modifications to it.</li></ul><p>The operating principle is to start a <code>ConsoleApplication</code> of <code>symfony/console</code>, and then parse the commands entered by the user in the terminal.</p><h2 id="basic-command-line-structure" tabindex="-1">Basic command line structure <a class="header-anchor" href="#basic-command-line-structure" aria-label="Permalink to "Basic command line structure""></a></h2><p><code>bin/spc</code> is an entry file, including the Unix common <code>#!/usr/bin/env php</code>, which is used to allow the system to automatically execute with the PHP interpreter installed on the system. After the project executes <code>new ConsoleApplication()</code>, the framework will automatically register them as commands.</p><p>The project does not directly use the Command registration method and command execution method recommended by Symfony. Here are small changes:</p><ol><li>Each command uses the <code>#[AsCommand()]</code> Attribute to register the name and description.</li><li>Abstract <code>execute()</code> so that all commands are based on <code>BaseCommand</code> (which is based on <code>Symfony\Component\Console\Command\Command</code>), and the execution code of each command itself is written in the <code>handle()</code> method .</li><li>Added variable <code>$no_motd</code> to <code>BaseCommand</code>, which is used to display the Figlet greeting when the command is executed.</li><li><code>BaseCommand</code> saves <code>InputInterface</code> and <code>OutputInterface</code> as member variables. You can use <code>$this->input</code> and <code>$this->output</code> within the command class.</li></ol><h2 id="basic-source-code-structure" tabindex="-1">Basic source code structure <a class="header-anchor" href="#basic-source-code-structure" aria-label="Permalink to "Basic source code structure""></a></h2><p>The source code of the project is located in the <code>src/SPC</code> directory, supports automatic loading of the PSR-4 standard, and contains the following subdirectories and classes:</p><ul><li><code>src/SPC/builder/</code>: The core compilation command code used to build libraries, PHP and related extensions under different operating systems, and also includes some compilation system tool methods.</li><li><code>src/SPC/command/</code>: All commands of the project are here.</li><li><code>src/SPC/doctor/</code>: Doctor module, which is a relatively independent module used to check the system environment. It can be entered using the command <code>bin/spc doctor</code>.</li><li><code>src/SPC/exception/</code>: exception class.</li><li><code>src/SPC/store/</code>: Classes related to storage, files and sources are all here.</li><li><code>src/SPC/util/</code>: Some reusable tool methods are here.</li><li><code>src/SPC/ConsoleApplication.php</code>: command line program entry file.</li></ul><p>If you have read the source code, you may find that there is also a <code>src/globals/</code> directory, which is used to store some global variables, global methods, and non-PSR-4 standard PHP source code that is relied upon during the build process, such as extension sanity check code etc.</p><h2 id="phar-application-directory-issue" tabindex="-1">Phar application directory issue <a class="header-anchor" href="#phar-application-directory-issue" aria-label="Permalink to "Phar application directory issue""></a></h2><p>Like other php-cli projects, spc itself has additional considerations for paths. Because spc can run in multiple modes such as <code>php-cli directly</code>, <code>micro SAPI</code>, <code>php-cli with Phar</code>, <code>vendor with Phar</code>, etc., there are ambiguities in various root directories. A complete explanation is given here. This problem is generally common in the base class path selection problem of accessing files in PHP projects, especially when used with <code>micro.sfx</code>.</p><p>Note that this may only be useful for you when developing Phar projects or PHP frameworks.</p><blockquote><p>Next, we will treat <code>static-php-cli</code> (that is, spc) as a normal <code>php</code> command line program. You can understand spc as any of your own php-cli applications for reference.</p></blockquote><p>There are three basic constant theoretical values below. We recommend that you introduce these three constants when writing PHP projects:</p><ul><li><p><code>WORKING_DIR</code>: the working directory when executing PHP scripts</p></li><li><p><code>SOURCE_ROOT_DIR</code> or <code>ROOT_DIR</code>: the root directory of the project folder, generally the directory where <code>composer.json</code> is located</p></li><li><p><code>FRAMEWORK_ROOT_DIR</code>: the root directory of the framework used, which may be used by self-developed frameworks. Generally, the framework directory is read-only</p></li></ul><p>You can define these constants in your framework entry or cli applications to facilitate the use of paths in your project.</p><p>The following are PHP built-in constant values, which have been defined inside the PHP interpreter:</p><ul><li><p><code>__DIR__</code>: the directory where the file of the currently executed script is located</p></li><li><p><code>__FILE__</code>: the file path of the currently executed script</p></li></ul><h3 id="git-project-mode-source" tabindex="-1">Git project mode (source) <a class="header-anchor" href="#git-project-mode-source" aria-label="Permalink to "Git project mode (source)""></a></h3><p>Git project mode refers to a framework or program itself stored in plain text in the current folder, and running through <code>php path/to/entry.php</code>.</p><p>Assume that your project is stored in the <code>/home/example/static-php-cli/</code> directory, or your project is the framework itself, which contains project files such as <code>composer.json</code>:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>composer.json</span></span>
- <span class="line"><span>src/App/MyCommand.app</span></span>
- <span class="line"><span>vendor/*</span></span>
- <span class="line"><span>bin/entry.php</span></span></code></pre></div><p>We assume that the above constants are obtained from <code>src/App/MyCommand.php</code>:</p><table tabindex="0"><thead><tr><th>Constant</th><th>Value</th></tr></thead><tbody><tr><td><code>WORKING_DIR</code></td><td><code>/home/example/static-php-cli</code></td></tr><tr><td><code>SOURCE_ROOT_DIR</code></td><td><code>/home/example/static-php-cli</code></td></tr><tr><td><code>FRAMEWORK_ROOT_DIR</code></td><td><code>/home/example/static-php-cli</code></td></tr><tr><td><code>__DIR__</code></td><td><code>/home/example/static-php-cli/src/App</code></td></tr><tr><td><code>__FILE__</code></td><td><code>/home/example/static-php-cli/src/App/MyCommand.php</code></td></tr></tbody></table><p>In this case, the values of <code>WORKING_DIR</code>, <code>SOURCE_ROOT_DIR</code>, and <code>FRAMEWORK_ROOT_DIR</code> are exactly the same: <code>/home/example/static-php-cli</code>.</p><p>The source code of the framework and the source code of the application are both in the current path.</p><h3 id="vendor-library-mode-vendor" tabindex="-1">Vendor library mode (vendor) <a class="header-anchor" href="#vendor-library-mode-vendor" aria-label="Permalink to "Vendor library mode (vendor)""></a></h3><p>The vendor library mode generally means that your project is a framework or is installed into the project as a composer dependency by other applications, and the storage location is in the <code>vendor/author/XXX</code> directory.</p><p>Suppose your project is <code>crazywhalecc/static-php-cli</code>, and you or others install this project in another project using <code>composer require</code>.</p><p>We assume that static-php-cli contains all files except the <code>vendor</code> directory with the same <code>Git mode</code>, and get the constant value from <code>src/App/MyCommand</code>, Directory constant should be:</p><table tabindex="0"><thead><tr><th>Constant</th><th>Value</th></tr></thead><tbody><tr><td><code>WORKING_DIR</code></td><td><code>/home/example/another-app</code></td></tr><tr><td><code>SOURCE_ROOT_DIR</code></td><td><code>/home/example/another-app</code></td></tr><tr><td><code>FRAMEWORK_ROOT_DIR</code></td><td><code>/home/example/another-app/vendor/crazywhalecc/static-php-cli</code></td></tr><tr><td><code>__DIR__</code></td><td><code>/home/example/another-app/vendor/crazywhalecc/static-php-cli/src/App</code></td></tr><tr><td><code>__FILE__</code></td><td><code>/home/example/another-app/vendor/crazywhalecc/static-php-cli/src/App/MyCommand.php</code></td></tr></tbody></table><p>Here <code>SOURCE_ROOT_DIR</code> refers to the root directory of the project using <code>static-php-cli</code>.</p><h3 id="git-project-phar-mode-source-phar" tabindex="-1">Git project Phar mode (source-phar) <a class="header-anchor" href="#git-project-phar-mode-source-phar" aria-label="Permalink to "Git project Phar mode (source-phar)""></a></h3><p>Git project Phar mode refers to the mode of packaging the project directory of the Git project mode into a <code>phar</code> file. We assume that <code>/home/example/static-php-cli</code> will be packaged into a Phar file, and the directory has the following files:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>composer.json</span></span>
- <span class="line"><span>src/App/MyCommand.app</span></span>
- <span class="line"><span>vendor/*</span></span>
- <span class="line"><span>bin/entry.php</span></span></code></pre></div><p>When packaged into <code>app.phar</code> and stored in the <code>/home/example/static-php-cli</code> directory, <code>app.phar</code> is executed at this time. Assuming that the <code>src/App/MyCommand</code> code is executed, the constant is obtained in the file:</p><table tabindex="0"><thead><tr><th>Constant</th><th>Value</th></tr></thead><tbody><tr><td><code>WORKING_DIR</code></td><td><code>/home/example/static-php-cli</code></td></tr><tr><td><code>SOURCE_ROOT_DIR</code></td><td><code>phar:///home/example/static-php-cli/app.phar/</code></td></tr><tr><td><code>FRAMEWORK_ROOT_DIR</code></td><td><code>phar:///home/example/static-php-cli/app.phar/</code></td></tr><tr><td><code>__DIR__</code></td><td><code>phar:///home/example/static-php-cli/app.phar/src/App</code></td></tr><tr><td><code>__FILE__</code></td><td><code>phar:///home/example/static-php-cli/app.phar/src/App/MyCommand.php</code></td></tr></tbody></table><p>Because the <code>phar://</code> protocol is required to read files in the phar itself, the project root directory and the framework directory will be different from <code>WORKING_DIR</code>.</p><h3 id="vendor-library-phar-mode-vendor-phar" tabindex="-1">Vendor Library Phar Mode (vendor-phar) <a class="header-anchor" href="#vendor-library-phar-mode-vendor-phar" aria-label="Permalink to "Vendor Library Phar Mode (vendor-phar)""></a></h3><p>Vendor Library Phar Mode means that your project is installed as a framework in other projects and stored in the <code>vendor</code> directory.</p><p>We assume that your project directory structure is as follows:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>composer.json # Composer configuration file of the current project</span></span>
- <span class="line"><span>box.json # Configuration file for packaging Phar</span></span>
- <span class="line"><span>another-app.php # Entry file of another project</span></span>
- <span class="line"><span>vendor/crazywhalecc/static-php-cli/* # Your project is used as a dependent library</span></span></code></pre></div><p>When packaging these files under the directory <code>/home/example/another-app/</code> into <code>app.phar</code>, the value of the following constant for your project should be:</p><table tabindex="0"><thead><tr><th>Constant</th><th>Value</th></tr></thead><tbody><tr><td><code>WORKING_DIR</code></td><td><code>/home/example/another-app</code></td></tr><tr><td><code>SOURCE_ROOT_DIR</code></td><td><code>phar:///home/example/another-app/app.phar/</code></td></tr><tr><td><code>FRAMEWORK_ROOT_DIR</code></td><td><code>phar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli</code></td></tr><tr><td><code>__DIR__</code></td><td><code>phar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli/src/App</code></td></tr><tr><td><code>__FILE__</code></td><td><code>phar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli/src/App/MyCommand.php</code></td></tr></tbody></table></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-d4a0bba5><!--[--><!--]--><!----><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-d4a0bba5><span class="visually-hidden" id="doc-footer-aria-label" data-v-d4a0bba5>Pager</span><div class="pager" data-v-d4a0bba5><a class="VPLink link pager-link prev" href="/en/develop/" data-v-d4a0bba5><!--[--><span class="desc" data-v-d4a0bba5>Previous page</span><span class="title" data-v-d4a0bba5>Get Started</span><!--]--></a></div><div class="pager" data-v-d4a0bba5><a class="VPLink link pager-link next" href="/en/develop/php-src-changes.html" data-v-d4a0bba5><!--[--><span class="desc" data-v-d4a0bba5>Next page</span><span class="title" data-v-d4a0bba5>PHP Source Modification</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2023-present crazywhalecc</p></div></footer><!--[--><!--]--></div></div>
- <script>window.__VP_HASH_MAP__=JSON.parse("{\"en_guide_extensions.md\":\"C5vF7yDY\",\"zh_develop_index.md\":\"-CPpDfMx\",\"en_guide_index.md\":\"CjOUKFgy\",\"en_contributing_index.md\":\"CsY8mx8F\",\"zh_contributing_index.md\":\"BvgdahxO\",\"en_guide_extension-notes.md\":\"BaBSDnpT\",\"en_index.md\":\"Cbpb4iAg\",\"zh_develop_structure.md\":\"B-0RMSSw\",\"en_guide_troubleshooting.md\":\"9z66WsuC\",\"en_develop_system-build-tools.md\":\"D6vaAwN3\",\"extension-notes.md\":\"Bw8xYOie\",\"extensions.md\":\"BOvD4zE9\",\"zh_guide_action-build.md\":\"DWMlBDvT\",\"zh_guide_env-vars.md\":\"CfYA93uA\",\"zh_guide_cli-generator.md\":\"B7mYo4Lw\",\"zh_guide_deps-map.md\":\"b1yfT0cS\",\"en_faq_index.md\":\"DLWPz-7S\",\"zh_develop_system-build-tools.md\":\"Ds53VEw1\",\"deps-map-ext.md\":\"Ct90_tZH\",\"zh_develop_php-src-changes.md\":\"Df0-NcBw\",\"deps-map-lib.md\":\"CHkEUaxl\",\"zh_guide_build-on-windows.md\":\"BxVEYT8r\",\"en_develop_php-src-changes.md\":\"DLlooohw\",\"en_develop_source-module.md\":\"CdOHR0ez\",\"en_guide_cli-generator.md\":\"DsQUY_G0\",\"index.md\":\"mKXtywCA\",\"en_guide_env-vars.md\":\"DXDG6yvH\",\"en_guide_manual-build.md\":\"cuxk79AG\",\"en_guide_build-on-windows.md\":\"0XosmiyO\",\"zh_guide_troubleshooting.md\":\"DsBZI1Y4\",\"en_develop_structure.md\":\"BA5PDIse\",\"zh_guide_manual-build.md\":\"CPnjjhB_\",\"en_develop_index.md\":\"B7_c9YYa\",\"zh_guide_extension-notes.md\":\"Bk8p1Uuk\",\"zh_guide_extensions.md\":\"A3n52TMR\",\"zh_guide_index.md\":\"20ged7P4\",\"zh_index.md\":\"LslJ1UMp\",\"zh_faq_index.md\":\"DL8Ncj95\",\"en_develop_doctor-module.md\":\"DGd8PeM_\",\"en_guide_action-build.md\":\"BKamBazh\",\"zh_develop_doctor-module.md\":\"DgFAPT6E\",\"zh_develop_source-module.md\":\"D0odLsHX\",\"en_guide_deps-map.md\":\"BMawLo1f\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"en-US\",\"dir\":\"ltr\",\"title\":\"static-php-cli\",\"description\":\"Build single static PHP binary, with PHP project together, with popular extensions included.\",\"base\":\"/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"nav\":[],\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/crazywhalecc/static-php-cli\"}]},\"locales\":{\"en\":{\"label\":\"English\",\"lang\":\"en\",\"themeConfig\":{\"nav\":[{\"text\":\"Guide\",\"link\":\"/en/guide/\"},{\"text\":\"Advanced\",\"link\":\"/en/develop/\"},{\"text\":\"Contributing\",\"link\":\"/en/contributing/\"},{\"text\":\"FAQ\",\"link\":\"/en/faq/\"}],\"sidebar\":{\"/en/guide/\":[{\"text\":\"Guide\",\"items\":[{\"text\":\"Guide\",\"link\":\"/en/guide/\"},{\"text\":\"Actions Build\",\"link\":\"/en/guide/action-build\"},{\"text\":\"Manual Build\",\"link\":\"/en/guide/manual-build\"},{\"text\":\"Extension List\",\"link\":\"/en/guide/extensions\"},{\"text\":\"Extension Notes\",\"link\":\"/en/guide/extension-notes\"},{\"text\":\"Command Generator\",\"link\":\"/en/guide/cli-generator\"},{\"text\":\"Environment Variables\",\"link\":\"/en/guide/env-vars\",\"collapsed\":true},{\"text\":\"Dependency Table\",\"link\":\"/en/guide/deps-map\"}]},{\"items\":[{\"text\":\"Troubleshooting\",\"link\":\"/en/guide/troubleshooting\"},{\"text\":\"Build on Windows\",\"link\":\"/en/guide/build-on-windows\"}]}],\"/en/develop/\":[{\"text\":\"Development\",\"items\":[{\"text\":\"Get Started\",\"link\":\"/en/develop/\"},{\"text\":\"Project Structure\",\"link\":\"/en/develop/structure\"},{\"text\":\"PHP Source Modification\",\"link\":\"/en/develop/php-src-changes\"}]},{\"text\":\"Module\",\"items\":[{\"text\":\"Doctor \",\"link\":\"/en/develop/doctor-module\"},{\"text\":\"Source\",\"link\":\"/en/develop/source-module\"}]},{\"text\":\"Extra\",\"items\":[{\"text\":\"Compilation Tools\",\"link\":\"/en/develop/system-build-tools\"}]}],\"/en/contributing/\":[{\"text\":\"Contributing\",\"items\":[{\"text\":\"Contributing\",\"link\":\"/en/contributing/\"}]}]},\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2023-present crazywhalecc\"}}},\"zh\":{\"label\":\"简体中文\",\"lang\":\"zh\",\"themeConfig\":{\"nav\":[{\"text\":\"构建指南\",\"link\":\"/zh/guide/\"},{\"text\":\"进阶\",\"link\":\"/zh/develop/\"},{\"text\":\"贡献\",\"link\":\"/zh/contributing/\"},{\"text\":\"FAQ\",\"link\":\"/zh/faq/\"}],\"sidebar\":{\"/zh/guide/\":[{\"text\":\"构建指南\",\"items\":[{\"text\":\"指南\",\"link\":\"/zh/guide/\"},{\"text\":\"Actions 构建\",\"link\":\"/zh/guide/action-build\"},{\"text\":\"本地构建\",\"link\":\"/zh/guide/manual-build\"},{\"text\":\"扩展列表\",\"link\":\"/zh/guide/extensions\"},{\"text\":\"扩展注意事项\",\"link\":\"/zh/guide/extension-notes\"},{\"text\":\"编译命令生成器\",\"link\":\"/zh/guide/cli-generator\"},{\"text\":\"环境变量列表\",\"link\":\"/zh/guide/env-vars\"},{\"text\":\"依赖关系图表\",\"link\":\"/zh/guide/deps-map\"}]},{\"items\":[{\"text\":\"故障排除\",\"link\":\"/zh/guide/troubleshooting\"},{\"text\":\"在 Windows 上构建\",\"link\":\"/zh/guide/build-on-windows\"}]}],\"/zh/develop/\":[{\"text\":\"开发指南\",\"items\":[{\"text\":\"开发简介\",\"link\":\"/zh/develop/\"},{\"text\":\"项目结构简介\",\"link\":\"/zh/develop/structure\"},{\"text\":\"对 PHP 源码的修改\",\"link\":\"/zh/develop/php-src-changes\"}]},{\"text\":\"模块\",\"items\":[{\"text\":\"Doctor 环境检查工具\",\"link\":\"/zh/develop/doctor-module\"},{\"text\":\"资源模块\",\"link\":\"/zh/develop/source-module\"}]},{\"text\":\"其他\",\"items\":[{\"text\":\"系统编译工具\",\"link\":\"/zh/develop/system-build-tools\"}]}],\"/zh/contributing/\":[{\"text\":\"贡献指南\",\"items\":[{\"text\":\"贡献指南\",\"link\":\"/zh/contributing/\"}]}]},\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2023-present crazywhalecc\"}}}},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
-
- </body>
- </html>
|