-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
514 additions
and
269 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
vendor/ | ||
|
||
tests/tmp/ | ||
phpunit*.xml | ||
.DS_Store | ||
._* | ||
node_modules/ | ||
npm* | ||
.svn/ | ||
!src/assets | ||
|
||
composer.lock | ||
|
||
vendor | ||
inc/requisite/* | ||
!inc/requisite/src | ||
|
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,8 +1,15 @@ | ||
language: php | ||
|
||
php: | ||
- '5.4' | ||
- '5.5' | ||
- '5.6' | ||
- '7.0' | ||
- hhvm | ||
- nightly | ||
|
||
before_script: | ||
- composer install --no-progress --prefer-source | ||
|
||
script: | ||
- phpunit |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Export the same files as the wordpress.org plugin repository | ||
# Based on https://plugins.trac.wordpress.org/browser/search-and-replace/trunk | ||
|
||
wporg export-ignore |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
|
||
namespace Requisite; | ||
|
||
/** | ||
* Interface AutoLoaderInterface | ||
* | ||
* @package Requisite | ||
*/ | ||
interface AutoLoaderInterface { | ||
|
||
/** | ||
* @param Rule\AutoLoadRuleInterface $rule | ||
* @return void | ||
*/ | ||
public function addRule( Rule\AutoLoadRuleInterface $rule ); | ||
} |
27 changes: 27 additions & 0 deletions
27
inc/requisite/src/Requisite/Loader/DefaultConditionalFileLoader.php
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
|
||
namespace Requisite\Loader; | ||
|
||
/** | ||
* Class DefaultConditionalFileLoader | ||
* | ||
* Loads a given file if it is_readable(). | ||
* | ||
* @package Requisite\Loader | ||
*/ | ||
class DefaultConditionalFileLoader implements FileLoaderInterface { | ||
|
||
/** | ||
* @param string $file | ||
* @return bool | ||
*/ | ||
public function loadFile( $file ) { | ||
|
||
if ( ! is_readable( $file ) ) | ||
return FALSE; | ||
|
||
require_once $file; | ||
return TRUE; | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
inc/requisite/src/Requisite/Loader/DirectoryCacheFileLoader.php
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
|
||
namespace Requisite\Loader; | ||
|
||
/** | ||
* Class DirectoryCacheFileLoader | ||
* | ||
* reads in a whole directory at once to cache the existing files | ||
* to avoid frequently usage of file_exists() checks | ||
* | ||
* @package Requisite\Loader | ||
*/ | ||
class DirectoryCacheFileLoader implements FileLoaderInterface { | ||
|
||
/** | ||
* @type array | ||
*/ | ||
private $files = array(); | ||
|
||
/** | ||
* @type string | ||
*/ | ||
private $extension; | ||
|
||
/** | ||
* @tpye string | ||
*/ | ||
private $base_dir; | ||
|
||
/** | ||
* @param string $base_dir | ||
* @param string $extension | ||
*/ | ||
function __construct( $base_dir, $extension = '.php' ) { | ||
|
||
$this->base_dir = (string) $base_dir; | ||
$this->extension = (string) $extension; | ||
} | ||
|
||
/** | ||
* @param string $file | ||
* @return bool | ||
*/ | ||
public function loadFile( $file ) { | ||
|
||
if ( empty( $this->files ) ) | ||
$this->files = $this->readDirRecursive( | ||
$this->base_dir, | ||
'*' . $this->extension | ||
); | ||
|
||
if ( ! in_array( $file, $this->files ) ) | ||
return FALSE; | ||
|
||
require_once $file; | ||
return TRUE; | ||
} | ||
|
||
/** | ||
* read the subdirectory recursive and catch all files with the | ||
* given pattern | ||
* | ||
* Will return an array with the pattern as element if no file exists | ||
* | ||
* @param $dir | ||
* @param $pattern | ||
* @return array | ||
*/ | ||
public function readDirRecursive( $dir, $pattern ) { | ||
|
||
$sub_dirs = glob( $dir . '/*', \GLOB_ONLYDIR ); | ||
$files = array(); | ||
if ( ! empty( $sub_dirs ) ) { | ||
foreach ( $sub_dirs as $sub_dir ) { | ||
$files = array_merge( $files, $this->readDirRecursive( $sub_dir, $pattern ) ); | ||
} | ||
} | ||
$files = array_merge( $files, glob( $dir . '/' . $pattern, \GLOB_NOCHECK ) ); | ||
|
||
return $files; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
inc/requisite/src/Requisite/Loader/FileLoaderInterface.php
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
|
||
namespace Requisite\Loader; | ||
|
||
/** | ||
* Interface FileLoaderInterface | ||
* | ||
* Loads a given file, if exists. | ||
* | ||
* @package Requisite\Loader | ||
*/ | ||
interface FileLoaderInterface { | ||
|
||
/** | ||
* @param string $file | ||
* @return bool | ||
*/ | ||
public function loadFile( $file ); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
|
||
namespace Requisite; | ||
|
||
/** | ||
* Class Requisite | ||
* | ||
* This class is just a static wrapper to load Requisite | ||
* if it is not used with an auto loader itself. | ||
* | ||
* @package Requisite | ||
*/ | ||
class Requisite { | ||
|
||
/** | ||
* @type bool | ||
*/ | ||
private static $is_loaded = FALSE; | ||
|
||
/** | ||
* @param string $base_dir (Optional, default to __DIR__ which is normally src/Requisite) | ||
*/ | ||
public static function init( $base_dir = '' ) { | ||
|
||
if ( self::$is_loaded ) | ||
return; | ||
|
||
if ( empty( $base_dir ) ) | ||
$base_dir = __DIR__; | ||
$base_dir = rtrim( $base_dir, '/\\' ); | ||
$classes = self::get_classes(); | ||
|
||
foreach ( $classes as $class => $file ) { | ||
if ( ! class_exists( $class ) ) | ||
require_once $base_dir . $file; | ||
} | ||
|
||
self::$is_loaded = TRUE; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private static function get_classes() { | ||
|
||
return array( | ||
__NAMESPACE__ . '\Loader\FileLoaderInterface' | ||
=> '/Loader/FileLoaderInterface.php', | ||
|
||
__NAMESPACE__ . '\Loader\DefaultConditionalFileLoader' | ||
=> '/Loader/DefaultConditionalFileLoader.php', | ||
|
||
__NAMESPACE__ . '\Loader\DirectoryCacheFileLoader' | ||
=> '/Loader/DirectoryCacheFileLoader.php', | ||
|
||
__NAMESPACE__ . '\Rule\AutoLoadRuleInterface' | ||
=> '/Rule/AutoLoadRuleInterface.php', | ||
|
||
__NAMESPACE__ . '\Rule\Psr4' | ||
=> '/Rule/Psr4.php', | ||
|
||
__NAMESPACE__ . '\Rule\NamespaceDirectoryMapper' | ||
=> '/Rule/NamespaceDirectoryMapper.php', | ||
|
||
__NAMESPACE__ . '\AutoLoaderInterface' | ||
=> '/AutoLoaderInterface.php', | ||
|
||
__NAMESPACE__ . '\SPLAutoLoader' | ||
=> '/SPLAutoLoader.php' | ||
); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
inc/requisite/src/Requisite/Rule/AutoLoadRuleInterface.php
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
|
||
namespace Requisite\Rule; | ||
|
||
/** | ||
* Interface AutoLoadRuleInterface | ||
* | ||
* AutoLoad rules are responsible to locate concrete files by a given, | ||
* fully qualified class names and load this class, if exists. | ||
* In a typical Requisite implementation they use Instances of | ||
* Requisite\Loader\FileLoaderInterface for that. | ||
* | ||
* @package Requisite\Rule | ||
*/ | ||
interface AutoLoadRuleInterface { | ||
|
||
/** | ||
* @param string $class | ||
* @return bool | ||
*/ | ||
public function loadClass( $class ); | ||
} |
13 changes: 13 additions & 0 deletions
13
inc/requisite/src/Requisite/Rule/NamespaceDirectoryMapper.php
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
|
||
namespace Requisite\Rule; | ||
|
||
/** | ||
* Class NamespaceDirectoryMapper | ||
* | ||
* Alias of Psr4, provided for backward compatibility | ||
* | ||
* @deprecated | ||
* @package Requisite\Rule | ||
*/ | ||
class NamespaceDirectoryMapper extends Psr4 implements AutoLoadRuleInterface {} |
Oops, something went wrong.