Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cadorn committed Nov 11, 2011
0 parents commit 3a49041
Show file tree
Hide file tree
Showing 18 changed files with 454 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.pinf_packages/
109 changes: 109 additions & 0 deletions README.md
@@ -0,0 +1,109 @@
PHP Module, Package & Program Loader
====================================

*Status: DEV* - **WORK IN PROGRESS: YOU MAY GET FRUSTRATED TRYING THIS!**

The PINF PHP Loader combines what you would traditionally call a **package installer** and
**class loader** and is **intended to be used as the core to all your PHP applications**.

The loader allows for bootstrapping a state-of-the-art, consistent and portable modular environment
for PHP with the ability to load third party PHP packages from PEAR and other communities following
typical PHP class naming conventions.

The loader brings [CommonJS Packages/1.1 (draft)](http://wiki.commonjs.org/wiki/Packages/1.1),
[CommonJS Packages/Mappings/C (proposal)](http://wiki.commonjs.org/wiki/Packages/Mappings/C) and further concepts to the PHP platform.

For more information about the direction this loader is taking see the [JavaScript implementation](https://github.com/pinf/loader-js).


Install
=======

TODO


Development
===========

[PHPUnit](http://www.phpunit.de/manual/current/en/installation.html) Tests:

cd ./tests

phpunit PINF
phpunit demos


TODO
====

**Questions**

* How do you tell PHPUnit to disable output buffering when running tests?



Support, Feedback & News
========================

* Mailing list: [http://groups.google.com/group/pinf-dev/](http://groups.google.com/group/pinf-dev/)
* Twitter: [http://twitter.com/pinf](http://twitter.com/pinf)
* Blog: [http://christophdorn.com/Blog/](http://christophdorn.com/Blog/)


Contribute
==========

Collaboration Platform: [https://github.com/pinf/loader-php/](https://github.com/pinf/loader-php/)

Collaboration Process:

1. Discuss your change on the mailing list
2. Write a patch on your own
3. Send pull request on github & ping mailing list
4. Discuss pull request on github to refine

You must explicitly license your patch by adding the following to the top of any file you modify
in order for your patch to be accepted:

// - <GithubUsername>, First Last <Email>, Copyright YYYY, MIT License


Author
======

This project is a part of the [PINF](http://www.christophdorn.com/Research/#PINF) project maintained by
[Christoph Dorn](http://www.christophdorn.com/).


Documentation License
=====================

[Creative Commons Attribution-NonCommercial-ShareAlike 3.0](http://creativecommons.org/licenses/by-nc-sa/3.0/)

Copyright (c) 2011+ [Christoph Dorn](http://www.christophdorn.com/)


Code License
============

[MIT License](http://www.opensource.org/licenses/mit-license.php)

Copyright (c) 2011+ [Christoph Dorn](http://www.christophdorn.com/)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
13 changes: 13 additions & 0 deletions demos/StaticMappings/main.php
@@ -0,0 +1,13 @@
<?php

use lang-1/Greetings as Greets1;
use lang-2/Greetings as Greets2;


$greeting1 = Greets1::sayHello();

echo $greeting1 . "\n";

$greeting2 = Greets2::sayHello();

echo $greeting2 . "\n";
6 changes: 6 additions & 0 deletions demos/StaticMappings/package.json
@@ -0,0 +1,6 @@
{
"mappings": {
"lang-1": "github.com/pinf/loader-php/demos/StaticMappings/packages/lang-en/",
"lang-2": "github.com/pinf/loader-php/demos/StaticMappings/packages/lang-de/"
}
}
9 changes: 9 additions & 0 deletions demos/StaticMappings/packages/lang-de/lib/Greetings.php
@@ -0,0 +1,9 @@
<?php

class Greetings
{
public static function sayHello()
{
return 'Hallo Welt';
}
}
2 changes: 2 additions & 0 deletions demos/StaticMappings/packages/lang-de/package.json
@@ -0,0 +1,2 @@
{
}
12 changes: 12 additions & 0 deletions demos/StaticMappings/packages/lang-en/lib/Greetings.php
@@ -0,0 +1,12 @@
<?php

//use ./Words as Words;

class Greetings
{
public static function sayHello()
{
// return Words::get('Hello') . ' ' . Words::get('World');
return 'Hello World';
}
}
9 changes: 9 additions & 0 deletions demos/StaticMappings/packages/lang-en/lib/Words.php
@@ -0,0 +1,9 @@
<?php

class Words
{
public static function get($name)
{
return $name;
}
}
7 changes: 7 additions & 0 deletions demos/StaticMappings/packages/lang-en/package.json
@@ -0,0 +1,7 @@
{
"directories": {
"lib": {
"path": "lib"
}
}
}
20 changes: 20 additions & 0 deletions demos/StaticMappings/program.json
@@ -0,0 +1,20 @@
{
"boot": "github.com/pinf/loader-php/demos/StaticMappings/",
"packages": {
"github.com/pinf/loader-php/demos/StaticMappings/": {
"locator": {
"location": "./"
}
},
"github.com/pinf/loader-php/demos/StaticMappings/packages/lang-en/": {
"locator": {
"location": "./packages/lang-en"
}
},
"github.com/pinf/loader-php/demos/StaticMappings/packages/lang-de/": {
"locator": {
"location": "./packages/lang-de"
}
}
}
}
42 changes: 42 additions & 0 deletions lib/PINF/Loader/Autoloader.php
@@ -0,0 +1,42 @@
<?php

class PINF_Loader_Autoloader
{
private static $instance = null;

private $mappings = array();

public static function init()
{
if (self::$instance === null)
{
self::$instance = new PINF_Loader_Autoloader();
spl_autoload_register('PINF_Loader_Autoloader::_loadClass');
}
return self::$instance;
}

public static function _loadClass($name)
{
self::$instance->loadClass($name);
}

public function loadClass($name)
{
$name = str_replace('\\', '/', $name);

$key = substr($name, 0, strpos($name, '/'));

if (!isset($this->mappings[$key]))
return;

$path = $this->mappings[$key] . substr($name, strlen($key)) . '.php';

require_once($path);
}

public function addMapping($key, $path)
{
$this->mappings[$key] = $path;
}
}
8 changes: 8 additions & 0 deletions lib/PINF/Loader/Descriptor.php
@@ -0,0 +1,8 @@
<?php

class PINF_Loader_Descriptor
{
public function __construct()
{
}
}
Empty file added lib/PINF/Loader/Init.php
Empty file.

0 comments on commit 3a49041

Please sign in to comment.