static-php-cli/en/develop/structure.html

34 lines
35 KiB
HTML
Raw Normal View History

<!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 v2.0.0-alpha.5">
<link rel="preload stylesheet" href="/assets/style.dWIvQ_yG.css" as="style">
<link rel="preload stylesheet" href="/vp-icons.css" as="style">
<script type="module" src="/assets/app.DQMp3l4I.js"></script>
<link rel="preload" href="/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/assets/chunks/theme.DbVD3jYa.js">
<link rel="modulepreload" href="/assets/chunks/framework.PeLcR_tw.js">
<link rel="modulepreload" href="/assets/en_develop_structure.md.D1kBTweh.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-5e06b97a><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0b0ada53></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0b0ada53>Skip to content</a><!--]--><!----><header class="VPNav" data-v-5e06b97a data-v-ae24b3ad><div class="VPNavBar" data-v-ae24b3ad data-v-0ae64501><div class="wrapper" data-v-0ae64501><div class="container" data-v-0ae64501><div class="title" data-v-0ae64501><div class="VPNavBarTitle has-sidebar" data-v-0ae64501 data-v-1e38c6bc><a class="title" href="/en/" data-v-1e38c6bc><!--[--><!--]--><!----><span data-v-1e38c6bc>static-php-cli</span><!--[--><!--]--></a></div></div><div class="content" data-v-0ae64501><div class="content-body" data-v-0ae64501><!--[--><!--]--><div class="VPNavBarSearch search" data-v-0ae64501><!----></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-0ae64501 data-v-39714824><span id="main-nav-aria-label" class="visually-hidden" data-v-39714824> Main Navigation </span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/guide/" tabindex="0" data-v-39714824 data-v-e56f3d57><!--[--><span data-v-e56f3d57>Guide</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/develop/" tabindex="0" data-v-39714824 data-v-e56f3d57><!--[--><span data-v-e56f3d57>Advanced</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/contributing/" tabindex="0" data-v-39714824 data-v-e56f3d57><!--[--><span data-v-e56f3d57>Contributing</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/faq/" tabindex="0" data-v-39714824 data-v-e56f3d57><!--[--><span data-v-e56f3d57>FAQ</span><!--]--></a><!--]--><!--]--></nav><div class="VPFlyout VPNavBarTranslations translations" data-v-0ae64501 data-v-88af2de4 data-v-3ab3deac><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="Change language" data-v-3ab3deac><span class="text" data-v-3ab3deac><span class="vpi-languages option-icon" data-v-3ab3deac></span><!----><span class="vpi-chevron-down text-icon" data-v-3ab3deac></span></span></button><div class="menu" data-v-3ab3deac><div class="VPMenu" data-v-3ab3deac data-v-c9afd7f1><!----><!--[--><!--[--><div class="items" data-v-88af2de4><p class="title" data-v-88af2de4>English</p><!--[--><div class="VPMenuLink" data-v-88af2de4 data-v-35975db6><a class="VPLink link" href="/zh/develop/structure.html" data-v-35975db6><!--[--><span data-v-35975db6>简体中文</span><!--]--></a></div><!--]--></div><!--]--><!--]--></div></div></div><div class="VPNavBarAppearance appearance" data-v-0ae64501 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-0ae64501 data-v-0394ad82 data-v-d474d15f><!--[--><a class="VPSocialLink no-icon" href="https://github.com/crazywhalecc/static-php-cli" aria-label="github" target="_blank" rel="noopener" data-v-d474d15f data-v-bd121fe5><span class="vpi-social-github"></span></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-0ae64501 data-v-bb2aa2f0 data-v-3ab3deac><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-3ab3deac><span class="vpi-more-horizontal icon" data-v-3ab3deac></span></button><div class="menu" data-v-3ab3deac><div class="VPMenu" data-v-3ab3deac data-v-c9afd7f1><!----><!--[--><!--[--><div class="group translations" data-v-bb2aa2f0><p class="trans-title" data-v-bb2aa2f0>English</p><!--[--><div class="VPMenuLink" data-v-bb2aa2f0 data-v-35975db6><a class="VPLink link" href="/zh/develop/structure.html" data-v-35975db6><!--[--><span data-v-35975db6>简体中文</span><!--]--></a></div><!--]--></div><div
<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-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><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-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><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-7011f0d8 data-v-e257564d><!--[--><!--]--><!----><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/en/develop/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>Previous page</span><span class="title" data-v-e257564d>Get Started</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/en/develop/php-src-changes.html" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>Next page</span><span class="title" data-v-e257564d>PHP Source Modification</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5e06b97a data-v-c3855bb3><div class="container" data-v-c3855bb3><p class="message" data-v-c3855bb3>Released under the MIT License.</p><p class="copyright" data-v-c3855bb3>Copyright © 2023-present crazywhalecc</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"deps-craft-yml.md\":\"DWPKeuXi\",\"deps-map-ext.md\":\"C_51TV4x\",\"deps-map-lib.md\":\"BvyAILTb\",\"en_contributing_index.md\":\"C8tXDL1f\",\"en_develop_craft-yml.md\":\"BDq8uWIr\",\"en_develop_doctor-module.md\":\"DYVfKght\",\"en_develop_index.md\":\"DSlquryN\",\"en_develop_php-src-changes.md\":\"DadHFaGC\",\"en_develop_source-module.md\":\"CeJEgS_j\",\"en_develop_structure.md\":\"D1kBTweh\",\"en_develop_system-build-tools.md\":\"DK4AaCy_\",\"en_faq_index.md\":\"DnHLgGcl\",\"en_guide_action-build.md\":\"BCJvLz8l\",\"en_guide_build-on-windows.md\":\"CG23CkLK\",\"en_guide_build-with-glibc.md\":\"BDBCsGWa\",\"en_guide_cli-generator.md\":\"CfXidhft\",\"en_guide_deps-map.md\":\"Bb6l58tU\",\"en_guide_env-vars.md\":\"DzVATbtO\",\"en_guide_extension-notes.md\":\"4_zoofny\",\"en_guide_extensions.md\":\"CqgQnQ-P\",\"en_guide_index.md\":\"BE1G5v55\",\"en_guide_manual-build.md\":\"9IRiOUoX\",\"en_guide_troubleshooting.md\":\"BvJgQKvb\",\"en_index.md\":\"kO-e39M0\",\"extension-notes.md\":\"DkpYDq7p\",\"extensions.md\":\"I66dgmMR\",\"index.md\":\"wJBxKTzp\",\"zh_contributing_index.md\":\"7JN5xgrv\",\"zh_develop_craft-yml.md\":\"Dfv1fXuq\",\"zh_develop_doctor-module.md\":\"B8r2lbU8\",\"zh_develop_index.md\":\"BFWliVJD\",\"zh_develop_php-src-changes.md\":\"CkjaMIky\",\"zh_develop_source-module.md\":\"DoBnezP5\",\"zh_develop_structure.md\":\"DStJTsYD\",\"zh_develop_system-build-tools.md\":\"CxPkPV_h\",\"zh_faq_index.md\":\"D63hFHSU\",\"zh_guide_action-build.md\":\"BWFrjWwZ\",\"zh_guide_build-on-windows.md\":\"6JBREABQ\",\"zh_guide_build-with-glibc.md\":\"CGbU937o\",\"zh_guide_cli-generator.md\":\"DirpekSi\",\"zh_guide_deps-map.md\":\"CO6ZMGBg\",\"zh_guide_env-vars.md\":\"DqYHbUfS\",\"zh_guide_extension-notes.md\":\"9Fmfx-hb\",\"zh_guide_extensions.md\":\"nKe_OKJ8\",\"zh_guide_index.md\":\"DIAjAKH4\",\"zh_guide_manual-build.md\":\"CrFA3mm-\",\"zh_guide_troubleshooting.md\":\"B9WGHMIU\",\"zh_index.md\":\"DcikGFee\"}");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\"}],\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2023-present crazywhalecc\"}},\"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\":\"Basic Build Guides\",\"items\":[{\"text\":\"Guide\",\"link\":\"/en/guide/\"},{\"text\":\"Build (Local)\",\"link\":\"/en/guide/manual-build\"},{\"text\":\"Build (CI)\",\"link\":\"/en/guide/action-build\"},{\"text\":\"Supported Extensions\",\"link\":\"/en/guide/extensions\"},{\"text\":\"Extension Notes\",\"link\":\"/en/guide/extension-notes\"},{\"text\":\"Build 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\"}]},{\"text\":\"Extended Build Guides\",\"items\":[{\"text\":\"Troubleshooting\",\"link\":\"/en/guide/troubleshooting\"},{\"text\":\"Build on Windows\",\"link\":\"/en/guide/build-on-windows\"},{\"text\":\"Build with GNU libc\",\"link\":\"/en/guide/build-with-glibc\"}]}],\"/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-
</body>
</html>