2017 © Pedro Peláez
 

drupal-module nsautoload

Namespace Autoloader for Drupal 7.x.

image

korstiaan/nsautoload

Namespace Autoloader for Drupal 7.x.

  • Thursday, March 27, 2014
  • by korstiaan
  • Repository
  • 0 Watchers
  • 3 Stars
  • 23 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Nsautoload for Drupal 7.x

Drupal 7.x module which autoloads your modules namespaced classes., (*1)

Build Status, (*2)

Requirements

  • Drupal 7.x
  • PHP 5.3.3+

Installation

Download the module

The recommended way to install Nsautoload is with Composer. Just add the following to your composer.json:, (*3)

   {
       "minimum-stability": "dev",
       "require": {
           "korstiaan/nsautoload": "dev-master"
       }
   }

Now update Composer and install the newly added requirement and its dependencies:, (*4)

``` bash $ php composer.phar update korstiaan/nsautoload, (*5)


If all went well and `composer/installers` did its job, Nsautoload was installed to `modules/nsautoload`. If you don't want it there, or it's not part of your Drupal rootdir, symlink it to your folder of choice. ### Using Composer Using `Composer` means including its autoloader. Add the following to your Drupals settings.php: ```php // /path/to/sites/default/settings.php require '/path/to/vendor/autoload.php';

2. Use composer_loader

Just follow its readme., (*6)

Enable Nsautoload

There are 2 ways to enable Nsautoload:, (*7)

Add the following to your project's settings.php:, (*8)

<?php
// /path/to/sites/default/settings.php

use Nsautoload\Nsautoload;

$loader = new Nsautoload();
$loader->register();

2. Enable it as a Drupal module.

Go to site/all/modules and enable it on http://yourdomain.com/admin/modules/list. (If you're using voiture just add nsautoload to cnf/shared/modules.php), (*9)

Usage

In order for Nsautoload to be able to find your classes some conventions have to be followed:, (*10)

Naming your namespace

Your namespace must be the name of your module with an under_score to CamelCase conversion. For example:, (*11)

  • my_module has namespace MyModule
  • my_foo_module has namespace MyFooModule
  • mymodule has namespace Mymodule

Location of your classes

Two conventions can be used for this, one following the PSR-0 standard, and a more Drupal'ish convention:, (*12)

1. PSR-0

This one completely follows the PSR-0 standard, for example:, (*13)

  • MyModule\Foo is located at /path/to/my_module/MyModule/Foo.php
  • Mymodule\Foo\Bar is located at /path/to/mymodule/Mymodule/Foo/Bar.php
  • Mymodule\Foo\Bar_Crux is located at /path/to/mymodule/Mymodule/Foo/Bar/Crux.php

2. Drupal-style (deprecated)

When this convention is followed, a class is located at module_name/class/_class_.class.inc. Only a 2 level namespace can be used. Examples:, (*14)

  • MyModule\Foo is located at /path/to/my_module/class/foo.class.inc
  • MyModule\Foo_Bar is located at /path/to/my_module/class/foo_bar.class.inc
  • MyModule\Foo\Bar can't be mapped with this convention.

This convention also adds another namespace naming strategy for BC purposes. Next to a under_score to CamelCase conversion, it also allows you to randomly add capitals in your namespace. This allows the following mapping:, (*15)

  • MyOldModule\Foo to /path/to/myoldmodule/class/foo.class.inc

APC caching

In order to cache Nsautoload's autoload map you can wrap it into Symfony's ApcClassLoader., (*16)

First add Symfony's ClassLoader component to your composer.json:, (*17)

   {
       "require": {
           "symfony/class-loader": "dev-master"
       }
   }

Install it:, (*18)

$ php composer.phar update symfony/class-loader

Then change your project's settings.php Nsautoload lines to look like this:, (*19)

<?php
// /path/to/sites/default/settings.php

use Nsautoload\Nsautoload;

$loader    = new Nsautoload();
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader(md5(__DIR__), $loader);
$apcLoader->register(true);

And you're done!, (*20)

License

Nsautoload is licensed under the MIT license., (*21)

The Versions

27/03 2014

dev-master

9999999-dev http://korstiaan.com/nsautoload

Namespace Autoloader for Drupal 7.x.

  Sources   Download

MIT

The Requires

 

The Development Requires

drupal autoloading

29/07 2012

dev-refactoring

dev-refactoring http://korstiaan.com/nsautoload

Namespace Autoloader for Drupal 7.x.

  Sources   Download

MIT

The Requires

 

The Development Requires

drupal autoloading