public function execute($fonction = 'shell_exec')
{
+
$startTime = microtime(true);
$this->_preExecute();
if ($fonction instanceof SSH2) {
$this->makeCommande();
+ if (function_exists('start_measure')) {
+ start_measure('Exec CLI : ' . $this->commande);
+ }
$o = $fonction->exec($this->commande);
+ if (function_exists('stop_measure')) {
+ stop_measure('Exec CLI : ' . $this->commande);
+ }
file_put_contents($this->output, $o['output'] . "\n\n---\n\n" . $o['error']);
} else if (null === $this->ssh) {
$this->makeCommande($this->output, $this->error);
+ if (function_exists('start_measure')) {
+ start_measure('Exec CLI : ' . $this->commande);
+ }
$fonction($this->commande);
+ if (function_exists('stop_measure')) {
+ stop_measure('Exec CLI : ' . $this->commande);
+ }
} else {
$this->makeCommande();
}
$this->commande = $c;
-
+ if (function_exists('start_measure')) {
+ start_measure('Exec CLI : ' . $this->commande);
+ }
$fonction($c);
+ if (function_exists('stop_measure')) {
+ stop_measure('Exec CLI : ' . $this->commande);
+ }
}
$endTime = microtime(true);
$this->execTime = $endTime - $startTime;
$commande = $this->program;
$commandes = array();
foreach ($this->args as $arg) {
- if (strlen($arg[0]) == 1) {
+ if (null === $arg[0]) {
+ $commande .= ' ' . $arg[1];
+ } else if (strlen($arg[0]) == 1) {
$commande .= ' -' . $arg[0];
if (null !== $arg[1]) {
$commande .= ' ' . $arg[1];
}
- } elseif (null === $arg[0]) {
- $commande .= ' ' . $arg[1];
} else {
if (substr($arg[0], 0, 1) == '-') {
$commande .= ' ' . $arg[0];
* @param array $exclude
* @return array|\RecursiveIteratorIterator
*/
- public static function getRecursiveDirectoryIterator($path, $mode = \RecursiveIteratorIterator::SELF_FIRST, $exclude = array())
+ public static function getRecursiveDirectoryIterator($path, $mode = \RecursiveIteratorIterator::SELF_FIRST, $exclude = [])
{
$path = realpath($path);
if (!file_exists($path)) {
- return array();
+ return [];
+ }
+ return new \RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, $exclude), $mode);
+ }
+
+ public static function listFilesOfDirectory($path, &$res = [])
+ {
+ $files = scandir($path);
+
+ foreach ($files as $key => $value) {
+ $path = realpath($path . DIRECTORY_SEPARATOR . $value);
+ if (!is_dir($path)) {
+ $res[] = $path;
+ } else if ($value != "." && $value != "..") {
+ static::listFilesOfDirectory($path, $res);
+ $res[] = $path;
+ }
}
- $res = new \RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, $exclude), $mode);
+
return $res;
+
}
/**
Files::mkdir($from);
}
}
- $this->_directories[$this->path($to)] = $from;
+ $to = $this->path($to);
+ $this->_directories[$to] = $from;
return $this;
}
Files::mkdir($dir);
}
-
foreach ($this->_copy as $to => $from) {
-
if ($delete) {
$existing[$to] = true;
}
if (!$this->compare($from, $to)) {
$to_esc = escapeshellarg($to);
$from_esc = escapeshellarg($from);
- `cp -p $from_esc $to_esc`;
- $this->log('Copy file ' . $to);
+ $cpcmd = "cp -p $from_esc $to_esc";
+ `$cpcmd`;
+ $this->log('Copy file ' . $to . ' : ' . $cpcmd);
if (!file_exists($to)) {
$this->throwError(sprintf('Failed to copy %s to %s', $from, $to));
}
protected function _addDirectory($from, $to)
{
$from = realpath($from);
- $files = Files::getRecursiveDirectoryIterator($from);
+ Files::listFilesOfDirectory($from, $files);
- foreach ($files as $file) {
- /* @var $file SplFileInfo */
- if ($file->isDir()) {
- continue;
- }
- $path = $file->getRealPath();
+
+ if (!count($files)) {
+ dddd(`ls -l $from`);
+ }
+
+ $relativeTo = $this->relativePath($to);
+
+ $total = 0;
+ $parsed = 0;
+
+ foreach ($files as $path) {
+ $total++;
$dest = str_replace($from, '', $path);
if (!$path) {
+ $this->log('Skip file ' . $path . ' because no real path');
continue;
}
- $this->copy($path, $this->relativePath($to) . '/' . ltrim($dest, '/'), true);
+ $this->copy($path, $relativeTo . '/' . ltrim($dest, '/'), true);
+ $parsed++;
}
+
+ $this->log('parsed directory ' . $from . ' (' . $to . ') (' . $parsed . '/' . $total . ')');
}
protected function _delete($existing = array())
<?php
namespace Cubist\Util;
-use MicrodataDOM\DOMDocument;
+
+use DOMDocument;
+use DOMNode;
class Html
{
return $dom;
}
+ protected static function _getTextNode(DOMNode $domNode): array
+ {
+ $res = [];
+ foreach ($domNode->childNodes as $node) {
+ if ($node instanceof \DOMText) {
+ $res[] = $node->nodeValue;
+ }
+ if ($node->hasChildNodes()) {
+ $res = array_merge($res, static::_getTextNode($node));
+ }
+ }
+ return $res;
+ }
+
+ public static function getTextNodes($string)
+ {
+ if (!$string) {
+ return [];
+ }
+ try {
+ $doc = new DOMDocument('1.0', 'utf-8');
+ $doc->loadHTML($string);
+
+ $res= static::_getTextNode($doc);
+ return $res;
+ } catch (\Exception $e) {
+ return [$string];
+ }
+ }
+
}