CodeSniffer initial steps
This commit is contained in:
@ -26,8 +26,8 @@ class CommandBackup extends Command
|
||||
$output->writeln('Opening: '.$input->getArgument('config'));
|
||||
try {
|
||||
$config = Yaml::parseFile($input->getArgument('config'));
|
||||
} catch (ParseException $exception) {
|
||||
$output->writeln('Unable to parse the YAML string: '. $exception->getMessage());
|
||||
} catch (ParseException $e) {
|
||||
$output->writeln('Unable to parse the YAML string: '. $e->getMessage());
|
||||
}
|
||||
|
||||
$rclone = new Rclone\Rclone();
|
||||
@ -38,8 +38,7 @@ class CommandBackup extends Command
|
||||
$twig = new \Twig\Environment($loader);
|
||||
$twig->addExtension(new Twig\AppExtension());
|
||||
|
||||
foreach($config['backup'] as $conf)
|
||||
{
|
||||
foreach ($config['backup'] as $conf) {
|
||||
try {
|
||||
$template['config'] = $conf;
|
||||
$template['start'] = new \DateTime();
|
||||
|
@ -25,8 +25,8 @@ class CommandShow extends Command
|
||||
$output->writeln('Reading from: '.$input->getArgument('config'));
|
||||
try {
|
||||
$config = Yaml::parseFile($input->getArgument('config'));
|
||||
} catch (ParseException $exception) {
|
||||
$output->writeln('Unable to parse the YAML string: '. $exception->getMessage());
|
||||
} catch (ParseException $e) {
|
||||
$output->writeln('Unable to parse the YAML string: '. $e->getMessage());
|
||||
}
|
||||
$table = new Table($output);
|
||||
$table
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
namespace App\Ntfy;
|
||||
|
||||
class Ntfy {
|
||||
private $domain;
|
||||
class Ntfy
|
||||
{
|
||||
protected $domain;
|
||||
function __construct($domain)
|
||||
{
|
||||
$this->domain = $domain;
|
||||
@ -10,16 +11,18 @@ class Ntfy {
|
||||
|
||||
function send($topic,$title, $message)
|
||||
{
|
||||
file_get_contents('https://'.$this->domain.'/'.$topic, false, stream_context_create([
|
||||
'http' => [
|
||||
file_get_contents(
|
||||
'https://'.$this->domain.'/'.$topic, false, stream_context_create(
|
||||
['http' => [
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-Type: text/plain',
|
||||
'header' =>
|
||||
"Content-Type: text/plain\r\n" .
|
||||
"Title: $title\r\n",
|
||||
'content' => $message
|
||||
]
|
||||
]));
|
||||
'content' => $message]
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -4,9 +4,10 @@ namespace App\Rclone;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
|
||||
class Rclone {
|
||||
private $rclone_path;
|
||||
private $global_options = [];
|
||||
class Rclone
|
||||
{
|
||||
protected $rclone_path;
|
||||
protected $global_options = [];
|
||||
|
||||
function __construct($rclone_path = "rclone")
|
||||
{
|
||||
@ -31,8 +32,7 @@ class Rclone {
|
||||
|
||||
$options[] = $src;
|
||||
$options[] = $dest;
|
||||
if($bandwidth)
|
||||
{
|
||||
if ($bandwidth) {
|
||||
$options[] = "--bwlimit";
|
||||
$options[] = $bandwidth;
|
||||
}
|
||||
@ -40,9 +40,16 @@ class Rclone {
|
||||
return $this->exec('copy', $options);
|
||||
}
|
||||
|
||||
private function exec(string $command, array $options = array())
|
||||
protected function exec(string $command, array $options = array())
|
||||
{
|
||||
$process = new Process(array_merge([$this->rclone_path], $this->global_options, [$command], $options));
|
||||
$process = new Process(
|
||||
array_merge(
|
||||
[$this->rclone_path],
|
||||
$this->global_options,
|
||||
[$command],
|
||||
$options
|
||||
)
|
||||
);
|
||||
$process->setTimeout(4*3600);
|
||||
$process->run();
|
||||
|
||||
|
@ -16,15 +16,16 @@ class AppExtension extends AbstractExtension
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bytes
|
||||
* @param int $precision
|
||||
* @return string
|
||||
* Format a file size to be human readable
|
||||
* @param int $bytes Number of bytes
|
||||
* @param int $precision Precision
|
||||
* @return string Formatted string
|
||||
*/
|
||||
public function formatBytes($bytes, $precision = 2)
|
||||
{
|
||||
$size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
|
||||
$factor = floor((strlen($bytes) - 1) / 3);
|
||||
return sprintf("%.{$precision}f", $bytes / pow(1024, $factor)) . @$size[$factor];
|
||||
$fact = floor((strlen($bytes) - 1) / 3);
|
||||
return sprintf("%.{$precision}f", $bytes / pow(1024, $fact)) . $size[$fact];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user