Example #1
0
 /**
  * Does a command exist?
  *
  * @param string $command Command line
  *
  * @return boolean
  */
 public static function is($command)
 {
     $result = trim(shell_exec("which {$command}"));
     return !TextHelper::isEmpty($result);
 }
Example #2
0
 * @category XML
 * @package  XmlQuery
 * @author   Gonzalo Chumillas <*****@*****.**>
 * @license  https://raw.github.com/soloproyectos/core/master/LICENSE BSD 2-Clause License
 * @link     https://github.com/soloproyectos/core
 */
use com\soloproyectos\common\sys\file\SysFileHelper;
use com\soloproyectos\common\text\TextHelper;
require_once __DIR__ . "/sys/file/sys-file-helper.php";
require_once __DIR__ . "/text/text-helper.php";
spl_autoload_register(function ($classname) {
    if (preg_match_all("/[A-Z][a-z,0-9]*/", $classname, $matches)) {
        // script filename
        $dir = __DIR__;
        $name = "";
        $items = $matches[0];
        foreach ($items as $item) {
            $item = strtolower($item);
            $d = SysFileHelper::concat($dir, $item);
            if (is_dir($d)) {
                $dir = $d;
            }
            $name = TextHelper::concat("-", $name, $item);
        }
        $filename = SysFileHelper::concat($dir, "{$name}.php");
        if (!is_file($filename)) {
            throw new Exception("Script not found: {$filename}");
        }
        include_once $filename;
    }
});
 /**
  * Sets inner HTML code.
  *
  * @param string $value Inner HTML code
  *
  * @return DomNode
  */
 private function _setInnerHtml($value)
 {
     $this->clear();
     if (!TextHelper::isEmpty($value)) {
         foreach ($this->elements() as $element) {
             $doc = $element->ownerDocument;
             $fragment = $doc->createDocumentFragment();
             @$fragment->appendXML($value);
             $node = @$element->appendChild($fragment);
             if ($node === false) {
                 throw new DomNodeException("Invalid XML fragment");
             }
         }
     }
     return $this;
 }
Example #4
0
 /**
  * Gets the string representation of the instance.
  *
  * @return string
  */
 public function toString()
 {
     $ret = $this->_name ? "-" . SysCmdHelper::escape($this->_name) : null;
     if (!TextHelper::isEmpty($this->_value)) {
         $value = $this->_value;
         if (!$this->_isRaw) {
             $value = SysCmdHelper::escape($value);
         }
         $ret = TextHelper::concat(" ", $ret, $value);
     }
     return $ret;
 }
Example #5
0
 /**
  * Gets an available name under a given directory.
  *
  * This function returns an available name under a given directory. For
  * example, if there's a file named 'test.txt' under de directory 'dir1', the
  * following command returns 'test_1.txt':
  *
  * ```php
  * // prints 'test_1.txt' if the name 'test.txt' is taken:
  * echo SysFile::getAvailName('dir1', 'test1.txt');
  * ```
  *
  * @param string $dir     Directory
  * @param string $refname Filename used as reference (default is "")
  * @param string $refext  Extension used as reference (default is "")
  *
  * @return string
  */
 public static function getAvailName($dir, $refname = "", $refext = "")
 {
     // fixes arguments
     $dir = trim($dir);
     $refname = trim($refname);
     $refext = ltrim(trim($refext), ".");
     if (!is_dir($dir)) {
         throw new SysException("Directory not found: {$dir}");
     }
     // default refname
     if (TextHelper::isEmpty($refname)) {
         $refname = "file";
     }
     // gets name and extension
     $refname = basename($refname);
     $pos = strrpos($refname, ".");
     $name = $refname;
     $ext = $refext;
     if ($pos !== false) {
         $name = substr($refname, 0, $pos);
         if (TextHelper::isEmpty($refext)) {
             $ext = substr($refname, $pos + 1);
         }
     }
     // gets an available name
     for ($i = 0; $i < 100; $i++) {
         $basename = $i > 0 ? TextHelper::concat(".", $name . "_" . $i, $ext) : TextHelper::concat(".", $name, $ext);
         $filename = SysFileHelper::concat($dir, $basename);
         if (!is_file($filename)) {
             break;
         }
     }
     return $filename;
 }
Example #6
0
 /**
  * Gets a string representation of the node.
  *
  * @return string
  */
 public function __toString()
 {
     $ret = "";
     foreach ($this->elements as $element) {
         $ret = TextHelper::concat("\n", $ret, DomHelper::dom2str($element));
     }
     return $ret;
 }