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

34 lines
36 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.12">
<link rel="preload stylesheet" href="/assets/style.DCggPa4H.css" as="style">
<link rel="preload stylesheet" href="/vp-icons.css" as="style">
<script type="module" src="/assets/app.C9FYtCRt.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.MOrVMOSc.js">
<link rel="modulepreload" href="/assets/chunks/framework.Bhsyh9kO.js">
<link rel="modulepreload" href="/assets/en_develop_structure.md.X2JId3N9.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-1df9f90f><!--[--><!--]--><!--[--><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-1df9f90f data-v-9f75dce3><div class="VPNavBar" data-v-9f75dce3 data-v-2a96a3d0><div class="wrapper" data-v-2a96a3d0><div class="container" data-v-2a96a3d0><div class="title" data-v-2a96a3d0><div class="VPNavBarTitle has-sidebar" data-v-2a96a3d0 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-2a96a3d0><div class="content-body" data-v-2a96a3d0><!--[--><!--]--><div class="VPNavBarSearch search" data-v-2a96a3d0><!--[--><!----><div id="docsearch"><button type="button" aria-label="Search" aria-keyshortcuts="/ control+k meta+k" class="DocSearch DocSearch-Button"><span class="DocSearch-Button-Container"><span class="vpi-search DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key"></kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-2a96a3d0 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-2a96a3d0 data-v-88af2de4 data-v-42cb505d><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="Change language" data-v-42cb505d><span class="text" data-v-42cb505d><span class="vpi-languages option-icon" data-v-42cb505d></span><!----><span class="vpi-chevron-down text-icon" data-v-42cb505d></span></span></button><div class="menu" data-v-42cb505d><div class="VPMenu" data-v-42cb505d data-v-25a6cce8><!----><!--[--><!--[--><div class="items" data-v-88af2de4><p class="title" data-v-88af2de4>English</p><!--[--><div class="VPMenuLink" data-v-88af2de4 data-v-cd834e02><a class="VPLink link" href="/zh/develop/structure.html" data-v-cd834e02><!--[--><span data-v-cd834e02>简体中文</span><!--]--></a></div><!--]--></div><!--]--><!--]--></div></div></div><div class="VPNavBarAppearance appearance" data-v-2a96a3d0 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-2a96a3d0 data-v-0394ad82 data-v-d07f11e6><!--[--><a class="VPSocialLink no-icon" href="https://github.com/crazywhalecc/static-php-cli" aria-label="github" target="_blank" rel="me noopener" data-v-d07f11e6 data-v-591a6b30><span class="vpi-social-github"></span></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-2a96a3d0 data-v-bb2aa2f0 data-v-42cb505d><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-42cb505d><span class="vpi-more-horizontal icon" data-v-42cb
<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-1df9f90f 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\":\"DqNYV3B0\",\"deps-map-ext.md\":\"BVAR3McO\",\"deps-map-lib.md\":\"BnsDnV_s\",\"en_contributing_index.md\":\"fCA6lXnW\",\"en_develop_craft-yml.md\":\"Ci97ssL7\",\"en_develop_doctor-module.md\":\"BTDyp-aK\",\"en_develop_index.md\":\"DUNrUVP9\",\"en_develop_php-src-changes.md\":\"dN8aSiwg\",\"en_develop_source-module.md\":\"hhJuiZD0\",\"en_develop_structure.md\":\"X2JId3N9\",\"en_develop_system-build-tools.md\":\"BmQhyTle\",\"en_faq_index.md\":\"B89Sredc\",\"en_guide_action-build.md\":\"Dnzq6gNC\",\"en_guide_build-on-windows.md\":\"DiYVSaPG\",\"en_guide_build-with-glibc.md\":\"CkVR75n5\",\"en_guide_cli-generator.md\":\"q_BZ_Z7C\",\"en_guide_deps-map.md\":\"BUF4uebw\",\"en_guide_env-vars.md\":\"51DQ7bvx\",\"en_guide_extension-notes.md\":\"CHFGRiKx\",\"en_guide_extensions.md\":\"UqRV3ESR\",\"en_guide_index.md\":\"BC5dTAQW\",\"en_guide_manual-build.md\":\"D7BTH2HF\",\"en_guide_troubleshooting.md\":\"D19jRB1K\",\"en_index.md\":\"WiGlW8EH\",\"extension-notes.md\":\"BB7Xlw1w\",\"extensions.md\":\"hO1GVZPt\",\"index.md\":\"AJG02Jxt\",\"zh_contributing_index.md\":\"fiiKMXnj\",\"zh_develop_craft-yml.md\":\"CAUu6v38\",\"zh_develop_doctor-module.md\":\"1NRXIINs\",\"zh_develop_index.md\":\"CRxnJZDt\",\"zh_develop_php-src-changes.md\":\"CwVUc0oE\",\"zh_develop_source-module.md\":\"3iGbQTPs\",\"zh_develop_structure.md\":\"CEd1RycZ\",\"zh_develop_system-build-tools.md\":\"CQ4BvPVa\",\"zh_faq_index.md\":\"BihV7puH\",\"zh_guide_action-build.md\":\"CQ3Vf3i9\",\"zh_guide_build-on-windows.md\":\"oogWrPn_\",\"zh_guide_build-with-glibc.md\":\"CHXyK61r\",\"zh_guide_cli-generator.md\":\"iYR_rOpk\",\"zh_guide_deps-map.md\":\"Cu7XhPTT\",\"zh_guide_env-vars.md\":\"CtNlqGk4\",\"zh_guide_extension-notes.md\":\"BCwDjBZH\",\"zh_guide_extensions.md\":\"DEhoyCES\",\"zh_guide_index.md\":\"C3GV6eqU\",\"zh_guide_manual-build.md\":\"DVCjR4yy\",\"zh_guide_troubleshooting.md\":\"BRQLW2WP\",\"zh_index.md\":\"Dv99zA_s\"}");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\"},\"search\":{\"provider\":\"algolia\",\"options\":{\"appId\":\"IHJHUB1SF1\",\"apiKey\":\"8266d31cc2ffbd0e059f1c6e5bdaf8fc\",\"indexName\":\"static-php docs\"}}},\"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
</body>
</html>