endsWith() public method

public endsWith ( string $str ) : boolean
$str string
return boolean
Beispiel #1
0
 /**
  * Prefix to apply to properties loaded using <code>file</code>.
  * A "." is appended to the prefix if not specified.
  * @param string $prefix prefix string
  * @return void
  * @since 2.0
  */
 function setPrefix($prefix)
 {
     $this->prefix = $prefix;
     if (!StringHelper::endsWith(".", $prefix)) {
         $this->prefix .= ".";
     }
 }
 function main($_sourceFileName)
 {
     if ($this->fromPrefix === null || !StringHelper::startsWith($this->fromPrefix, $_sourceFileName) || !StringHelper::endsWith($this->fromPostfix, $_sourceFileName)) {
         return null;
     }
     $varpart = $this->_extractVariablePart($_sourceFileName);
     $substitution = $this->toPrefix . $varpart . $this->toPostfix;
     return array($substitution);
 }
    /**
     * The name of the file, or the pattern for the name, that
     * should be used for selection.
     *
     * @param pattern the file pattern that any filename must match
     *                against in order to be selected.
     */
    public function setName($pattern) {
        $pattern = str_replace('\\', DIRECTORY_SEPARATOR, $pattern);
        $pattern = str_replace('/', DIRECTORY_SEPARATOR, $pattern);

        if (StringHelper::endsWith(DIRECTORY_SEPARATOR, $pattern)) {
            $pattern .= "**";
        }
        $this->pattern = $pattern;
    }
Beispiel #4
0
 public static function MaskCheck($item, $masks)
 {
     $maskCheck = false;
     foreach ($masks as $mask) {
         if (\StringHelper::startsWith($item, $mask) || \StringHelper::endsWith($item, $mask)) {
             $maskCheck = true;
         }
     }
     return $maskCheck;
 }
Beispiel #5
0
 function templateFileName($templateName)
 {
     if ($templateName != null) {
         if (!StringHelper::endsWith($templateName, '.html')) {
             $templateName .= '.html';
         }
         return $templateName;
     }
     $rc = new ReflectionObject($this);
     $filename = $rc->getName() . '.html';
     return $filename;
 }
Beispiel #6
0
 function normalizeSlashes($path)
 {
     // Url must not end with slash
     while (StringHelper::endsWith($path, '/')) {
         $path = substr($path, 0, -1);
     }
     // Url must start with slash
     if (!StringHelper::startsWith($path, '/')) {
         $path = '/' . $path;
     }
     return $path;
 }
 function evaluate()
 {
     $osName = strtolower(Phing::getProperty("os.name"));
     if ($this->family !== null) {
         if ($this->family === "windows") {
             return StringHelper::startsWith("win", $osName);
         } elseif ($this->family === "mac") {
             return strpos($osName, "mac") !== false || strpos($osName, "darwin") !== false;
         } elseif ($this->family === "unix") {
             return StringHelper::endsWith("ix", $osName) || StringHelper::endsWith("ux", $osName) || StringHelper::endsWith("bsd", $osName) || StringHelper::startsWith("sunos", $osName) || StringHelper::startsWith("darwin", $osName);
         }
         throw new BuildException("Don't know how to detect os family '" . $this->family . "'");
     }
     return false;
 }
Beispiel #8
0
 /**
  * Return files in a folder by type
  * @param $folderPath
  * @param $type
  * @param $removeExtension
  */
 public static function listFilesByType($folderPath, $type, $removeExtension = false) {
     $results = null;
     if (is_dir($folderPath)) {
         $results = array();
         if ($handle = opendir($folderPath)) {
             while (($file = readdir($handle)) !== false) {
                 if (StringHelper::endsWith($file, $type)) {
                     if ($removeExtension) {
                         $results[] = substr($file, 0, strlen($file) - 4);
                     } else {
                         $results[] = $file;
                     }
                 }
             }
             closedir($handle);
         }
     }
     return $results;
 }
