-
Notifications
You must be signed in to change notification settings - Fork 8
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 #12 from resmushit/updates
- Loading branch information
Showing
50 changed files
with
6,193 additions
and
2,691 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
namespace Resmush\Build; | ||
|
||
class PackageLoader | ||
{ | ||
public $dir; | ||
public $composerFile = false; | ||
|
||
public function __construct() | ||
{ | ||
|
||
} | ||
|
||
public function setComposerFile($filePath) | ||
{ | ||
$this->composerFile = json_decode(file_get_contents($filePath),1); | ||
} | ||
|
||
public function getComposerFile($filePath = false ) | ||
{ | ||
if (! $this->composerFile) | ||
$this->composerFile = json_decode(file_get_contents($this->dir."/composer.json"), 1); | ||
|
||
return $this->composerFile; | ||
} | ||
|
||
public function load($dir, $prepend = false) | ||
{ | ||
$this->dir = $dir; | ||
$composer = $this->getComposerFile(); | ||
|
||
|
||
if(isset($composer["autoload"]["psr-4"])){ | ||
$this->loadPSR4($composer['autoload']['psr-4'], $prepend); | ||
} | ||
if(isset($composer["autoload"]["psr-0"])){ | ||
$this->loadPSR0($composer['autoload']['psr-0']); | ||
} | ||
if(isset($composer["autoload"]["files"])){ | ||
$this->loadFiles($composer["autoload"]["files"]); | ||
} | ||
} | ||
|
||
public function loadFiles($files){ | ||
foreach($files as $file){ | ||
$fullpath = $this->dir."/".$file; | ||
if(file_exists($fullpath)){ | ||
include_once($fullpath); | ||
} | ||
} | ||
} | ||
|
||
public function loadPSR4($namespaces, $prepend) | ||
{ | ||
$this->loadPSR($namespaces, true, $prepend); | ||
} | ||
|
||
public function loadPSR0($namespaces) | ||
{ | ||
$this->loadPSR($namespaces, false); | ||
} | ||
|
||
public function loadPSR($namespaces, $psr4, $prepend = false) | ||
{ | ||
$dir = $this->dir; | ||
// Foreach namespace specified in the composer, load the given classes | ||
foreach ($namespaces as $namespace => $classpaths) { | ||
if (!is_array($classpaths)) { | ||
$classpaths = array($classpaths); | ||
} | ||
spl_autoload_register(function ($classname) use ($namespace, $classpaths, $dir, $psr4) { | ||
// Check if the namespace matches the class we are looking for | ||
if (preg_match("#^".preg_quote($namespace)."#", $classname)) { | ||
// Remove the namespace from the file path since it's psr4 | ||
if ($psr4) { | ||
$classname = str_replace($namespace, "", $classname); | ||
} | ||
|
||
// $filename = preg_replace("#\\\\#", "", $classname).".php"; | ||
// This is fix for nested classes which were losing a / | ||
$filename = ltrim($classname .'.php', '\\'); | ||
$filename = str_replace('\\','/', $filename); | ||
|
||
foreach ($classpaths as $classpath) { | ||
$fullpath = trailingslashit($dir) . trailingslashit($classpath) .$filename; | ||
if (file_exists($fullpath)) { | ||
include_once $fullpath; | ||
} | ||
} | ||
} | ||
}, true, $prepend); | ||
} | ||
} | ||
} |
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,5 @@ | ||
<?php | ||
require_once (__DIR__ . "/PackageLoader.php"); | ||
$loader = new Resmush\Build\PackageLoader(); | ||
$loader->load(__DIR__); | ||
|
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 @@ | ||
{"name":"Resmush\/shortpixelmodules","description":"ShortPixel submodules","type":"function","autoload":{"psr-4":{"Resmush\\Notices":"notices\/src","Resmush\\ShortPixelLogger":"log\/src","Resmush\\FileSystem":"filesystem\/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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "shortpixel/filesystem", | ||
"description": "ShortPixel FileSystem", | ||
"version": 1.0, | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Bas", | ||
"email": "bas@weblogmechanic.com" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": {}, | ||
"autoload": { | ||
"psr-4": { "ShortPixel\\FileSystem\\" : "src" } | ||
} | ||
} |
Oops, something went wrong.