Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
derpixler committed Apr 4, 2016
2 parents f4ce20e + 72bb0eb commit a72f7a3
Show file tree
Hide file tree
Showing 63 changed files with 514 additions and 269 deletions.
5 changes: 2 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
.git export-ignore
.gitignore export-ignore
.gitattributes export-ignore
assets/ export-ignore
test/ export-ignore
CHANGELOG.md export-ignore
CONTRIBUTING.md export-ignore
Gruntfile.js export-ignore
LICENSE export-ignore
README.md export-ignore
assets export-ignore
composer.json export-ignore
package.json export-ignore
phpunit.xml.dist export-ignore
.travis.yml export-ignore
.travis.yml export-ignore
wporg-assets export-ignore
10 changes: 8 additions & 2 deletions .gitignore
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

7 changes: 7 additions & 0 deletions .travis.yml
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
4 changes: 4 additions & 0 deletions assets/.gitattributes
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
22 changes: 19 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,26 @@
},
"require": {
"php": ">=5.3",
"composer/installers": "~1.0"
"composer/installers": "~1.0",
"level-2/dice": "dev-v2.0-PHP5.4-5.5",
"mnsami/composer-custom-directory-installer": "1.1.*",
"dnaber/requisite": "1.0"
},
"require-dev": {
"phpmd/phpmd": "2.1.3",
"phpunit/phpunit": "5.*"
"brain/monkey": "^1.3",
"mockery/mockery": "*"
},
"autoload-dev": {
"psr-4": {
"Inpsyde\\SearchReplace\\Test\\Helper\\": "tests/phpunit/Helper/"
}
},
"extra":
{
"installer-paths": {
"./inc/requisite": [
"dnaber/requisite"
]
}
}
}
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.
17 changes: 17 additions & 0 deletions inc/requisite/src/Requisite/AutoLoaderInterface.php
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 );
}
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 inc/requisite/src/Requisite/Loader/DirectoryCacheFileLoader.php
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 inc/requisite/src/Requisite/Loader/FileLoaderInterface.php
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 );
}
72 changes: 72 additions & 0 deletions inc/requisite/src/Requisite/Requisite.php
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 inc/requisite/src/Requisite/Rule/AutoLoadRuleInterface.php
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 inc/requisite/src/Requisite/Rule/NamespaceDirectoryMapper.php
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 {}
Loading

0 comments on commit a72f7a3

Please sign in to comment.