本文整理汇总了PHP中OS类的典型用法代码示例。如果您正苦于以下问题:PHP OS类的具体用法?PHP OS怎么用?PHP OS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRevisionAuthor
function getRevisionAuthor($rev)
{
$xmlLines = OS::executeAndReturnOutput("svn log -c {$rev} --xml");
$xmlString = implode('', $xmlLines);
$xml = simplexml_load_string($xmlString);
return (string) $xml->logentry->author;
}
示例2: update
public function update()
{
if (isset($this->config['build'])) {
OS::run('cd ' . OS::bashize($this->directory) . ';git pull');
$this->readConfig();
}
}
示例3: db_executeSqlFile
function db_executeSqlFile($filename)
{
$dsn = Config::get('global.database');
$parts = db_splitDsn($dsn);
$command = sprintf("cat {$filename} | mysql -u %s %s %s", $parts['user'], $parts['database'], $parts['password'] ? "-p" . $parts['password'] : '');
OS::executeAndAssert($command);
}
示例4: parseArguments
function parseArguments()
{
global $argv;
$verbose = false;
$fileName = FILE_NAME;
for ($i = 1; $i < count($argv); $i++) {
$arg = $argv[$i];
if ($arg == "-v") {
$verbose = true;
} else {
if ($arg == '-f') {
$i++;
$fileName = $argv[$i];
} else {
if ($arg == '-t') {
runTestSuite();
exit;
} else {
OS::errorAndExit("Unknown flag: {$arg}");
}
}
}
}
return array($verbose, $fileName);
}
示例5: run
public function run(array $arguments)
{
foreach ($arguments as $dep) {
echo "* Removing {$dep}...\n";
$dir = $this->deps->getPackageDirectory($dep);
OS::run("rm -rf {$dir}");
}
return true;
}
示例6: closeCurrentFile
function closeCurrentFile()
{
global $g_numFiles;
global $g_curFileName;
global $g_curFile;
fprintf($g_curFile, "</urlset>\n");
fclose($g_curFile);
OS::executeAndAssert("gzip - < {$g_curFileName} > wwwbase/sitemap{$g_numFiles}.xml.gz");
util_deleteFile($g_curFileName);
}
示例7: bold
public static function bold($message)
{
if (!OS::isWindows()) {
echo "[1m";
}
echo $message;
if (!OS::isWindows()) {
echo "[m";
}
}
示例8: GetWotdFromSubject
function GetWotdFromSubject($subject)
{
$parts = preg_split("/\\s+/", trim($subject));
if (count($parts) != 2) {
OS::errorAndExit("Ignoring message '{$subject}' due to invalid subject", 0);
}
if ($parts[0] != Config::get('WotD.password')) {
OS::errorAndExit("Ignoring message '{$subject}' due to invalid password in the subject", 0);
}
return $parts[1];
}
示例9: get_grid_cell
/** @return lat_lng_bound */
public function get_grid_cell()
{
/** @var lat_lng_bound $cell */
foreach (OS::cells() as $cell) {
if ($cell->contains($this)) {
return $cell;
}
}
$bound = new \stdClass();
$bound->code = 'N/A';
return $bound;
}
示例10: ensureThumbnail
public function ensureThumbnail()
{
if (!$this->image) {
return;
}
$fullImage = self::$IMAGE_DIR . "/{$this->image}";
$fullThumb = self::$THUMB_DIR . "/{$this->image}";
if (!file_exists($fullThumb) && file_exists($fullImage)) {
$oldumask = umask(0);
@mkdir(dirname($fullThumb), 0777, true);
umask($oldumask);
OS::executeAndAssert(sprintf("convert -strip -geometry %dx%d -sharpen 1x1 '%s' '%s'", self::$THUMB_SIZE, self::$THUMB_SIZE, $fullImage, $fullThumb));
}
}
示例11: recursiveScan
function recursiveScan($path, $logFile)
{
global $IGNORED_DIRS, $EXTENSIONS, $beforeBytes, $afterBytes;
$files = scandir($path);
foreach ($files as $file) {
if (in_array($file, $IGNORED_DIRS)) {
continue;
}
$full = "{$path}/{$file}";
if (is_dir($full)) {
recursiveScan($full, $logFile);
} else {
$extension = pathinfo(strtolower($full), PATHINFO_EXTENSION);
$fullNoExt = substr($full, 0, strlen($full) - strlen($extension) - 1);
// Strip the dot as well
if (in_array($extension, $EXTENSIONS)) {
OS::executeAndAssert("convert -strip '{$full}' '" . Config::get('global.tempDir') . "/fileNoExif.{$extension}'");
OS::executeAndAssert("convert '" . Config::get('global.tempDir') . "/fileNoExif.{$extension}' '/fileNoExifPng.png'");
OS::executeAndAssert("optipng '" . Config::get('global.tempDir') . "/fileNoExifPng.png'");
$fs1 = filesize($full);
$fs2 = filesize(Config::get('global.tempDir') . "/fileNoExif.{$extension}");
$fs3 = filesize(Config::get('global.tempDir') . '/fileNoExifPng.png');
$beforeBytes += $fs1;
if ($fs3 < $fs1 && $fs3 < $fs2) {
$compression = 100.0 * (1 - $fs3 / $fs1);
$afterBytes += $fs3;
fprintf($logFile, "%s -- Strip EXIF, convert to PNG and optimize: %d/%d bytes, %.2f%% saved\n", $full, $fs3, $fs1, $compression);
unlink($full);
unlink(Config::get('global.tempDir') . "/fileNoExif.{$extension}");
rename(Config::get('global.tempDir') . '/fileNoExifPng.png', "{$fullNoExt}.png");
} else {
if ($fs2 < $fs1) {
$compression = 100.0 * (1 - $fs2 / $fs1);
$afterBytes += $fs2;
fprintf($logFile, "%s -- Strip EXIF: %d/%d bytes, %.2f%% saved\n", $full, $fs2, $fs1, $compression);
unlink($full);
rename(Config::get('global.tempDir') . "/fileNoExif.{$extension}", $full);
unlink(Config::get('global.tempDir') . '/fileNoExifPng.png');
} else {
$afterBytes += $fs1;
fprintf($logFile, "{$full} -- leave unchanged\n");
unlink(Config::get('global.tempDir') . "/fileNoExif.{$extension}");
unlink(Config::get('global.tempDir') . '/fileNoExifPng.png');
}
}
}
}
}
}
示例12: createThumb
function createThumb()
{
$url = Config::get('static.url') . self::STATIC_DIR . $this->path;
$ext = pathinfo($url, PATHINFO_EXTENSION);
$localFile = "/tmp/a.{$ext}";
$localThumbFile = "/tmp/thumb.{$ext}";
$contents = file_get_contents($url);
file_put_contents($localFile, $contents);
$command = sprintf("convert -strip -geometry %sx%s -sharpen 1x1 '%s' '%s'", self::THUMB_SIZE, self::THUMB_SIZE, $localFile, $localThumbFile);
OS::executeAndAssert($command);
$f = new FtpUtil();
$f->staticServerPut($localThumbFile, self::STATIC_THUMB_DIR . $this->path);
unlink($localFile);
unlink($localThumbFile);
}
示例13: run
public function run(array $arguments)
{
$json = $this->deps->nearestJson();
$linkDir = dirname($json);
$package = new Package(dirname($json));
$name = $package->getName();
if (!$name) {
echo "Error: no name for package\n";
} else {
echo "* Linking package {$name} to {$linkDir}...\n";
$dir = $this->deps->getPackageDirectory($package->getName());
if (is_dir($dir)) {
OS::run("rm -rf {$dir}");
}
OS::run("ln -s {$linkDir} {$dir}");
}
}
示例14: run
public function run(array $arguments)
{
$json = $this->deps->nearestJson();
$linkDir = dirname($json);
$package = new Package(dirname($json));
$name = $package->getName();
if (!$name) {
echo "Error: no name for package\n";
} else {
echo "Do you want to create symlink from {$name} to {$linkDir}? (yes/no)\n";
$l = readline();
if (trim($l) == 'yes') {
echo "* Linking package {$name} to {$linkDir}...\n";
$dir = $this->deps->getPackageDirectory($package->getName());
if (is_dir($dir)) {
OS::run("rm -rf {$dir}");
}
OS::run("ln -s {$linkDir} {$dir}");
} else {
echo "Aborting.\n";
}
}
}
示例15: deleteContents
/**
* deleteContents of a folder recursively, but not the folder itself.
*
* On Windows systems this will try to remove the read-only attribute if needed.
*
* @param string $path Path of folder whose contents will be deleted
*
* @throws \RuntimeException Thrown when something could not be deleted.
*/
public static function deleteContents($path)
{
if (!is_dir($path)) {
return;
}
/** @var \SplFileInfo[] $files */
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $fileInfo) {
if ($fileInfo->isDir()) {
if (@rmdir($fileInfo->getRealPath()) === false) {
throw new \RuntimeException(sprintf("Unable to delete child folder '%s' in '%s': %s", $fileInfo->getFilename(), $fileInfo->getPathname(), error_get_last()['message']));
}
} elseif (@unlink($fileInfo->getRealPath()) === false) {
if (OS::isWindows()) {
Exec::create('attrib', '-R', $fileInfo->getRealPath())->run();
if (@unlink($fileInfo->getPathname())) {
continue;
}
}
throw new \RuntimeException(sprintf("Unable to delete file '%s' in folder '%s': %s", $fileInfo->getFilename(), $fileInfo->getPathname(), error_get_last()['message']));
}
}
}