Beispiel #9
0
 /**
  * do the work
  * @throws BuildException if required attributes are not supplied
  *                        property and attribute are required attributes
  */
 public function main()
 {
     if ($this->property === null) {
         throw new BuildException("property attribute required", $this->getLocation());
     }
     if ($this->file == null) {
         throw new BuildException("file attribute required", $this->getLocation());
     }
     $value = $this->file->getName();
     if ($this->suffix != null && StringHelper::endsWith($this->suffix, $value)) {
         // if the suffix does not starts with a '.' and the
         // char preceding the suffix is a '.', we assume the user
         // wants to remove the '.' as well
         $pos = strlen($value) - strlen($this->suffix) - 1;
         if ($pos > 0 && $this->suffix[0] !== '.' && $value[$pos] === '.') {
             $pos--;
         }
         $value = StringHelper::substring($value, 0, $pos);
     }
     $this->getProject()->setNewProperty($this->property, $value);
 }
 /**
  * Returns entire SQL source
  *
  * @return string|null
  */
 public function nextQuery()
 {
     $sql = null;
     while (($line = $this->sqlReader->readLine()) !== null) {
         $delimiter = $this->parent->getDelimiter();
         $project = $this->parent->getOwningTarget()->getProject();
         $line = ProjectConfigurator::replaceProperties($project, trim($line), $project->getProperties());
         if ($line != $delimiter && (StringHelper::startsWith("//", $line) || StringHelper::startsWith("--", $line) || StringHelper::startsWith("#", $line))) {
             continue;
         }
         $sql .= " " . $line . "\n";
         /**
          * fix issue with PDO and wrong formated multistatements
          * @issue 1108
          */
         if (StringHelper::endsWith($delimiter, $line)) {
             break;
         }
     }
     return $sql;
 }
Beispiel #11
0
 /**
  *
  * Enter description here ...
  * @param  PhingFile|string $path
  * @param  boolean          $isDirectory
  * @return string
  */
 public function _slashify($path, $isDirectory)
 {
     $p = (string) $path;
     if (self::$separator !== '/') {
         $p = str_replace(self::$separator, '/', $p);
     }
     if (!StringHelper::startsWith('/', $p)) {
         $p = '/' . $p;
     }
     if (!StringHelper::endsWith('/', $p) && $isDirectory) {
         $p = $p . '/';
     }
     return $p;
 }
Beispiel #12
0
 function fromURIPath($p)
 {
     if (StringHelper::endsWith("/", $p) && strlen($p) > 1) {
         // "/foo/" --> "/foo", but "/" --> "/"
         $p = substr($p, 0, strlen($p) - 1);
     }
     return $p;
 }
 /**
  * read in lines and execute them
  * @param Reader $reader
  * @param null $out
  * @throws BuildException
  */
 public function runStatements(Reader $reader, $out = null)
 {
     $sql = "";
     $line = "";
     $buffer = '';
     if (is_array($this->filterChains) && !empty($this->filterChains)) {
         $in = FileUtils::getChainedReader(new BufferedReader($reader), $this->filterChains, $this->getProject());
         while (-1 !== ($read = $in->read())) {
             // -1 indicates EOF
             $buffer .= $read;
         }
         $lines = explode("\n", $buffer);
     } else {
         $in = new BufferedReader($reader);
         while (($line = $in->readLine()) !== null) {
             $lines[] = $line;
         }
     }
     try {
         foreach ($lines as $line) {
             $line = trim($line);
             $line = ProjectConfigurator::replaceProperties($this->project, $line, $this->project->getProperties());
             if (StringHelper::startsWith("//", $line) || StringHelper::startsWith("--", $line) || StringHelper::startsWith("#", $line)) {
                 continue;
             }
             if (strlen($line) > 4 && strtoupper(substr($line, 0, 4)) == "REM ") {
                 continue;
             }
             $sql .= " " . $line;
             $sql = trim($sql);
             // SQL defines "--" as a comment to EOL
             // and in Oracle it may contain a hint
             // so we cannot just remove it, instead we must end it
             if (strpos($line, "--") !== false) {
                 $sql .= "\n";
             }
             if ($this->delimiterType == self::DELIM_NORMAL && StringHelper::endsWith($this->delimiter, $sql) || $this->delimiterType == self::DELIM_ROW && $line == $this->delimiter) {
                 $this->log("SQL: " . $sql, Project::MSG_VERBOSE);
                 $this->execSQL(StringHelper::substring($sql, 0, strlen($sql) - strlen($this->delimiter)), $out);
                 $sql = "";
             }
         }
         // Catch any statements not followed by ;
         if ($sql !== "") {
             $this->execSQL($sql, $out);
         }
     } catch (SQLException $e) {
         throw new BuildException("Error running statements", $e);
     }
 }
Beispiel #14
0
 /**
  * Evaluates expression and returns resulting value.
  * @return mixed
  */
 protected function evalExpression()
 {
     $this->log("Evaluating PHP expression: " . $this->expression);
     if (!StringHelper::endsWith(';', trim($this->expression))) {
         $this->expression .= ';';
     }
     $retval = null;
     eval('$retval = ' . $this->expression);
     return $retval;
 }
Beispiel #15
0
 public static function throwableMessage(&$msg, $error, $verbose)
 {
     while ($error instanceof BuildException) {
         $cause = $error->getCause();
         if ($cause === null) {
             break;
         }
         $msg1 = (string) $error;
         $msg2 = (string) $cause;
         if (StringHelper::endsWith($msg2, $msg1)) {
             $msg .= StringHelper::substring($msg1, 0, strlen($msg1) - strlen($msg2));
             $error = $cause;
         } else {
             break;
         }
     }
     if ($verbose || !$error instanceof BuildException) {
         $msg .= (string) $error;
     } else {
         $msg .= $error->getMessage() . PHP_EOL;
     }
 }
