Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Autoloader sanity
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-scott committed Apr 16, 2015
1 parent fb825df commit bd1ef40
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 43 deletions.
15 changes: 6 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "paragonie/pharaoh",
"description": "Compare PHARs from the Command Line",
"version": "0.1.0",
"version": "0.1.2",
"keywords": [
"tool",
"utility",
Expand All @@ -20,15 +20,12 @@
],
"support": {
"issues": "https://github.com/paragonie/pharaoh/issues",
"email": "info@resonantcore.net",
"email": "info@paragonie.com",
"source": "https://github.com/paragonie/pharaoh"
},
"autoload": {
"psr-4": {
"ParagonIE\\Pharoah\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "4.5.*"
"files": [
"src/autoload.php"
]
}
}
}
35 changes: 1 addition & 34 deletions pharaoh
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
#!/usr/bin/env php
<?php

\spl_autoload_register(function ($class) {
// Project-specific namespace prefix
$prefix = 'ParagonIE\\Pharaoh';

// Base directory for the namespace prefix
$base_dir = __DIR__.'/src/';

// Does the class use the namespace prefix?
$len = \strlen($prefix);
if (\strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}

// Get the relative class name
$relative_class = \substr($class, $len);

// Replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir.
\str_replace(
['\\', '_'],
'/',
$relative_class
).'.php';

// If the file exists, require it
if (\file_exists($file)) {
require $file;
}
});

require_once __DIR__.'/autoload.php';
if ($argc < 3) {
die("Please pass two phars to diff them.\n");
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions src/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
\spl_autoload_register(function ($class) {
// Project-specific namespace prefix
$prefix = 'ParagonIE\\Pharaoh';

// Base directory for the namespace prefix
$base_dir = __DIR__.'/Pharaoh/';

// Does the class use the namespace prefix?
$len = \strlen($prefix);
if (\strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}

// Get the relative class name
$relative_class = \substr($class, $len);

// Replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir.
\str_replace(
['\\', '_'],
'/',
$relative_class
).'.php';

// If the file exists, require it
if (\file_exists($file)) {
require $file;
}
});

0 comments on commit bd1ef40

Please sign in to comment.