<spanclass="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><tabletabindex="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><h3id="vendor-library-mode-vendor"tabindex="-1">Vendor library mode (vendor) <aclass="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><tabletabindex="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><h3id="git-project-phar-mode-source-phar"tabindex="-1">Git project Phar mode (source-phar) <aclass="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><divclass="language-"><buttontitle="Copy Code"class="copy"></button><spanclass="lang"></span><preclass="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><spanclass="line"><span>composer.json</span></span>
<spanclass="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><tabletabindex="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><h3id="vendor-library-phar-mode-vendor-phar"tabindex="-1">Vendor Library Phar Mode (vendor-phar) <aclass="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><divclass="language-"><buttontitle="Copy Code"class="copy"></button><spanclass="lang"></span><preclass="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><spanclass="line"><span>composer.json # Composer configuration file of the current project</span></span>