-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from clickalicious/story-2-refactoring-general
Refactored // Updated documentation // Cleanup // Polyfill added
- Loading branch information
Showing
9 changed files
with
331 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
<?php | ||
|
||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | ||
|
||
namespace Clickalicious\Rng; | ||
|
||
/** | ||
* Rng | ||
* Rng. | ||
* | ||
* Autoloader.php - Autoloader of Rng. | ||
* | ||
* | ||
* PHP versions 5.3 | ||
* PHP versions 5.4 | ||
* | ||
* LICENSE: | ||
* Rng - Random number generator for PHP | ||
* | ||
* Copyright (c) 2015, Benjamin Carl | ||
* Copyright (c) 2015 - 2016, Benjamin Carl | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -45,27 +46,29 @@ | |
* Please feel free to contact us via e-mail: [email protected] | ||
* | ||
* @category Clickalicious | ||
* @package Clickalicious_Rng | ||
* @subpackage Clickalicious_Rng_Autoloader | ||
* | ||
* @author Benjamin Carl <[email protected]> | ||
* @copyright 2015 Benjamin Carl | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright 2015 - 2016 Benjamin Carl | ||
* @license https://opensource.org/licenses/BSD-2-Clause BSD-2-Clause | ||
* | ||
* @version Git: $Id$ | ||
* | ||
* @link https://github.com/clickalicious/Rng | ||
*/ | ||
|
||
/** | ||
* Rng | ||
* Rng. | ||
* | ||
* Autoloader.php - Autoloader of Rng. | ||
* | ||
* @category Clickalicious | ||
* @package Clickalicious_Rng | ||
* @subpackage Clickalicious_Rng_Autoloader | ||
* | ||
* @author Benjamin Carl <[email protected]> | ||
* @copyright 2015 Benjamin Carl | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright 2015 - 2016 Benjamin Carl | ||
* @license https://opensource.org/licenses/BSD-2-Clause BSD-2-Clause | ||
* | ||
* @version Git: $Id$ | ||
* | ||
* @link https://github.com/clickalicious/Rng | ||
*/ | ||
class Autoloader | ||
|
@@ -76,40 +79,37 @@ class Autoloader | |
* | ||
* @var array | ||
*/ | ||
protected $prefixes = array(); | ||
protected $prefixes = []; | ||
|
||
/** | ||
* Register loader with SPL autoloader stack. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
spl_autoload_register(array($this, 'loadClass')); | ||
spl_autoload_register([$this, 'loadClass']); | ||
} | ||
|
||
/** | ||
* Adds a base directory for a namespace prefix. | ||
* | ||
* @param string $prefix The namespace prefix. | ||
* @param string $prefix The namespace prefix. | ||
* @param string $base_dir A base directory for class files in the | ||
* namespace. | ||
* @param bool $prepend If true, prepend the base directory to the stack | ||
* instead of appending it; this causes it to be searched first rather | ||
* than last. | ||
* @return void | ||
* namespace. | ||
* @param bool $prepend If true, prepend the base directory to the stack | ||
* instead of appending it; this causes it to be searched first rather | ||
* than last. | ||
*/ | ||
public function addNamespace($prefix, $base_dir, $prepend = false) | ||
{ | ||
// normalize namespace prefix | ||
$prefix = trim($prefix, '\\') . '\\'; | ||
$prefix = trim($prefix, '\\').'\\'; | ||
|
||
// normalize the base directory with a trailing separator | ||
$base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; | ||
$base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; | ||
|
||
// initialize the namespace prefix array | ||
if (isset($this->prefixes[$prefix]) === false) { | ||
$this->prefixes[$prefix] = array(); | ||
$this->prefixes[$prefix] = []; | ||
} | ||
|
||
// retain the base directory for the namespace prefix | ||
|
@@ -124,8 +124,9 @@ public function addNamespace($prefix, $base_dir, $prepend = false) | |
* Loads the class file for a given class name. | ||
* | ||
* @param string $class The fully-qualified class name. | ||
* | ||
* @return mixed The mapped file name on success, or boolean false on | ||
* failure. | ||
* failure. | ||
*/ | ||
public function loadClass($class) | ||
{ | ||
|
@@ -161,10 +162,11 @@ public function loadClass($class) | |
/** | ||
* Load the mapped file for a namespace prefix and relative class. | ||
* | ||
* @param string $prefix The namespace prefix. | ||
* @param string $prefix The namespace prefix. | ||
* @param string $relative_class The relative class name. | ||
* | ||
* @return mixed Boolean false if no mapped file can be loaded, or the | ||
* name of the mapped file that was loaded. | ||
* name of the mapped file that was loaded. | ||
*/ | ||
protected function loadMappedFile($prefix, $relative_class) | ||
{ | ||
|
@@ -180,8 +182,8 @@ protected function loadMappedFile($prefix, $relative_class) | |
// replace namespace separators with directory separators | ||
// in the relative class name, append with .php | ||
$file = $base_dir | ||
. str_replace('\\', '/', $relative_class) | ||
. '.php'; | ||
.str_replace('\\', '/', $relative_class) | ||
.'.php'; | ||
|
||
// if the mapped file exists, require it | ||
if ($this->requireFile($file)) { | ||
|
@@ -198,14 +200,17 @@ protected function loadMappedFile($prefix, $relative_class) | |
* If a file exists, require it from the file system. | ||
* | ||
* @param string $file The file to require. | ||
* | ||
* @return bool True if the file exists, false if not. | ||
*/ | ||
protected function requireFile($file) | ||
{ | ||
if (file_exists($file)) { | ||
require $file; | ||
include_once $file; | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
<?php | ||
|
||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | ||
|
||
namespace Clickalicious\Rng; | ||
|
||
/** | ||
* Rng | ||
* Rng. | ||
* | ||
* Bootstrap.php - Bootstrapping of directories and so on. | ||
* | ||
* | ||
* PHP versions 5.3 | ||
* PHP versions 5.4 | ||
* | ||
* LICENSE: | ||
* Rng - Plain vanilla PHP Rng client with full support of Rng protocol. | ||
* | ||
* Copyright (c) 2015, Benjamin Carl | ||
* Copyright (c) 2015 - 2016, Benjamin Carl | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -45,28 +46,29 @@ | |
* Please feel free to contact us via e-mail: [email protected] | ||
* | ||
* @category Clickalicious | ||
* @package Clickalicious_Rng | ||
* @subpackage Clickalicious_Rng_Bootstrap | ||
* | ||
* @author Benjamin Carl <[email protected]> | ||
* @copyright 2015 Benjamin Carl | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright 2015 - 2016 Benjamin Carl | ||
* @license https://opensource.org/licenses/BSD-2-Clause BSD-2-Clause | ||
* | ||
* @version Git: $Id$ | ||
* | ||
* @link https://github.com/clickalicious/Rng | ||
*/ | ||
|
||
// Include autoloader | ||
require_once 'Autoloader.php'; | ||
|
||
/** | ||
* Detects composer in global scope | ||
* Detects composer in global scope. | ||
* | ||
* @author Benjamin Carl <[email protected]> | ||
* | ||
* @return bool TRUE if composer is active, otherwise FALSE | ||
* @access public | ||
*/ | ||
function composer_running() | ||
{ | ||
$result = false; | ||
$result = false; | ||
$classes = get_declared_classes(); | ||
natsort($classes); | ||
foreach ($classes as $class) { | ||
|
@@ -83,17 +85,16 @@ function composer_running() | |
// The base path to /src/ if we don't have Composer we need to know root path | ||
define( | ||
'CLICKALICIOUS_RNG_BASE_PATH', | ||
realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR) . | ||
realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR). | ||
DIRECTORY_SEPARATOR | ||
); | ||
|
||
// Root node | ||
$root = realpath(CLICKALICIOUS_RNG_BASE_PATH . '../'); | ||
$root = realpath(CLICKALICIOUS_RNG_BASE_PATH.'../'); | ||
|
||
// Check for composer existence | ||
if (true === $composerExist = $composerRunning = file_exists($root . '/vendor/autoload.php')) { | ||
include_once $root . '/vendor/autoload.php'; | ||
|
||
if (true === $composerExist = $composerRunning = file_exists($root.'/vendor/autoload.php')) { | ||
include_once $root.'/vendor/autoload.php'; | ||
} else { | ||
$composerExist = $composerRunning = composer_running(); | ||
} | ||
|
@@ -122,4 +123,4 @@ function composer_running() | |
$loader->register(); | ||
|
||
// register the base directories for the namespace prefix | ||
$loader->addNamespace('Clickalicious\Rng', CLICKALICIOUS_RNG_BASE_PATH . 'Clickalicious\Rng'); | ||
$loader->addNamespace('Clickalicious\Rng', CLICKALICIOUS_RNG_BASE_PATH.'Clickalicious\Rng'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
<?php | ||
|
||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | ||
|
||
namespace Clickalicious\Rng; | ||
|
||
/** | ||
* Rng | ||
* Rng. | ||
* | ||
* Exception.php - Exception of Rng package. | ||
* | ||
* | ||
* PHP versions 5.3 | ||
* PHP versions 5.4 | ||
* | ||
* LICENSE: | ||
* Rng - Random number generator for PHP | ||
* | ||
* Copyright (c) 2015, Benjamin Carl | ||
* Copyright (c) 2015 - 2016, Benjamin Carl | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -45,27 +46,29 @@ | |
* Please feel free to contact us via e-mail: [email protected] | ||
* | ||
* @category Clickalicious | ||
* @package Clickalicious_Rng | ||
* @subpackage Clickalicious_Rng_Exception | ||
* | ||
* @author Benjamin Carl <[email protected]> | ||
* @copyright 2015 Benjamin Carl | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright 2015 - 2016 Benjamin Carl | ||
* @license https://opensource.org/licenses/BSD-2-Clause BSD-2-Clause | ||
* | ||
* @version Git: $Id$ | ||
* | ||
* @link https://github.com/clickalicious/Rng | ||
*/ | ||
|
||
/** | ||
* Rng | ||
* Rng. | ||
* | ||
* Exception of Rng package. | ||
* | ||
* @category Clickalicious | ||
* @package Clickalicious_Rng | ||
* @subpackage Clickalicious_Rng_Exception | ||
* | ||
* @author Benjamin Carl <[email protected]> | ||
* @copyright 2015 Benjamin Carl | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright 2015 - 2016 Benjamin Carl | ||
* @license https://opensource.org/licenses/BSD-2-Clause BSD-2-Clause | ||
* | ||
* @version Git: $Id$ | ||
* | ||
* @link https://github.com/clickalicious/Rng | ||
*/ | ||
class Exception extends \RuntimeException | ||
|
Oops, something went wrong.