Skip to content

Commit

Permalink
- Remove dependencies methods, not needed for newer ZF versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Galperin committed May 30, 2016
1 parent 1afe23e commit 2ff4d74
Showing 1 changed file with 12 additions and 70 deletions.
82 changes: 12 additions & 70 deletions library/Zdm.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@ class Zdm {
'repository' => 'https://raw.githubusercontent.com/zendframework/zf1/release-',
'method' => self::CURL
);

protected $_dependencies = array(
'Zend/Layout.php' => array('Zend/Filter/Word','Zend/Filter/StringToLower.php'),
'Zend/View.php' => 'Zend/View',
'Zend/Controller/Action.php' => 'Zend/Controller/Action/Helper'
);

protected $_errors = array();

const CURL = 1;
const FILE_GET_CONTENTS = 2;

/**
* Initialize and register autoloader instance
* @param array $config
Expand Down Expand Up @@ -95,7 +88,9 @@ public function fetch($file) {
$local = $this -> _config['libraryPath'] . DIRECTORY_SEPARATOR . $file;
$target = $this -> _config['repository'] . $this -> _config['zfVersion'] . '/library/' . $file;
$data = $this -> _remoteFetch($target);
var_dump($data);
if($data === false) {
return false;
}
if(!is_dir(dirname($local))) {
mkdir(dirname($local),0755,true);
}
Expand All @@ -105,11 +100,11 @@ public function fetch($file) {
$offset = $pos + 10;
}
file_put_contents($local, $data);
$this -> fetchDependencies($file);

}

/**
* Select method to fetch remote file by configuration
* Fetch remote file by configuration method
* @param string $url
* @return string
*/
Expand All @@ -123,68 +118,15 @@ protected function _remoteFetch($url) {
CURLOPT_SSL_VERIFYPEER => false
);
curl_setopt_array($curl, $options);
$contents = curl_exec($curl);
$response = curl_exec($curl);
$status = curl_getinfo($curl,CURLINFO_HTTP_CODE);
curl_close($curl);
return $contents;
if(!in_array($status,array(200,301,302))) {
throw new Exception('File was not found in ' . $url);
}
return $response;
} else {
return file_get_contents($url);
}
}
/**
* Fetch a directory of Zend Framework classes from repository
* @param string $dir
*/
public function fetchDir($dir) {
$localDir = $this -> _config['libraryPath'] . DIRECTORY_SEPARATOR . $dir;
if(!is_dir($localDir)) {
mkdir($localDir,0755,true);
}
$target = $this -> _config['repository'] . $this -> _config['zfVersion'] . '/library/' . $dir;

//Local directory fetch
if(is_dir($target)) {
foreach(glob($target . DIRECTORY_SEPARATOR . '*.*') as $file) {
$base = $dir . DIRECTORY_SEPARATOR . basename($file);
if(is_dir($file)) {
$this -> fetchDir($base);
} else {
$this -> fetch($base);
}
}
//Zend Framework repo fetch
} else {
$result = file_get_contents($target);
$tree = new DOMDocument();
$tree -> loadHTML($result);
$xpath = new DOMXPath($tree);
$result = $xpath -> query('//ul/li/a');
foreach($result as $node) {
$file = $node -> getAttribute('href');
if(strpos($file,'.php') === false) {
if($file != '../') {
$this -> fetchDir($dir .'/' . $file);
}
} else {
$this ->fetch($dir . '/' . $file);
}
}
}
}

/**
* Fetch dependencies for file
* @param string $file
*/
public function fetchDependencies($file) {
if(array_key_exists($file, $this -> _dependencies)) {
$deps = (array)$this -> _dependencies[$file];
foreach($deps as $dep) {
if(stripos($dep,'.php') === false) {
$this -> fetchDir($dep);
} else {
$this -> fetch($dep);
}
}
}
}
}

0 comments on commit 2ff4d74

Please sign in to comment.