本文整理汇总了PHP中FileHandler::system方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHandler::system方法的具体用法?PHP FileHandler::system怎么用?PHP FileHandler::system使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHandler
的用法示例。
在下文中一共展示了FileHandler::system方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install
/**
* Installs a packagist package
*
* @param string $package_name
* @param string|boolean $version_param
* @param boolean-
*
* @return boolean
*/
public static function install($package_name, $version_param = false, $die_on_duplicate = true)
{
$package_info = json_decode(file_get_contents(self::URL . "/{$package_name}.json"), true);
if (!isset($package_info['status'])) {
//has package already been added to the app's packagist file
$exists = isset(self::$_packages[$package_name]) ? self::$_packages[$package_name] : false;
//check for matching version either new or existing ugradable
$to_install = self::match($package_info, $version_param);
if ($to_install === false && $exists !== true && $exists !== false) {
$to_install = self::match($package_info, $exists);
}
if ($to_install !== false) {
echo "Downloading {$package_name} " . $to_install["version"] . "\n";
//download requires
if (isset($to_install["require"])) {
foreach ($to_install["require"] as $rpackage => $version) {
if ($rpackage == "php") {
$php_vmatch = [];
preg_match('/([\\>\\=]+)\\s*([0-9\\.]+)/', $version, $php_vmatch);
if (version_compare(phpversion(), $php_vmatch[2], $php_vmatch[1]) == false) {
die("PHP version {$version} required");
}
} elseif (strpos($rpackage, '/') !== false) {
self::install($rpackage, $version, false);
}
}
}
//get directory names and create if not existing yet
$name = $to_install["source"]["url"];
$name = substr($name, strlen('https://github.com/'));
$name = str_replace('/', '-', substr($name, 0, strrpos($name, '.')));
$id = substr($to_install["dist"]["reference"], 0, 7);
$package_directory = App::libs()->directory('Packagist.' . strtolower($name));
$package_sub = $package_directory->directory("{$name}-{$id}");
if ($package_sub->exists()) {
if ($die_on_duplicate) {
die("Package version already installed\n");
} else {
echo "Package version already installed\n";
return false;
}
}
if (!$package_directory->exists()) {
$package_directory->create();
}
//download file
$package_zip = (string) FileHandler::system('package.zip');
$fp = fopen($package_zip, 'w');
$ch = curl_init($to_install["dist"]["url"]);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_exec($ch);
curl_close($ch);
fclose($fp);
//extract package.zip
$zip = new \ZipArchive();
$zip->open($package_zip);
$zip->extractTo($package_directory);
//remove zip
unlink($package_zip);
//add .exclude file
$package_sub->file(".exclude")->write('');
//get existing installed version
$prev_versions = $package_directory->directories();
//remove any existing key from autoload
$prev_version_found = false;
foreach ($prev_versions as $prev_version) {
$prev_version_name = $prev_version->name();
if ($prev_version_name !== "{$name}-{$id}" && isset(self::$_autoload[$prev_version_name])) {
$prev_version_found = $prev_version_name;
unset(self::$_autoload[$prev_version_name]);
}
}
//let the user know the previous version has been removed from autoload
if ($prev_version_found !== false) {
echo "A previously installed version was detected and removed from the autoload.json in favor of the new version. The package files still exist in Libs/Packagist/{$name}/{$prev_version_found}\n";
}
//add autoload
$classmap = [];
if (isset($to_install['autoload'])) {
// go through autoload
foreach ($to_install['autoload'] as $spec => $mapping) {
if ($spec == 'classmap') {
// loop through the files and fetch the fully qualified classnames
// through regex
foreach ($mapping as $file) {
// can also be directory
$d = $package_sub->directory($file);
$f = $package_sub->file($file, substr_count($file, '.'));
//.........这里部分代码省略.........