[TASK] composer update

This commit is contained in:
Kanti 2014-12-28 20:26:41 +01:00
commit ef90b19af8
6 changed files with 112 additions and 97 deletions

10
composer.lock generated
View file

@ -8,16 +8,16 @@
"packages": [ "packages": [
{ {
"name": "kanti/hub-updater", "name": "kanti/hub-updater",
"version": "v0.3.0", "version": "v0.3.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Kanti/hub-updater.git", "url": "https://github.com/Kanti/hub-updater.git",
"reference": "c520b71d9e836932e67bae7177b9a8bc49dda032" "reference": "105bf291983b1323c5916092cc4e170bf987b00c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Kanti/hub-updater/zipball/c520b71d9e836932e67bae7177b9a8bc49dda032", "url": "https://api.github.com/repos/Kanti/hub-updater/zipball/105bf291983b1323c5916092cc4e170bf987b00c",
"reference": "c520b71d9e836932e67bae7177b9a8bc49dda032", "reference": "105bf291983b1323c5916092cc4e170bf987b00c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -42,7 +42,7 @@
} }
], ],
"description": "Simple Github Updater for Web Projects", "description": "Simple Github Updater for Web Projects",
"time": "2014-12-12 17:28:13" "time": "2014-12-27 13:59:09"
}, },
{ {
"name": "michelf/php-markdown", "name": "michelf/php-markdown",

View file

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer' . '/autoload_real.php'; require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit4e8efbd787f4b484a9c0ae0966c85f83::getLoader(); return ComposerAutoloaderInita77bbbb06005e971afb84206c22613bb::getLoader();

View file

@ -56,7 +56,11 @@ class ClassLoader
public function getPrefixes() public function getPrefixes()
{ {
return call_user_func_array('array_merge', $this->prefixesPsr0); if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
} }
public function getPrefixesPsr4() public function getPrefixesPsr4()

View file

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInit4e8efbd787f4b484a9c0ae0966c85f83 class ComposerAutoloaderInita77bbbb06005e971afb84206c22613bb
{ {
private static $loader; private static $loader;
@ -19,9 +19,9 @@ class ComposerAutoloaderInit4e8efbd787f4b484a9c0ae0966c85f83
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInit4e8efbd787f4b484a9c0ae0966c85f83', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInita77bbbb06005e971afb84206c22613bb', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(); self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit4e8efbd787f4b484a9c0ae0966c85f83', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInita77bbbb06005e971afb84206c22613bb', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php'; $map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) { foreach ($map as $namespace => $path) {
@ -42,14 +42,14 @@ class ComposerAutoloaderInit4e8efbd787f4b484a9c0ae0966c85f83
$includeFiles = require __DIR__ . '/autoload_files.php'; $includeFiles = require __DIR__ . '/autoload_files.php';
foreach ($includeFiles as $file) { foreach ($includeFiles as $file) {
composerRequire4e8efbd787f4b484a9c0ae0966c85f83($file); composerRequirea77bbbb06005e971afb84206c22613bb($file);
} }
return $loader; return $loader;
} }
} }
function composerRequire4e8efbd787f4b484a9c0ae0966c85f83($file) function composerRequirea77bbbb06005e971afb84206c22613bb($file)
{ {
require $file; require $file;
} }

View file

@ -101,25 +101,25 @@
}, },
{ {
"name": "kanti/hub-updater", "name": "kanti/hub-updater",
"version": "v0.3.0", "version": "v0.3.1",
"version_normalized": "0.3.0.0", "version_normalized": "0.3.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Kanti/hub-updater.git", "url": "https://github.com/Kanti/hub-updater.git",
"reference": "c520b71d9e836932e67bae7177b9a8bc49dda032" "reference": "105bf291983b1323c5916092cc4e170bf987b00c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Kanti/hub-updater/zipball/c520b71d9e836932e67bae7177b9a8bc49dda032", "url": "https://api.github.com/repos/Kanti/hub-updater/zipball/105bf291983b1323c5916092cc4e170bf987b00c",
"reference": "c520b71d9e836932e67bae7177b9a8bc49dda032", "reference": "105bf291983b1323c5916092cc4e170bf987b00c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.0" "php": ">=5.3.0"
}, },
"time": "2014-12-12 17:28:13", "time": "2014-12-27 13:59:09",
"type": "library", "type": "library",
"installation-source": "source", "installation-source": "dist",
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Kanti\\": "" "Kanti\\": ""

View file

