Skip to content

Commit

Permalink
Code style updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Jan 9, 2012
1 parent e5f3a05 commit 236ba06
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
5 changes: 1 addition & 4 deletions Mustache.php
Expand Up @@ -819,10 +819,7 @@ protected function _findVariableInContext($tag_name, $context) {
* @return string
*/
protected function _getPartial($tag_name) {
if (
(is_array($this->_partials) || $this->_partials instanceof ArrayAccess)
&& isset($this->_partials[$tag_name])
) {
if ((is_array($this->_partials) || $this->_partials instanceof ArrayAccess) && isset($this->_partials[$tag_name])) {
return $this->_partials[$tag_name];
}

Expand Down
103 changes: 53 additions & 50 deletions bin/create_example.php
Expand Up @@ -2,12 +2,15 @@
<?php

/**
* A commandline script to create an example and the needed files
* use like this:
* $ bin/create_example.php my_new_example
* A commandline script to create an example and the needed files:
*
* and the folder my_new_example will be created in the examples/ folder containing 3 files
* $ bin/create_example.php my_new_example
*
* ... and the folder my_new_example will be created in the examples/ folder containing 3 files:
*
* my_new_example/my_new_example.mustache
* my_new_example/my_new_example.txt
* my_new_example/MyNewExample.php
*/

// some constants
Expand All @@ -30,16 +33,16 @@
* AString -> a_string
* SomeStrings -> some_strings
* AStringMore -> a_string_more
*
* @param string $name
*
* @param string $name
* @access public
* @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 @@ -49,66 +52,66 @@ function getLowerCaseName($name) {
* a_string -> AString
* some_strings -> SomeStrings
* a_string_more -> AStringMore -> a_string_more
*
* @param string $name
*
* @param string $name
* @access public
* @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));
}


/**
* return the given value and echo it out appending "\n"
*
* @param mixed $value
*
* @param mixed $value
* @access public
* @return mixed
*/
function out($value) {
echo $value . "\n";
return $value;
echo $value . "\n";
return $value;
}

/**
* create Path for certain files in an example
* returns the directory name if only $directory is given.
* if an extension is given a complete filename is returned.
* the returned filename will be echoed out
*
*
* @param string $directory directory without / at the end
* @param string $filename filename without path and extension
* @param string $extension extension of the file without "."
* @access public
* @return string
*/
function buildPath($directory, $filename = null, $extension = null) {
return out(EXAMPLE_PATH . DS . $directory.
($extension !== null && $filename !== null ? DS . $filename. "." . $extension : ""));
return out(EXAMPLE_PATH . DS . $directory.
($extension !== null && $filename !== null ? DS . $filename. "." . $extension : ""));
}

/**
* creates the directory for the example
* the script die()'s if mkdir() fails
*
* @param string $directory
*
* @param string $directory
* @access public
* @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");
}
}

/**
* create a file for the example with the given $content
* the script die()'s if fopen() fails
*
*
* @param string $directory directory without / at the end
* @param string $filename filename without path and extension
* @param string $extension extension of the file without "."
Expand All @@ -117,13 +120,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 @@ -135,35 +138,35 @@ function createFile($directory, $filename, $extension, $content = "") {
* examples/some_thing/some_thing.mustache
* examples/some_thing/some_thing.txt
* examples/some_thing/SomeThing.php
*
* @param mixed $example_name
*
* @param mixed $example_name
* @access public
* @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} extends Mustache {
}
CONTENT
);
);
}

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

main($example_name);

} else {
echo USAGE;
echo USAGE;
}

0 comments on commit 236ba06

Please sign in to comment.