Beispiel #16
0
<?php

$handler = opendir(dirname(__FILE__));
while ($file = readdir($handler)) {
    if ($file != "." && $file != "..") {
        if (StringHelper::endsWith($file, ".php")) {
            require_once dirname(__FILE__) . "/" . $file;
        }
    }
}
 /**
  * read in lines and execute them
  * @throws SQLException, IOException 
  */
 public function runStatements(Reader $reader, $out = null)
 {
     $sql = "";
     $line = "";
     $in = new BufferedReader($reader);
     try {
         while (($line = $in->readLine()) !== null) {
             $line = trim($line);
             $line = ProjectConfigurator::replaceProperties($this->project, $line, $this->project->getProperties());
             if (StringHelper::startsWith("//", $line) || StringHelper::startsWith("--", $line) || StringHelper::startsWith("#", $line)) {
                 continue;
             }
             if (strlen($line) > 4 && strtoupper(substr($line, 0, 4)) == "REM ") {
                 continue;
             }
             $sql .= " " . $line;
             $sql = trim($sql);
             // SQL defines "--" as a comment to EOL
             // and in Oracle it may contain a hint
             // so we cannot just remove it, instead we must end it
             if (strpos($line, "--") !== false) {
                 $sql .= "\n";
             }
             if ($this->delimiterType == self::DELIM_NORMAL && StringHelper::endsWith($this->delimiter, $sql) || $this->delimiterType == self::DELIM_ROW && $line == $this->delimiter) {
                 $this->log("SQL: " . $sql, PROJECT_MSG_VERBOSE);
                 $this->execSQL(StringHelper::substring($sql, 0, strlen($sql) - strlen($this->delimiter) - 1), $out);
                 $sql = "";
             }
         }
         // Catch any statements not followed by ;
         if ($sql !== "") {
             $this->execSQL($sql, $out);
         }
     } catch (SQLException $e) {
         throw new BuildException("Error running statements", $e);
     }
 }
 /**
  * Evaluates expression and returns resulting value.
  * @return mixed
  */
 protected function evalExpression()
 {
     $this->log("Evaluating PHP expression: " . $this->expression);
     if (!StringHelper::endsWith(';', trim($this->expression))) {
         $this->expression .= ';';
     }
     if ($this->returnProperty !== null) {
         $retval = null;
         eval('$retval = ' . $this->expression);
         $this->project->setProperty($this->returnProperty, $retval);
     } else {
         eval($this->expression);
     }
 }
 function fromURIPath($strPath)
 {
     $p = (string) $strPath;
     if (strlen($p) > 2 && $p[2] === ':') {
         // "/c:/foo" --> "c:/foo"
         $p = substr($p, 1);
         // "c:/foo/" --> "c:/foo", but "c:/" --> "c:/"
         if (strlen($p) > 3 && StringHelper::endsWith('/', $p)) {
             $p = substr($p, 0, strlen($p) - 1);
         }
     } elseif (strlen($p) > 1 && StringHelper::endsWith('/', $p)) {
         // "/foo/" --> "/foo"
         $p = substr($p, 0, strlen($p) - 1);
     }
     return (string) $p;
 }
Beispiel #20
0
 /**
  * Returns the applications host address.
  *
  * @return StringHelper
  */
 public static function getHostUri()
 {
     $sheme = self::getHostParam("HTTPS") == "on" ? "https" : "http";
     $serverName = new StringHelper(self::getHostParam("HTTP_HOST"));
     $serverPort = self::getHostParam("SERVER_PORT");
     $serverPort = $serverPort != 80 && $serverPort != 443 ? ":" . $serverPort : "";
     if ($serverName->endsWith($serverPort)) {
         $serverName = $serverName->replace($serverPort, "");
     }
     return new StringHelper($sheme . "://" . $serverName . $serverPort);
 }
Beispiel #21
0
 /**
  * Sets the set of exclude patterns to use. All '/' and '\' characters are
  * replaced by <code>File.separatorChar</code>. So the separator used need
  * not match <code>File.separatorChar</code>.
  *
  * When a pattern ends with a '/' or '\', "**" is appended.
  *
  * @param array $_excludes
  * @internal param list $excludes of exclude patterns
  */
 public function setExcludes($_excludes = array())
 {
     if (empty($_excludes) || is_null($_excludes)) {
         $this->excludes = null;
     } else {
         for ($i = 0; $i < count($_excludes); $i++) {
             $pattern = null;
             $pattern = str_replace('\\', DIRECTORY_SEPARATOR, $_excludes[$i]);
             $pattern = str_replace('/', DIRECTORY_SEPARATOR, $pattern);
             if (StringHelper::endsWith(DIRECTORY_SEPARATOR, $pattern)) {
                 $pattern .= "**";
             }
             $this->excludes[] = $pattern;
         }
     }
 }