@ -17,8 +17,8 @@ class HubUpdater
"cache" => "cache/", "cache" => "cache/",
"save" => "", "save" => "",
"prerelease" => false, "prerelease" => false,
"exceptions" => false, "exceptions" => false,
); );
protected $allRelease = array(); protected $allRelease = array();
@ -26,9 +26,9 @@ class HubUpdater
public function __construct($option) public function __construct($option)
{ {
//options //options
if (is_array($option)) { if (is_array($option)) {
if (! isset($option['name'])) { if (!isset($option['name'])) {
throw new \Exception('No Name in Option Set'); throw new \Exception('No Name in Option Set');
} }
$this->options = $option + $this->options; $this->options = $option + $this->options;
@ -52,15 +52,15 @@ class HubUpdater
mkdir($this->options['cache']); mkdir($this->options['cache']);
} }
} }
$caBundleDir = dirname(__FILE__); $caBundleDir = dirname(__FILE__);
if (HelperClass::isInPhar()) { if (HelperClass::isInPhar()) {
$caBundleDir = dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . $this->options['cache']; $caBundleDir = dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . $this->options['cache'];
if (! HelperClass::fileExists($this->options['cache'] . "ca_bundle.crt")) { if (!HelperClass::fileExists($this->options['cache'] . "ca_bundle.crt")) {
copy(dirname(__FILE__) . "/ca_bundle.crt",$caBundleDir . "ca_bundle.crt"); copy(dirname(__FILE__) . "/ca_bundle.crt", $caBundleDir . "ca_bundle.crt");
} }
} }
$this->cachedInfo = new CacheOneFile(dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . $this->options['cache'] . $this->options['cacheFile'],$this->options['holdTime']); $this->cachedInfo = new CacheOneFile(dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . $this->options['cache'] . $this->options['cacheFile'], $this->options['holdTime']);
$this->streamContext = stream_context_create( $this->streamContext = stream_context_create(
array( array(
@ -89,35 +89,39 @@ class HubUpdater
protected function getRemoteInfos() protected function getRemoteInfos()
{ {
$path = "https://api.github.com/repos/" . $this->options['name'] ."/releases"; $path = "https://api.github.com/repos/" . $this->options['name'] . "/releases";
if ($this->cachedInfo->is()) { if ($this->cachedInfo->is()) {
$fileContent = $this->cachedInfo->get(); $fileContent = $this->cachedInfo->get();
} else { } else {
if (!in_array('https', stream_get_wrappers())) { if (!in_array('https', stream_get_wrappers())) {
if($this->options["exceptions"]){ if ($this->options["exceptions"]) {
throw new \Exception("No HTTPS Wrapper Exception"); throw new \Exception("No HTTPS Wrapper Exception");
} else { } else {
return array(); return array();
} }
} }
$fileContent = @file_get_contents($path, false, $this->streamContext); $fileContent = @file_get_contents($path, false, $this->streamContext);
if ($fileContent === false) { if ($fileContent === false) {
if($this->options["exceptions"]){ if ($this->options["exceptions"]) {
throw new \Exception("No Internet Exception"); throw new \Exception("No Internet Exception");
} else { } else {
return array(); return array();
} }
} }
$json = json_decode($fileContent, true); $json = json_decode($fileContent, true);
if (isset($json['message'])) { if (isset($json['message'])) {
if($this->options["exceptions"]){ if ($this->options["exceptions"]) {
throw new \Exception("API Exception[" . $json['message'] . "]"); throw new \Exception("API Exception[" . $json['message'] . "]");
} else { } else {
$json = array(); $json = array();
} }
}
if (defined("JSON_PRETTY_PRINT")) {
$fileContent = json_encode($json, JSON_PRETTY_PRINT);
} else {
$fileContent = json_encode($json);
} }
$fileContent = json_encode($json, JSON_PRETTY_PRINT);
$this->cachedInfo->set($fileContent); $this->cachedInfo->set($fileContent);
return $json; return $json;
@ -134,8 +138,8 @@ class HubUpdater
if (empty($this->allRelease)) { if (empty($this->allRelease)) {
return false; return false;
} }
$this->getNewestInfo(); $this->getNewestInfo();
if (HelperClass::fileExists($this->options['cache'] . $this->options['versionFile'])) { if (HelperClass::fileExists($this->options['cache'] . $this->options['versionFile'])) {
$fileContent = file_get_contents($this->options['cache'] . $this->options['versionFile']); $fileContent = file_get_contents($this->options['cache'] . $this->options['versionFile']);
@ -154,15 +158,22 @@ class HubUpdater
public function update() public function update()
{ {
$newestRelease = $this->getNewestInfo(); $newestRelease = $this->getNewestInfo();
if ($this->able()) { if ($this->able()) {
if ($this->download($newestRelease['zipball_url'])) { if ($this->download($newestRelease['zipball_url'])) {
if ($this->unZip()) { if ($this->unZip()) {
unlink($this->options['cache'] . $this->options['zipFile']); unlink($this->options['cache'] . $this->options['zipFile']);
file_put_contents($this->options['cache'] . $this->options['versionFile'], json_encode(array( if (defined("JSON_PRETTY_PRINT")) {
"id" => $newestRelease['id'], file_put_contents($this->options['cache'] . $this->options['versionFile'], json_encode(array(
"tag_name" => $newestRelease['tag_name'] "id" => $newestRelease['id'],
), JSON_PRETTY_PRINT)); "tag_name" => $newestRelease['tag_name']
), JSON_PRETTY_PRINT));
} else {
file_put_contents($this->options['cache'] . $this->options['versionFile'], json_encode(array(
"id" => $newestRelease['id'],
"tag_name" => $newestRelease['tag_name']
)));
}
return true; return true;
} }
@ -176,11 +187,11 @@ class HubUpdater
{ {
$file = @fopen($url, 'r', false, $this->streamContext2); $file = @fopen($url, 'r', false, $this->streamContext2);
if ($file == false) { if ($file == false) {
if($this->options["exceptions"]){ if ($this->options["exceptions"]) {
throw new \Exception("Download faild Exception"); throw new \Exception("Download faild Exception");
} else { } else {
return false; return false;
} }
} }
file_put_contents( file_put_contents(
dirname($_SERVER['SCRIPT_FILENAME']) . "/" . $this->options['cache'] . $this->options['zipFile'], dirname($_SERVER['SCRIPT_FILENAME']) . "/" . $this->options['cache'] . $this->options['zipFile'],
@ -197,7 +208,7 @@ class HubUpdater
$updateIgnore = array(); $updateIgnore = array();
if (HelperClass::fileExists($this->options['updateignore'])) { if (HelperClass::fileExists($this->options['updateignore'])) {
$updateIgnore = file($this->options['updateignore']); $updateIgnore = file($this->options['updateignore']);
foreach($updateIgnore as &$ignore) { foreach ($updateIgnore as &$ignore) {
$ignore = $this->options['save'] . trim($ignore); $ignore = $this->options['save'] . trim($ignore);
} }
} }
@ -207,16 +218,16 @@ class HubUpdater
$cutLength = strlen($zip->getNameIndex(0)); $cutLength = strlen($zip->getNameIndex(0));
for ($i = 1; $i < $zip->numFiles; $i++) {//iterate throw the Zip for ($i = 1; $i < $zip->numFiles; $i++) {//iterate throw the Zip
$name = $this->options['save'] . substr($zip->getNameIndex($i), $cutLength); $name = $this->options['save'] . substr($zip->getNameIndex($i), $cutLength);
$do = true; $do = true;
foreach($updateIgnore as $ignore) { foreach ($updateIgnore as $ignore) {
if (substr($name, 0, strlen($ignore)) == $ignore) { if (substr($name, 0, strlen($ignore)) == $ignore) {
$do = false; $do = false;
break; break;
} }
} }
if ($do) { if ($do) {
$stat = $zip->statIndex($i); $stat = $zip->statIndex($i);
if ($stat["crc"] == 0) { if ($stat["crc"] == 0) {
@ -235,38 +246,38 @@ class HubUpdater
return false; return false;
} }
} }
public function getCurrentInfo()
{
if(isset($this->currentInfo)) {
return $this->currentInfo;
}
$this->currentInfo = null;
if (HelperClass::fileExists($this->options['cache'] . $this->options['versionFile'])) {
$fileContent = file_get_contents($this->options['cache'] . $this->options['versionFile']);
$current = json_decode($fileContent, true);
foreach ($this->allRelease as $release) { public function getCurrentInfo()
if (isset($current['id']) && $current['id'] == $release['id']) { {
$this->currentInfo = $release; if (isset($this->currentInfo)) {
break; return $this->currentInfo;
} }
if (isset($current['tag_name']) && $current['tag_name'] == $release['tag_name']) {
$this->currentInfo = $release; $this->currentInfo = null;
break; if (HelperClass::fileExists($this->options['cache'] . $this->options['versionFile'])) {
} $fileContent = file_get_contents($this->options['cache'] . $this->options['versionFile']);
} $current = json_decode($fileContent, true);
}
return $this->currentInfo; foreach ($this->allRelease as $release) {
} if (isset($current['id']) && $current['id'] == $release['id']) {
$this->currentInfo = $release;
public function getNewestInfo() break;
{ }
if(isset($this->newestInfo)) { if (isset($current['tag_name']) && $current['tag_name'] == $release['tag_name']) {
return $this->newestInfo; $this->currentInfo = $release;
} break;
}
}
}
return $this->currentInfo;
}
public function getNewestInfo()
{
if (isset($this->newestInfo)) {
return $this->newestInfo;
}
foreach ($this->allRelease as $release) { foreach ($this->allRelease as $release) {
if (!$this->options['prerelease'] && $release['prerelease']) { if (!$this->options['prerelease'] && $release['prerelease']) {
continue; continue;
@ -277,6 +288,6 @@ class HubUpdater
$this->newestInfo = $release; $this->newestInfo = $release;
break; break;
} }
return $this->newestInfo; return $this->newestInfo;
} }
} }