PHPKG: The Package Manager Supporting OOP and Functional Development
Tags: php, programming, opensource, tooling
Published: 2023-02-18 09:33:19

**PHPKG** is a new package manager designed for PHP developers who want to combine both object-oriented programming (OOP) and functional programming styles in their projects. It provides a flexible and customizable build process that allows developers to define how their namespaces are mapped to their code directories, making it easy to add new classes and functions to their projects.

One of the key advantages of PHPKG is its support for both OOP and functional development styles. While OOP provides a powerful and flexible way to organize and structure code, functional programming is often a more efficient way to perform certain tasks. PHPKG's build process supports both styles, allowing developers to use either or both as they see fit.

The build process is another area where PHPKG stands out from other package managers. When a project is built with PHPKG, it reads the source code and uses the defined map to transpile an executable code that contains the required "require" statements for namespaced functions and required registration for defining classes. The transpiling process is fully customizable, and developers can define how they want their namespaces to be mapped to their code directories in the phpkg.config.json file.

For example, if a developer has a map defined as "Application": "src", this means that for any namespace starting with "Application", PHPKG will search in the "src" directory. If a file with a namespace of "Application\Controllers\HomeController" is located in "src/Controllers/HomeController.php", PHPKG will add a path to the entry points of the project, which also must be defined by the developer in the config file. PHPKG will then use PHP's _spl_autoload_register_ function to register the class at the defined path, making it available for use in the project.

For namespaced functions, developers can add a _require_once_ statement to the client files that use them. PHPKG will automatically add the statement when building the project if the function is used in any code. The build process is highly flexible, and developers can define multiple mappings in their _phpkg.config.json_ file to structure their project as they see fit.

PHPKG's build process is not just flexible, it also has several advantages. One of the most significant benefits is that it makes it easy to add new classes and functions to a project without worrying about dependencies. PHPKG's transpiling process reads the source code and adds the necessary _require_once_ statements automatically. This makes it easier to write maintainable and scalable code, as it reduces the risk of dependency errors.

Another advantage of PHPKG's build process is that it's fast and efficient. By using _spl_autoload_register_ to register classes and _require_once_ statements for functions, PHPKG reduces the need for expensive file I/O operations. This makes PHPKG ideal for large-scale projects that require fast build times and efficient code execution.

PHPKG also provides a variety of other features, such as the **run** command, which allows developers to quickly download a repository into their OS's temp directory, install the required dependencies, and build and execute the first entry point defined in the project's config file. The run command makes it easy to test and debug projects, without having to worry about setting up a local environment.

In summary, PHPKG is an innovative package manager that provides support for both OOP and functional development styles. Its customizable and flexible build process makes it easy to structure large-scale projects and add new classes and functions without worrying about dependencies. With its fast and efficient build process, PHPKG is a great choice for PHP developers who want to build maintainable, scalable, and efficient code.
For more information please read [its documentations](https://phpkg.com/documentations/getting-started).