diff --git a/doc/PHAR-PLUGINS.md b/doc/PHAR-PLUGINS.md new file mode 100644 index 0000000..f3d1245 --- /dev/null +++ b/doc/PHAR-PLUGINS.md @@ -0,0 +1,98 @@ +Plugins in Phar Archives +======================== + +This is a short guide on how to create single-file portable plugins using +MakePhar. + + +## The workflow + +1. Your application should export functions that can be called by the plugin + on load, such as `myapp_plugin_register` in the example below. +2. Locate the .phar plugins to load, and `@include` them one at a time. +3. Process the plugins etc that has been registered from the successfully + loaded .phar libraries. + + +## Example files + +### src/plugin.php + + ~/myapp/myapp.phar + while (readlink($root)) { + $root = readlink($root); + } + // Finally get the directory (~/myapp) + $root = dirname($root); + +Use this to locate your plugins. + +### Find out if running from within a Phar + +You can easilly find out if running from within a .phar archive by calling +`Phar::running()`. + + if (Phar::running()) { inside_phar(); } + +This doesn't make sense to use in phar plugins, as the main application can +also be in a phar, in which case it will be true even for non-phar plugins. + diff --git a/makephar.sdl.dist b/makephar.sdl.dist new file mode 100644 index 0000000..97b16fe --- /dev/null +++ b/makephar.sdl.dist @@ -0,0 +1,25 @@ +// Define output file here +phar "output.phar" { + + // Remove this line to build an executable + library; + + // Remove this line to minify source files (recommended9) + verbatim; + + // Define the stub called when the phar is executed + stub "src/bootstrap.php"; + + // Select files/dirs to include + include { + dir "vendor"; + dir "src"; + } + + // Patterns to exclude + exclude { + dir "Tests"; + dir ".git"; + } + +}