The phpkg init command creates a phpkg.config.json file—your key to tailoring phpkg for your project. From mapping namespaces to autoloading functions or setting entry points, this file lets you control how phpkg builds and runs your code. Here’s how to make it yours.
Run phpkg init, and you’ll get a phpkg.config.json like this:
{
"map": [],
"autoloads": [],
"excludes": [],
"entry-points": [],
"executables": [],
"import-file": "phpkg.imports.php",
"packages-directory": "Packages",
"packages": []
}
Let’s break down each part.
Map namespaces to directories—like App to src/—so phpkg knows where your code lives. Example:
{
"map": {
"App": "src",
"Tests": "tests"
}
}
phpkg resolves them for you. // src/User.php
namespace App;
class User {
// Your code
}
// src/Utils.php
namespace App\Utils;
function log($msg) { echo $msg; }
Why it rocks: phpkg autoloads both, letting you mix OOP and functional code effortlessly.
List files to load before anything else—perfect for helpers or constants. Example:
{
"autoloads": ["src/helpers.php"]
}
// src/helpers.php
function debug($var) { var_dump($var); }
Skip files or dirs during builds—like node_modules or dev scripts. Example:
{
"excludes": ["node_modules", "build.sh"]
}
Define where your app starts—phpkg adds autoloading magic here. Example:
{
"entry-points": ["public/index.php", "cli/run.php"]
}
phpkg injects imports so App\Utils\log() just works.Turn package scripts into root-level commands via symlinks. Example:
{
"executables": {
"rocket": "Packages/rocket/launch.php"
}
}
php rocket to execute launch.php. "status": "Packages/rocket/status.php". Set where phpkg writes import statements (default: phpkg.imports.php). Change it with:
{
"import-file": "vendor/autoload.php"
}
Choose where packages live (default: Packages). Customize it:
{
"packages-directory": "vendor"
}
phpkg add uses this dir; builds pull from here too. .gitignore to keep Git clean.Note: If it doesn’t exist,
phpkgcreates it.
Tracks installed packages—phpkg fills this automatically with add, update, or remove. Example:
{
"packages": {
"https://github.com/php-repos/test-runner.git": "1.0.0",
"https://github.com/php-repos/datatype.git": "2.5.0"
}
}
Lists Git URLs and versions—no manual edits needed.
Edit phpkg.config.json after phpkg init, then use phpkg build to see it in action. Need more? Check Init Command or dive into other commands like phpkg add.
We believe that PHP has enormous untapped potential, and we are dedicated to creating tools that empower developers to harness its full power and capabilities. We aim to unlock this potential by creating tools that help developers harness PHP's full capabilities and extend its power to new heights. To this end, we developed phpkg, a cutting-edge package manager that simplifies the process of using PHP to its fullest extent. With phpkg, developers can take advantage of all that PHP has to offer and build more efficient, scalable, and powerful applications.