Skip to content

Commit

Permalink
Update to proposed PSR-1 coding standard.
Browse files Browse the repository at this point in the history
 * 4 space (no tab) indent
 * K&R-style braces
  • Loading branch information
bobthecow committed May 2, 2012
1 parent be5cfb3 commit 2448992
Show file tree
Hide file tree
Showing 57 changed files with 3,508 additions and 3,234 deletions.
66 changes: 33 additions & 33 deletions bin/create_example.php
Expand Up @@ -38,10 +38,10 @@
* @return string
*/
function getLowerCaseName($name) {
return preg_replace_callback("/([A-Z])/", create_function (
'$match',
'return "_" . strtolower($match[1]);'
), lcfirst($name));
return preg_replace_callback("/([A-Z])/", create_function (
'$match',
'return "_" . strtolower($match[1]);'
), lcfirst($name));
}

/**
Expand All @@ -57,10 +57,10 @@ function getLowerCaseName($name) {
* @return string
*/
function getUpperCaseName($name) {
return preg_replace_callback("/_([a-z])/", create_function (
'$match',
'return strtoupper($match{1});'
), ucfirst($name));
return preg_replace_callback("/_([a-z])/", create_function (
'$match',
'return strtoupper($match{1});'
), ucfirst($name));
}


Expand All @@ -72,8 +72,8 @@ function getUpperCaseName($name) {
* @return mixed
*/
function out($value) {
echo $value . "\n";
return $value;
echo $value . "\n";
return $value;
}

/**
Expand All @@ -89,8 +89,8 @@ function out($value) {
* @return string
*/
function buildPath($directory, $filename = null, $extension = null) {
return out(EXAMPLE_PATH . '/' . $directory.
($extension !== null && $filename !== null ? '/' . $filename. "." . $extension : ""));
return out(EXAMPLE_PATH . '/' . $directory.
($extension !== null && $filename !== null ? '/' . $filename. "." . $extension : ""));
}

/**
Expand All @@ -102,9 +102,9 @@ function buildPath($directory, $filename = null, $extension = null) {
* @return void
*/
function createDirectory($directory) {
if(!@mkdir(buildPath($directory))) {
die("FAILED to create directory\n");
}
if(!@mkdir(buildPath($directory))) {
die("FAILED to create directory\n");
}
}

/**
Expand All @@ -119,13 +119,13 @@ function createDirectory($directory) {
* @return void
*/
function createFile($directory, $filename, $extension, $content = "") {
$handle = @fopen(buildPath($directory, $filename, $extension), "w");
if($handle) {
fwrite($handle, $content);
fclose($handle);
} else {
die("FAILED to create file\n");
}
$handle = @fopen(buildPath($directory, $filename, $extension), "w");
if($handle) {
fwrite($handle, $content);
fclose($handle);
} else {
die("FAILED to create file\n");
}
}


Expand All @@ -143,29 +143,29 @@ function createFile($directory, $filename, $extension, $content = "") {
* @return void
*/
function main($example_name) {
$lowercase = getLowerCaseName($example_name);
$uppercase = getUpperCaseName($example_name);
createDirectory($lowercase);
createFile($lowercase, $lowercase, "mustache");
createFile($lowercase, $lowercase, "txt");
createFile($lowercase, $uppercase, "php", <<<CONTENT
$lowercase = getLowerCaseName($example_name);
$uppercase = getUpperCaseName($example_name);
createDirectory($lowercase);
createFile($lowercase, $lowercase, "mustache");
createFile($lowercase, $lowercase, "txt");
createFile($lowercase, $uppercase, "php", <<<CONTENT
<?php
class {$uppercase} {
}
CONTENT
);
);
}

// check if enougth arguments are given
if(count($argv) > 1) {
// get the name of the example
$example_name = $argv[1];
// get the name of the example
$example_name = $argv[1];

main($example_name);
main($example_name);

} else {
echo USAGE;
echo USAGE;
}
90 changes: 47 additions & 43 deletions src/Mustache/Autoloader.php
Expand Up @@ -12,54 +12,58 @@
/**
* Mustache class autoloader.
*/
class Mustache_Autoloader {
class Mustache_Autoloader
{

private $baseDir;
private $baseDir;

/**
* Autoloader constructor.
*
* @param string $baseDir Mustache library base directory (default: dirname(__FILE__).'/..')
*/
public function __construct($baseDir = null) {
if ($baseDir === null) {
$this->baseDir = dirname(__FILE__).'/..';
} else {
$this->baseDir = rtrim($baseDir, '/');
}
}
/**
* Autoloader constructor.
*
* @param string $baseDir Mustache library base directory (default: dirname(__FILE__).'/..')
*/
public function __construct($baseDir = null)
{
if ($baseDir === null) {
$this->baseDir = dirname(__FILE__).'/..';
} else {
$this->baseDir = rtrim($baseDir, '/');
}
}

/**
* Register a new instance as an SPL autoloader.
*
* @param string $baseDir Mustache library base directory (default: dirname(__FILE__).'/..')
*
* @return Mustache_Autoloader Registered Autoloader instance
*/
static public function register($baseDir = null) {
$loader = new self($baseDir);
spl_autoload_register(array($loader, 'autoload'));
/**
* Register a new instance as an SPL autoloader.
*
* @param string $baseDir Mustache library base directory (default: dirname(__FILE__).'/..')
*
* @return Mustache_Autoloader Registered Autoloader instance
*/
static public function register($baseDir = null)
{
$loader = new self($baseDir);
spl_autoload_register(array($loader, 'autoload'));

return $loader;
}
return $loader;
}

/**
* Autoload Mustache classes.
*
* @param string $class
*/
public function autoload($class) {
if ($class[0] === '\\') {
$class = substr($class, 1);
}
/**
* Autoload Mustache classes.
*
* @param string $class
*/
public function autoload($class)
{
if ($class[0] === '\\') {
$class = substr($class, 1);
}

if (strpos($class, 'Mustache') !== 0) {
return;
}
if (strpos($class, 'Mustache') !== 0) {
return;
}

$file = sprintf('%s/%s.php', $this->baseDir, str_replace('_', '/', $class));
if (is_file($file)) {
require $file;
}
}
$file = sprintf('%s/%s.php', $this->baseDir, str_replace('_', '/', $class));
if (is_file($file)) {
require $file;
}
}
}

0 comments on commit 2448992

Please sign in to comment.