Beispiel #22
0
 /**
  * Execute the input script with Velocity
  *
  * @throws BuildException
  *                        BuildExceptions are thrown when required attributes are missing.
  *                        Exceptions thrown by Velocity are rethrown as BuildExceptions.
  */
 public function main()
 {
     // Make sure the template path is set.
     if (empty($this->templatePath)) {
         throw new BuildException("The template path needs to be defined!");
     }
     // Make sure the control template is set.
     if ($this->controlTemplate === null) {
         throw new BuildException("The control template needs to be defined!");
     }
     // Make sure the output directory is set.
     if ($this->outputDirectory === null) {
         throw new BuildException("The output directory needs to be defined!");
     }
     // Make sure there is an output file.
     if ($this->outputFile === null) {
         throw new BuildException("The output file needs to be defined!");
     }
     // Setup Smarty runtime.
     // Smarty uses one object to store properties and to store
     // the context for the template (unlike Velocity).  We setup this object, calling it
     // $this->context, and then initControlContext simply zeros out
     // any assigned variables.
     //
     // Use the smarty backwards compatibility layer if existent.
     if (class_exists('SmartyBC')) {
         $this->context = new SmartyBC();
     } else {
         $this->context = new Smarty();
     }
     if ($this->compilePath !== null) {
         $this->log("Using compilePath: " . $this->compilePath);
         $this->context->compile_dir = $this->compilePath;
     }
     if ($this->configPath !== null) {
         $this->log("Using configPath: " . $this->configPath);
         $this->context->config_dir = $this->configPath;
     }
     if ($this->forceCompile !== null) {
         $this->context->force_compile = $this->forceCompile;
     }
     if ($this->leftDelimiter !== null) {
         $this->context->left_delimiter = $this->leftDelimiter;
     }
     if ($this->rightDelimiter !== null) {
         $this->context->right_delimiter = $this->rightDelimiter;
     }
     if ($this->templatePath !== null) {
         $this->log("Using templatePath: " . $this->templatePath);
         $this->context->template_dir = $this->templatePath;
     }
     $smartyCompilePath = new PhingFile($this->context->compile_dir);
     if (!$smartyCompilePath->exists()) {
         $this->log("Compile directory does not exist, creating: " . $smartyCompilePath->getPath(), Project::MSG_VERBOSE);
         if (!$smartyCompilePath->mkdirs()) {
             throw new BuildException("Smarty needs a place to compile templates; specify a 'compilePath' or create " . $this->context->compile_dir);
         }
     }
     // Make sure the output directory exists, if it doesn't
     // then create it.
     $file = new PhingFile($this->outputDirectory);
     if (!$file->exists()) {
         $this->log("Output directory does not exist, creating: " . $file->getAbsolutePath());
         $file->mkdirs();
     }
     $path = $this->outputDirectory . DIRECTORY_SEPARATOR . $this->outputFile;
     $this->log("Generating to file " . $path);
     $writer = new FileWriter($path);
     // The generator and the output path should
     // be placed in the init context here and
     // not in the generator class itself.
     $c = $this->initControlContext();
     // Set any variables that need to always
     // be loaded
     $this->populateInitialContext($c);
     // Feed all the options into the initial
     // control context so they are available
     // in the control/worker templates.
     if ($this->contextProperties !== null) {
         foreach ($this->contextProperties->keys() as $property) {
             $value = $this->contextProperties->getProperty($property);
             // Special exception (from Texen)
             // for properties ending in file.contents:
             // in that case we dump the contents of the file
             // as the "value" for the Property.
             if (StringHelper::endsWith("file.contents", $property)) {
                 // pull in contents of file specified
                 $property = substr($property, 0, strpos($property, "file.contents") - 1);
                 // reset value, and then
                 // read in teh contents of the file into that var
                 $value = "";
                 $f = new PhingFile($this->project->resolveFile($value)->getCanonicalPath());
                 if ($f->exists()) {
                     try {
                         $fr = new FileReader($f);
                         $fr->readInto($value);
                     } catch (Exception $e) {
                         throw $e;
                     }
                 }
             }
             // if ends with file.contents
             if (StringHelper::isBoolean($value)) {
                 $value = StringHelper::booleanValue($value);
             }
             $c->assign($property, $value);
         }
         // foreach property
     }
     // if contextProperties !== null
     try {
         //$c->display($this->controlTemplate);
         $writer->write($c->fetch($this->controlTemplate));
         $writer->close();
     } catch (IOException $ioe) {
         $writer->close();
         throw new BuildException("Cannot write parsed template.");
     }
     $this->cleanup();
 }