PHPackages                             karlnack/packmule - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. karlnack/packmule

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

karlnack/packmule
=================

Module- and package-based autoloading for PHP

v1.0.2(6y ago)05ISCPHPPHP &gt;= 5.3

Since May 18Pushed 6y ago1 watchersCompare

[ Source](https://github.com/gnarlyquack/packmule)[ Packagist](https://packagist.org/packages/karlnack/packmule)[ Docs](https://github.com/gnarlyquack/packmule)[ RSS](/packages/karlnack-packmule/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

```
Pack Mule
=========

Pack Mule is a PHP autoloader that takes advantage of PHP namespaces to
implement the concept of modules and packages. This means multiple classes
(along with functions and constants, although these cannot be autoloaded) can
be defined in a file and successfully autoloaded.

Pack Mule happily coexists with other autoloaders, so use it fearlessly.

Overview
========

A module is simply a file of PHP source code. A package is then simply a
directory containing one or more modules or packages. A namespace can then be
used to identify a module (or package) as follows:

1. A namespace corresponds to a file path relative to some starting point,
   called the "base directory", with namespace separators representing
   directory separators. Note that a class name, function name, constant
   name, etc., are NEVER part of a namespace.

2. The "project namespace" is an initial hierarchy of one or more names in
   the namespace and constitutes a project's top-level namespace. The project
   namespace represents the module or package that is your project and
   corresponds to a exactly one file (in the case of a module) or one
   directory (in the case of a package) in the base directory.

3. If a project namespace is longer than one name, everything except the
   rightmost name constitutes the "vendor prefix". The vendor prefix is
   excluded when mapping a namespace to a file path in the base directory.

4. File path names that correspond to a namespace name MUST be lowercase, and
   the file name identified by the namespace must end in ".php". This is
   because identifiers are case insensitive in PHP and clients may specify a
   namespace in whatever case they like. Consequently, Pack Mule standardizes
   all names to lowercase.

The following examples show how Pack Mule resolves fully-qualified class
names to a file name (which presumably contains the class definition).

         Class Name: \foo\Bar
  Project Namespace: foo
      Vendor Prefix:
     Base Directory: /path/to/foo/src
Resulting File Path: /path/to/foo/src/foo.php

         Class Name: \Fee\Fie\Foe
  Project Namespace: Fee\Fie
      Vendor Prefix: Fee
     Base Directory: /path/to/fie
Resulting File Path: /path/to/fie/fie.php

         Class Name: \Acme\Logger\File\Writer
  Project Namespace: Acme\Logger
      Vendor Prefix: Acme
     Base Directory: ./acme/logger/lib
Resulting File Path: ./acme/logger/lib/logger/file.php

         Class Name: \com\example\web\response\Status
  Project Namespace: com\example\web
      Vendor Prefix: com\example
     Base Directory: /usr/includes/example.com
Resulting File Path: /usr/includes/example.com/web/response.php

         Class Name: \framework\database\mysql\Database
  Project Namespace: framework
      Vendor Prefix:
     Base Directory: ./framework/
Resulting File Path: ./framework/framework/database/mysql.php

NOTE: Nothing currently prevents both a module and a package of the same name
from existing side by side in the same directory, although doing this is
perhaps inadvisable, and future support of this is not guaranteed.

Requirements
============

Pack Mule supports PHP 5.3 through 7.4.

Installation
============

Use Composer to install Pack Mule by adding the following configuration to
your project's "composer.json":

    "require": {
        "karlnack/packmule": "1.0.*"
    }

Usage
=====

With a bootstrap file
---------------------

Use this method if your project is NOT to be used as a library in others'
projects and you are using Composer to manage your project's dependencies.
In this case, you must register your project namespace and its base directory
with Pack Mule in your project's bootstrap process.

bootstrap.php:
