How to use trim method of StringUtils class

Best Gherkin-php code snippet using StringUtils.trim

StringUtils.php

Source:StringUtils.php Github

copy

Full Screen

...35 * programming.36 *37 * Instead, the class should be used as:38 * /---code php39 * StringUtils::trim(' foo ');40 * \---41 */42 protected function __construct()43 {44 }45 // @codeCoverageIgnoreEnd46 /**47 * Returns the character at the specified index.48 *49 * An index ranges from `0` to `StringUtils::length() - 1`. The first50 * character of the sequence is at index `0`, the next at index `1`, and so51 * on, as for array indexing.52 *53 * @param string $str The `string` to return the character from.54 * @param integer $index The index of the character.55 *56 * @return string The character at the specified index of the `string`.57 * The first character is at index `0`.58 * @throws OutOfBoundsException If the $index argument is negative or not59 * less than the length of the `string`.60 */61 public static function charAt($str, $index)62 {63 if (false === substr($str, $index, 1)) {64 throw new \OutOfBoundsException;65 }66 return substr($str, $index, 1);67 }68 /**69 * Removes one newline from end of a string if it's there, otherwise leave70 * it alone.71 *72 * A newline is "`\n`", "`\r`", or "`\r\n`".73 *74 * /---code php75 * StringUtils::chomp(null); // null76 * StringUtils::chomp(''); // ''77 * StringUtils::chomp("abc \r"); // 'abc '78 * StringUtils::chomp("abc\n"); // 'abc'79 * StringUtils::chomp("abc\r\n"); // 'abc'80 * StringUtils::chomp("abc\r\n\r\n"); // "abc\r\n"81 * StringUtils::chomp("abc\n\r"); // "abc\n"82 * StringUtils::chomp("abc\n\rabc"); // "abc\n\rabc"83 * StringUtils::chomp("\r"); // ''84 * StringUtils::chomp("\n"); // ''85 * StringUtils::chomp("\r\n"); // ''86 * \---87 *88 * @param string $str The `string` to chomp a newline from.89 *90 * @return string The `string` $str without newline, `null` if `null`91 * `string` input.92 */93 public static function chomp($str)94 {95 if (true === self::isEmpty($str)) {96 return $str;97 }98 if (1 === self::length($str)) {99 $firstChar = self::charAt($str, 0);100 if ("\r" === $firstChar || "\n" === $firstChar) {101 return self::EMPTY_STR;102 }103 return $str;104 }105 $lastIndex = self::length($str) - 1;106 $lastChar = self::charAt($str, $lastIndex);107 if ("\n" === $lastChar) {108 if ("\r" === self::charAt($str, $lastIndex - 1)) {109 --$lastIndex;110 }111 } elseif ("\r" !== $lastChar) {112 ++$lastIndex;113 }114 return self::substring($str, 0, $lastIndex);115 }116 /**117 * Remove the specified last character from a `string`.118 *119 * If the `string` ends in `\r\n`, then remove both of them.120 *121 * /---code php122 * StringUtils::chop(null); // null123 * StringUtils::chop(''); // ''124 * StringUtils::chop("abc \r"); // 'abc '125 * StringUtils::chop("abc\n"); // 'abc'126 * StringUtils::chop("abc\r\n"); // 'abc'127 * StringUtils::chop('abc'); // 'ab'128 * StringUtils::chop("abc\nabc"); // "abc\nab"129 * StringUtils::chop('a'); // ''130 * StringUtils::chop("\r"); // ''131 * StringUtils::chop("\n"); // ''132 * StringUtils::chop("\r\n"); // ''133 * \---134 *135 * @param string $str The `string` to chop the last character from.136 *137 * @return string|null The `string` without the last character; `null` if138 * `null` `string` input.139 */140 public static function chop($str)141 {142 $result = self::EMPTY_STR;143 if (true === self::isEmpty($str)) {144 $result = $str;145 } elseif ("\r\n" === \substr($str, -2)) {146 $result = \substr($str, 0, -2);147 } else {148 $result = \substr($str, 0, -1);149 }150 return $result;151 }152 /**153 * Checks if a `string` is whitespace, empty (`''`) or `null`.154 *155 * /---code php156 * StringUtils::isBlank(null); // true157 * StringUtils::isBlank(''); // true158 * StringUtils::isBlank(' '); // true159 * StringUtils::isBlank('bob'); // false160 * StringUtils::isBlank(' bob '); // false161 * \---162 *163 * @param string $str The `string` to check.164 *165 * @return boolean `true` if the `string` is `null`, empty or whitespace;166 * `false` otherwise.167 */168 public static function isBlank($str)169 {170 return self::EMPTY_STR === \trim($str);171 }172 /**173 * Checks if a `string` is not empty (`''`), not `null` and not whitespace174 * only.175 *176 * /---code php177 * StringUtils::isNotBlank(null); // false178 * StringUtils::isNotBlank(''); // false179 * StringUtils::isNotBlank(' '); // false180 * StringUtils::isNotBlank('bob'); // true181 * StringUtils::isNotBlank(' bob '); // true182 * \---183 *184 * @param string $str The `string` to check.185 *186 * @return boolean `true` if the `string` is not empty and not `null` and187 * not whitespace; `false` otherwise.188 */189 public static function isNotBlank($str)190 {191 return false === self::isBlank($str);192 }193 /**194 * Checks if a `string` is empty (`''`) or `null`.195 *196 * /---code php197 * StringUtils::isEmpty(null); // true198 * StringUtils::isEmpty(''); // true199 * StringUtils::isEmpty(' '); // false200 * StringUtils::isEmpty('bob'); // false201 * StringUtils::isEmpty(' bob '); // false202 * \---203 *204 * @param string $str The `string` to check.205 *206 * @return boolean `true` if the `string` is empty or `null`, `false`207 * otherwise.208 */209 public static function isEmpty($str)210 {211 return (self::EMPTY_STR === $str) || (null === $str);212 }213 /**214 * Checks if a `string` is not empty (`''`) and not `null`.215 *216 * /---code php217 * StringUtils::isNotEmpty(null); // false218 * StringUtils::isNotEmpty(''); // false219 * StringUtils::isNotEmpty(' '); // true220 * StringUtils::isNotEmpty('bob'); // true221 * StringUtils::isNotEmpty(' bob '); // true222 * \---223 *224 * @param string $str The `string` to check.225 *226 * @return boolean `true` if the `string` is not empty or `null`, `false`227 * otherwise.228 */229 public static function isNotEmpty($str)230 {231 return false === self::isEmpty($str);232 }233 /**234 * Returns the length of a `string` or `0` if the `string` is `null`.235 *236 * @param string $str The `string` to check.237 *238 * @return integer The length of the `string` or `0` if the `string` is239 * `null`.240 */241 public static function length($str)242 {243 return \strlen($str);244 }245 /**246 * Converts a `string` to lower case.247 *248 * A `null` input `string` returns `null`.249 *250 * /---code php251 * StringUtils::lowerCase(null) = null252 * StringUtils::lowerCase('') = ''253 * StringUtils::lowerCase('aBc') = 'abc'254 * \---255 *256 * @param string $str The `string` to lower case.257 *258 * @return string The lower cased `string` or `null` if `null` `string`259 * input.260 */261 public static function lowerCase($str)262 {263 return (true === self::isEmpty($str))264 ? $str265 : strtolower($str);266 }267 /**268 * Converts a `string` to upper case.269 *270 * A `null` input `string` returns `null`.271 *272 * /---code php273 * StringUtils::upperCase(null) = null274 * StringUtils::upperCase('') = ''275 * StringUtils::upperCase('aBc') = 'ABC'276 * \---277 *278 * @param string $str The `string` to upper case.279 *280 * @return string The upper cased `string` or `null` if `null` `string`281 * input.282 */283 public static function upperCase($str)284 {285 return (true === self::isEmpty($str))286 ? $str287 : strtoupper($str);288 }289 /**290 * Replaces a `string` with another `string` inside a larger `string`, for291 * the first maximum number of values to replace of the search `string`.292 *293 * /---code php294 * StringUtils::replace(null, *, *, *) // null295 * StringUtils::replace('', *, *, *) // ''296 * StringUtils::replace('any', null, *, *) // 'any'297 * StringUtils::replace('any', *, null, *) // 'any'298 * StringUtils::replace('any', '', *, *) // 'any'299 * StringUtils::replace('any', *, *, 0) // 'any'300 * StringUtils::replace('abaa', 'a', null, -1) // 'abaa'301 * StringUtils::replace('abaa', 'a', '', -1) // 'b'302 * StringUtils::replace('abaa', 'a', 'z', 0) // 'abaa'303 * StringUtils::replace('abaa', 'a', 'z', 1) // 'zbaa'304 * StringUtils::replace('abaa', 'a', 'z', 2) // 'zbza'305 * StringUtils::replace('abaa', 'a', 'z', -1) // 'zbzz'306 * \---307 *308 * @param string $text The `string` to search and replace in.309 * @param string $search The `string` to search for.310 * @param string $replace The `string` to replace $search with.311 * @param integer $max The maximum number of values to replace, or `-1`312 * if no maximum.313 *314 * @return string The text with any replacements processed or `null` if315 * `null` `string` input.316 */317 public static function replace($text, $search, $replace, $max = -1)318 {319 if ((true === self::isEmpty($text))320 || (true === self::isEmpty($search))321 || (null === $replace)322 || (0 === $max)323 ) {324 return $text;325 }326 return \preg_replace(327 '/' . \preg_quote($search) . '/',328 $replace,329 $text,330 $max331 );332 }333 /* -------------------------------------------------------------------------334 * Trim335 * ---------------------------------------------------------------------- */336 /**337 * Removes control characters (char <= 32) from both ends of a `string`,338 * handling `null` by returning `null`.339 *340 * This method removes start and end characters <= 32. To strip341 * whitespace use {@see strip}.342 *343 * To trim your choice of characters, use the {@see strip} method.344 *345 * /---code php346 * StringUtils::trim(null); // null347 * StringUtils::trim(''); // ''348 * StringUtils::trim(' '); // ''349 * StringUtils::trim('abc'); // 'abc'350 * StringUtils::trim(' abc '); // 'abc'351 * \---352 *353 * @param string $str The `string` to be trimmed.354 *355 * @return string The trimmed `string` or `null` if `null` `string` input.356 */357 public static function trim($str)358 {359 return (true === self::isEmpty($str))360 ? $str361 : self::trimToEmpty($str);362 }363 /**364 * Removes control characters (char <= 32) from both ends of a `string`365 * returning an empty `string` (`''`) if the `string` is empty (`''`) after366 * the trim or if it is `null`.367 *368 * This method removes start and end characters <= 32. To strip369 * whitespace use {@see stripToEmpty}.370 *371 * /---code php372 * StringUtils::trimToEmpty(null); // ''373 * StringUtils::trimToEmpty(''); // ''374 * StringUtils::trimToEmpty(' '); // ''375 * StringUtils::trimToEmpty('abc'); // 'abc'376 * StringUtils::trimToEmpty(' abc '); // 'abc'377 * \---378 *379 * @param string $str The `string` to be trimmed.380 *381 * @return string The trimmed `string` or an empty `string` if `null` input.382 */383 public static function trimToEmpty($str)384 {385 return \trim($str);386 }387 /**388 * Removes control characters (char <= 32) from both ends of a `string`389 * returning `null` if the `string` is empty (`''`) after the trim or if it390 * is `null`.391 *392 * This method removes start and end characters <= 32. To strip393 * whitespace use {@see stripToNull}.394 *395 * /---code php396 * StringUtils::trimToNull(null); // null397 * StringUtils::trimToNull(''); // null398 * StringUtils::trimToNull(' '); // null399 * StringUtils::trimToNull('abc'); // 'abc'400 * StringUtils::trimToNull(' abc '); // 'abc'401 * \---402 *403 * @param string $str The `string` to be trimmed.404 *405 * @return string|null The trimmed `string' or `null` if only chars406 * <= 32, empty or `null` `string` input.407 */408 public static function trimToNull($str)409 {410 $str = self::trimToEmpty($str);411 return (true === self::isEmpty($str))412 ? null413 : $str;414 }415 /* -------------------------------------------------------------------------416 * Strip417 * ---------------------------------------------------------------------- */418 /**419 * Strips any of a set of characters from the start and end of a `string`.420 *421 * This is similar to {@see trim} but allows the characters to be stripped422 * to be controlled.423 *424 * A `null` input `string` returns `null`.425 * An empty string (`''`) input returns the empty `string`.426 *427 * If the `string` for the characters to remove is `null`, whitespace is428 * stripped.429 *430 * /---code php431 * StringUtils::strip(null, *); // null432 * StringUtils::strip('', *); // ''433 * StringUtils::strip('abc', null); // 'abc'434 * StringUtils::strip(' abc', null); // 'abc'435 * StringUtils::strip('abc ', null); // 'abc'436 * StringUtils::strip(' abc ', null); // 'abc'437 * StringUtils::strip(' abcyx', 'xyz'); // ' abc'438 * \---439 *440 * @param string $str The `string` to remove characters from.441 * @param string $chars The characters to remove. `null` is treated as442 * whitespace.443 *444 * @return string|null The stripped `string` or `null` if `null` `string`445 * input.446 */447 public static function strip($str, $chars)448 {449 return (true === self::isEmpty($str))450 ? $str451 : self::stripEnd(self::stripStart($str, $chars), $chars);452 }453 /**454 * Strips whitespace from the start and end of a `string` returning an empty455 * `string` if `null` input.456 *457 * This is similar to {@see trimToEmpty} but removes whitespace.458 *459 * /---code php460 * StringUtils::stripToEmpty(null); // ''461 * StringUtils::stripToEmpty(''); // ''462 * StringUtils::stripToEmpty(' '); // ''463 * StringUtils::stripToEmpty('abc'); // 'abc'464 * StringUtils::stripToEmpty(' abc'); // 'abc'465 * StringUtils::stripToEmpty('abc '); // 'abc'466 * StringUtils::stripToEmpty(' abc '); // 'abc'467 * StringUtils::stripToEmpty(' ab c '); // 'ab c'468 * \---469 *470 * @param string $str The `string` to be stripped.471 *472 * @return string The stripped `string` or an empty `string` if `null`473 * input.474 */475 public static function stripToEmpty($str)476 {477 return (null === $str)478 ? self::EMPTY_STR479 : self::strip($str, null);480 }481 /**482 * Strips whitespace from the start and end of a `string` returning `null`483 * if the `string` is empty (`''`) after the strip.484 *485 * This is similar to {@see trimToNull} but removes whitespace.486 *487 * /---code php488 * StringUtils::stripToNull(null); // null489 * StringUtils::stripToNull(''); // null490 * StringUtils::stripToNull(' '); // null491 * StringUtils::stripToNull('abc'); // 'abc'492 * StringUtils::stripToNull(' abc'); // 'abc'493 * StringUtils::stripToNull('abc '); // 'abc'494 * StringUtils::stripToNull(' abc '); // 'abc'495 * StringUtils::stripToNull(' ab c '); // 'ab c'496 * \---497 *498 * @param string $str The `string` to be stripped.499 *500 * @return string|null The stripped `string` or `null` if whitespace, empty501 * or `null` `string` input.502 */503 public static function stripToNull($str)504 {505 $str = self::strip($str, null);506 return (0 === self::length($str))507 ? null508 : $str;509 }510 /**511 * Strips any of a set of characters from the start of a `string`.512 *513 * A `null` input `string` returns `null`.514 * An empty string (`''`) input returns the empty `string`.515 *516 * If the `string` for the characters to remove is `null`, whitespace is517 * stripped.518 *519 * /---code php520 * StringUtils::stripStart(null, *); // null521 * StringUtils::stripStart('', *); // ''522 * StringUtils::stripStart('abc', ''); // 'abc'523 * StringUtils::stripStart('abc', null); // 'abc'524 * StringUtils::stripStart(' abc', null); // 'abc'525 * StringUtils::stripStart('abc ', null); // 'abc '526 * StringUtils::stripStart(' abc ', null); // 'abc '527 * StringUtils::stripStart('yxabc ', 'xyz'); // 'abc '528 * \---529 *530 * @param string $str The `string` to remove characters from.531 * @param string $chars The characters to remove. `null` is treated as532 * whitespace.533 *534 * @return string|null The stripped `string` or `null` if `null` `string`535 * input.536 */537 public static function stripStart($str, $chars)538 {539 if (true === self::isEmpty($str)) {540 return $str;541 }542 return (null === $chars)543 ? \ltrim($str)544 : \ltrim($str, $chars);545 }546 /**547 * Strips any of a set of characters from the end of a `string`.548 *549 * A `null` input `string` returns `null`.550 * An empty string (`''`) input returns the empty `string`.551 *552 * If the `string` for the characters to remove is `null`, whitespace is553 * stripped.554 *555 * /---code php556 * StringUtils::stripEnd(null, *) = null557 * StringUtils::stripEnd('', *) = ''558 * StringUtils::stripEnd('abc', '') = 'abc'559 * StringUtils::stripEnd('abc', null) = 'abc'560 * StringUtils::stripEnd(' abc', null) = ' abc'561 * StringUtils::stripEnd('abc ', null) = 'abc'562 * StringUtils::stripEnd(' abc ', null) = ' abc'563 * StringUtils::stripEnd(' abcyx', 'xyz') = ' abc'564 * \---565 *566 * @param string $str The `string` to remove characters from.567 * @param string $chars The characters to remove. `null` is treated as568 * whitespace.569 *570 * @return string|null The stripped `string` or `null` if `null` `string`571 * input.572 */573 public static function stripEnd($str, $chars)574 {575 if (true === self::isEmpty($str)) {576 return $str;577 }578 return (null === $chars)579 ? \rtrim($str)580 : \rtrim($str, $chars);581 }582 /* -------------------------------------------------------------------------583 * Compare584 * ---------------------------------------------------------------------- */585 /**586 * Compares two `string`s lexicographically.587 *588 * The comparison is based on the Unicode value of each character in the589 * `string`s. The character sequence represented by the first `string` is590 * compared lexicographically to the character sequence represented by the591 * second `string`. The result is a negative integer if the first `string`592 * lexicographically precedes the second `string`. The result is a positive593 * integer if the first `string` lexicographically follows the second594 * `string`....

Full Screen

Full Screen

ProducteurManager.php

Source:ProducteurManager.php Github

copy

Full Screen

...294 $lLogger = &Log::singleton('file', CHEMIN_FICHIER_LOGS);295 $lLogger->setMask(Log::MAX(LOG_LEVEL));296 297 // Mise en forme des données298 $pVo->setNom(StringUtils::formaterNom(trim($pVo->getNom())));299 $pVo->setPrenom(StringUtils::formaterPrenom(trim($pVo->getPrenom())));300 $pVo->setCourrielPrincipal(trim($pVo->getCourrielPrincipal()));301 $pVo->setCourrielSecondaire(trim($pVo->getCourrielSecondaire()));302 $pVo->setTelephonePrincipal(trim($pVo->getTelephonePrincipal()));303 $pVo->setTelephoneSecondaire(trim($pVo->getTelephoneSecondaire()));304 $pVo->setAdresse(trim($pVo->getAdresse()));305 $pVo->setCodePostal(trim($pVo->getCodePostal()));306 $pVo->setVille(StringUtils::formaterVille(trim($pVo->getVille())));307 $pVo->setCommentaire(trim($pVo->getCommentaire()));308 309 // Protection des dates vides310 if($pVo->getDateNaissance() == '') {311 $pVo->setDateNaissance(StringUtils::FORMAT_DATE_NULLE);312 }313 if($pVo->getDateCreation() == '') {314 $pVo->setDateCreation(StringUtils::FORMAT_DATE_NULLE);315 }316 if($pVo->getDateMaj() == '') {317 $pVo->getDateMaj(StringUtils::FORMAT_DATE_NULLE);318 }319 320 $lRequete =321 "INSERT INTO " . ProducteurManager::TABLE_PRODUCTEUR . "322 (" . ProducteurManager::CHAMP_PRODUCTEUR_ID . "323 ," . ProducteurManager::CHAMP_PRODUCTEUR_ID_FERME . "324 ," . ProducteurManager::CHAMP_PRODUCTEUR_NUMERO . "325 ," . ProducteurManager::CHAMP_PRODUCTEUR_NOM . "326 ," . ProducteurManager::CHAMP_PRODUCTEUR_PRENOM . "327 ," . ProducteurManager::CHAMP_PRODUCTEUR_COURRIEL_PRINCIPAL . "328 ," . ProducteurManager::CHAMP_PRODUCTEUR_COURRIEL_SECONDAIRE . "329 ," . ProducteurManager::CHAMP_PRODUCTEUR_TELEPHONE_PRINCIPAL . "330 ," . ProducteurManager::CHAMP_PRODUCTEUR_TELEPHONE_SECONDAIRE . "331 ," . ProducteurManager::CHAMP_PRODUCTEUR_ADRESSE . "332 ," . ProducteurManager::CHAMP_PRODUCTEUR_CODE_POSTAL . "333 ," . ProducteurManager::CHAMP_PRODUCTEUR_VILLE . "334 ," . ProducteurManager::CHAMP_PRODUCTEUR_DATE_NAISSANCE . "335 ," . ProducteurManager::CHAMP_PRODUCTEUR_DATE_CREATION . "336 ," . ProducteurManager::CHAMP_PRODUCTEUR_DATE_MAJ . "337 ," . ProducteurManager::CHAMP_PRODUCTEUR_COMMENTAIRE . "338 ," . ProducteurManager::CHAMP_PRODUCTEUR_ETAT . ")339 VALUES (NULL340 ,'" . StringUtils::securiser( $pVo->getIdFerme() ) . "'341 ,'" . StringUtils::securiser( $pVo->getNumero() ) . "'342 ,'" . StringUtils::securiser( $pVo->getNom() ) . "'343 ,'" . StringUtils::securiser( $pVo->getPrenom() ) . "'344 ,'" . StringUtils::securiser( $pVo->getCourrielPrincipal() ) . "'345 ,'" . StringUtils::securiser( $pVo->getCourrielSecondaire() ) . "'346 ,'" . StringUtils::securiser( $pVo->getTelephonePrincipal() ) . "'347 ,'" . StringUtils::securiser( $pVo->getTelephoneSecondaire() ) . "'348 ,'" . StringUtils::securiser( $pVo->getAdresse() ) . "'349 ,'" . StringUtils::securiser( $pVo->getCodePostal() ) . "'350 ,'" . StringUtils::securiser( $pVo->getVille() ) . "'351 ,'" . StringUtils::securiser( $pVo->getDateNaissance() ) . "'352 ,'" . StringUtils::securiser( $pVo->getDateCreation() ) . "'353 ,'" . StringUtils::securiser( $pVo->getDateMaj() ) . "'354 ,'" . StringUtils::securiser( $pVo->getCommentaire() ) . "'355 ,'" . StringUtils::securiser( $pVo->getEtat() ) . "')";356 $lLogger->log("Execution de la requete : " . $lRequete,PEAR_LOG_DEBUG); // Maj des logs357 358 $lId = Dbutils::executerRequeteInsertRetourId($lRequete); // Execution de la requete et récupération de l'Id généré par la BDD359 $pVo->setId($lId);360 $pVo->setNumero('P' . $lId); // Mise à jour du numéro dans l'objet361 ProducteurManager::update($pVo); // Mise à jour de la base362 return $lId;363 }364 /**365 * @name update($pVo)366 * @param ProducteurVO367 * @desc Met à jour la ligne de la table, correspondant à l'id du ProducteurVO, avec les informations du ProducteurVO368 */369 public static function update($pVo) {370 // Initialisation du Logger371 $lLogger = &Log::singleton('file', CHEMIN_FICHIER_LOGS);372 $lLogger->setMask(Log::MAX(LOG_LEVEL));373 // Mise en forme des données374 $pVo->setNom(StringUtils::formaterNom(trim($pVo->getNom())));375 $pVo->setPrenom(StringUtils::formaterPrenom(trim($pVo->getPrenom())));376 $pVo->setCourrielPrincipal(trim($pVo->getCourrielPrincipal()));377 $pVo->setCourrielSecondaire(trim($pVo->getCourrielSecondaire()));378 $pVo->setTelephonePrincipal(trim($pVo->getTelephonePrincipal()));379 $pVo->setTelephoneSecondaire(trim($pVo->getTelephoneSecondaire()));380 $pVo->setAdresse(trim($pVo->getAdresse()));381 $pVo->setCodePostal(trim($pVo->getCodePostal()));382 $pVo->setVille(StringUtils::formaterVille(trim($pVo->getVille())));383 $pVo->setCommentaire(trim($pVo->getCommentaire()));384 385 // Protection des dates vides386 if($pVo->getDateNaissance() == '') {387 $pVo->setDateNaissance(StringUtils::FORMAT_DATE_NULLE);388 }389 if($pVo->getDateCreation() == '') {390 $pVo->setDateCreation(StringUtils::FORMAT_DATE_NULLE);391 }392 if($pVo->getDateMaj() == '') {393 $pVo->getDateMaj(StringUtils::FORMAT_DATE_NULLE);394 }395 396 $lRequete = 397 "UPDATE " . ProducteurManager::TABLE_PRODUCTEUR . "...

Full Screen

Full Screen

VagasUtils.php

Source:VagasUtils.php Github

copy

Full Screen

...50 }51 // Nome da empresa52 $divJobListingCompany = $li->find('.job_listing-company')[0];53 if ($divJobListingCompany) {54 $nomeEmpresa = StringUtils::getText(trim($divJobListingCompany->text));55 }56 // Tipo da vaga57 $divJType = $li->find('.jtype')[0];58 if ($divJType) {59 $tipoVaga = trim($divJType->text);60 $tipoVaga = ucfirst(strtolower($tipoVaga));61 }62 // Descrição - Mini texto da vaga63 $divDescription = $li->find('.ti')[1];64 if ($divDescription) {65 $miniTextoVaga = StringUtils::getText(trim($divDescription->text));66 }67 // Data da publicação68 $divDetails = $li->find('.details')[0];69 if ($divDetails) {70 $span = $divDetails->find('span')[0];71 if ($span) {72 $dataPublicacao = trim($span->text);73 }74 }75 $vaga = [76 'nomeVaga' => $nomeVaga,77 'urlVaga' => $urlVaga,78 'nomeEmpresa' => $nomeEmpresa,79 'tipoVaga' => $tipoVaga,80 'miniTextoVaga' => $miniTextoVaga,81 'dataPublicacao' => $dataPublicacao,82 'isRH' => FALSE,83 'origem' => 'Joinville Vagas',84 ];85 // Filtra as vagas de interesse86 $add = FALSE;87 if (in_array(strtolower($nomeVaga), $vagasInteresse)) {88 $add = TRUE;89 }90 if (!$add) {91 foreach ($vagasInteresse as $vg) {92 if (StringUtils::contains(strtolower($nomeVaga), $vg)) {93 $add = TRUE;94 break;95 }96 }97 }98 if ($isDev) {99 $add = TRUE;100 }101 if ($add) {102 array_push($data, $vaga);103 $adicionado = TRUE;104 } else {105 // Vagas de RH para a esposa do Gerson106 $isAnalista = StringUtils::contains(strtolower($nomeVaga), 'analista');107 $isVagaPossivel =108 StringUtils::contains(strtolower($nomeVaga), 'rh') ||109 StringUtils::contains(strtolower($nomeVaga), 'recursos') ||110 StringUtils::contains(strtolower($nomeVaga), 'recrutamento');111 if ($isAnalista && $isVagaPossivel) {112 $vaga['isRH'] = TRUE;113 array_push($data, $vaga);114 }115 }116 }117 }118 // Sine Joinville - https://www.sine.com.br/vagas-empregos-em-joinville-sc119 /*120 $urlSine = 'https://www.sine.com.br/vagas-empregos-em-joinville-sc';121 $client = new Client();122 $response = $client->request('GET', $urlSine, ['verify' => false]);123 $type = $response->getHeader('content-type');124 $parsed = Psr7\parse_header($type);125 $original_body = (string)$response->getBody();126 $utf8_body = mb_convert_encoding($original_body, 'UTF-8', $parsed[0]['charset'] ?: 'UTF-8');127 $html = $utf8_body; //(string) $response->getBody();128 $domCrawler = (new Dom)->load($html);129 $adicionado = FALSE;130 $divJobs = $domCrawler->find('.jobs')[0];131 if ($divJobs) {132 $divItem = $divJobs->find('.item');133 foreach ($divItem as $job) {134 if ($isDev && $adicionado) continue;135 $nomeVaga = '';136 $nomeEmpresa = 'Não informado';137 $tipoVaga = 'Efetivo'; // Efetivo, estágio..138 $miniTextoVaga = '';139 $dataPublicacao = 'Não informado';140 $urlVaga = '';141 $valorSalario = '';142 // URL da vaga143 $a = $job->find('a')[0];144 if ($a) {145 $urlVaga = 'https://www.sine.com.br' . $a->href;146 $nomeVaga = StringUtils::getText(trim($a->title));147 }148 // Valor do salário149 $p1 = $job->find('p')[0];150 if ($p1) {151 $span = $p1->find('span')[0];152 if ($span) {153 $txt = trim($span->text);154 if (StringUtils::startsWith($txt, 'R')) {155 $valorSalario = $txt;156 }157 }158 }159 // Descrição da vaga160 $idx = 1;161 if ($valorSalario != '') {162 $idx = 2;163 }164 $p2 = $job->find('p')[$idx];165 if ($p2) {166 if ($valorSalario != '') {167 $miniTextoVaga = 'Salário: ' . $valorSalario . '. ';168 }169 $tmp = trim(preg_replace("/\r\n|\r|\n/", '', $p2->text));170 $miniTextoVaga .= $tmp;171 StringUtils::getText($miniTextoVaga);172 }173 $vaga = [174 'nomeVaga' => $nomeVaga,175 'urlVaga' => $urlVaga,176 'nomeEmpresa' => $nomeEmpresa,177 'tipoVaga' => $tipoVaga,178 'miniTextoVaga' => $miniTextoVaga,179 'dataPublicacao' => $dataPublicacao,180 'isRH' => FALSE,181 'origem' => 'SINE Joinville',182 ];183 // Filtra as vagas de interesse184 $add = FALSE;185 if (in_array(strtolower($nomeVaga), $vagasInteresse)) {186 $add = TRUE;187 }188 if (!$add) {189 foreach ($vagasInteresse as $vg) {190 if (StringUtils::contains(strtolower($nomeVaga), $vg)) {191 $add = TRUE;192 break;193 }194 }195 }196 if ($isDev) {197 $add = TRUE;198 }199 if ($add) {200 array_push($data, $vaga);201 $adicionado = TRUE;202 } else {203 // Vagas de RH para a esposa do Gerson204 $isAnalista = StringUtils::contains(strtolower($nomeVaga), 'analista');205 $isVagaPossivel =206 StringUtils::contains(strtolower($nomeVaga), 'rh') ||207 StringUtils::contains(strtolower($nomeVaga), 'recursos') ||208 StringUtils::contains(strtolower($nomeVaga), 'recrutamento');209 if ($isAnalista && $isVagaPossivel) {210 $vaga['isRH'] = TRUE;211 array_push($data, $vaga);212 }213 }214 }215 }216 */217 // Indeed - https://www.indeed.com.br/empregos?q=&l=Joinville%2C+SC218 $urlIndeed = 'https://www.indeed.com.br/empregos?q=&l=Joinville%2C+SC';219 $urlB = 'https://www.indeed.com.br';220 $client = new Client();221 $response = $client->request('GET', $urlIndeed, ['verify' => false]);222 $type = $response->getHeader('content-type');223 $parsed = Psr7\parse_header($type);224 $original_body = (string)$response->getBody();225 $utf8_body = mb_convert_encoding($original_body, 'UTF-8', $parsed[0]['charset'] ?: 'UTF-8');226 $html = $utf8_body; //(string) $response->getBody();227 $domCrawler = (new Dom)->load($html);228 $adicionado = FALSE;229 $divJobs = $domCrawler->find('.row');230 foreach ($divJobs as $job) {231 $r = $job->getAttribute('class');232 if (!StringUtils::contains($r, 'result')) continue;233 if ($isDev && $adicionado) continue;234 $nomeVaga = '';235 $nomeEmpresa = 'Não informado';236 $tipoVaga = 'Efetivo'; // Efetivo, estágio..237 $miniTextoVaga = '';238 $dataPublicacao = 'Não informado';239 $urlVaga = '';240 $valorSalario = '';241 // Nome da vaga242 $h2JobTitle = $job->find('h2[class=jobtitle]')[0];243 if ($h2JobTitle) {244 $aEnd = $h2JobTitle->find('a')[0];245 if ($aEnd) {246 $nomeVaga = StringUtils::getText(ucfirst(strtolower(trim($aEnd->text))));247 // URL da vaga248 $urlVaga = $urlB . $aEnd->href;249 $urlTmp = $aEnd->href;250 $posCorte = strpos($urlTmp, '?');251 if ($posCorte !== FALSE) {252 $urlVaga = $urlB . substr($urlTmp, 0, $posCorte);253 }254 }255 } else {256 $jobtitle = $job->find('.jobtitle')[0];257 if ($jobtitle) {258 $nomeVaga = StringUtils::getText(ucfirst(strtolower(trim($jobtitle->text))));259 // URL da vaga260 $urlVaga = $urlB . $jobtitle->href;261 $urlTmp = $jobtitle->href;262 $posCorte = strpos($urlTmp, '?');263 if ($posCorte !== FALSE) {264 $urlVaga = $urlB . substr($urlTmp, 0, $posCorte);265 }266 }267 }268 // Nome da empresa269 $spanCompany = $job->find('span[class=company]')[0];270 if ($spanCompany) {271 $aComp = $spanCompany->find('a')[0];272 if ($aComp) {273 $nomeEmpresa = StringUtils::getText(ucfirst(strtolower(trim($aComp->text))));274 } else {275 $nomeEmpresa = StringUtils::getText(ucfirst(strtolower(trim($spanCompany->text))));276 }277 }278 // Valor do salário279 $spanNoWrap = $job->find('.no-wrap')[0];280 if ($spanNoWrap) {281 $valorSalario = trim($spanNoWrap->text);282 }283 // Descrição da vaga284 $spanSummary = $job->find('.summary')[0];285 if ($spanSummary) {286 $miniTextoVaga = StringUtils::getText(trim($spanSummary->text));287 }288 // Data da publicação289 $vaga = [290 'nomeVaga' => $nomeVaga,291 'urlVaga' => $urlVaga,292 'nomeEmpresa' => $nomeEmpresa,293 'tipoVaga' => $tipoVaga,294 'miniTextoVaga' => $miniTextoVaga,295 'dataPublicacao' => $dataPublicacao,296 'isRH' => FALSE,297 'origem' => 'Indeed',298 ];299 // Filtra as vagas de interesse300 $add = FALSE;301 if (in_array(strtolower($nomeVaga), $vagasInteresse)) {302 $add = TRUE;303 }304 if (!$add) {305 foreach ($vagasInteresse as $vg) {306 if (StringUtils::contains(strtolower($nomeVaga), $vg)) {307 $add = TRUE;308 break;309 }310 }311 }312 if ($isDev) {313 $add = TRUE;314 }315 if ($add) {316 array_push($data, $vaga);317 $adicionado = TRUE;318 } else {319 // Vagas de RH para a esposa do Gerson320 if (StringUtils::contains(strtolower($nomeVaga), 'rh')) {321 $vaga['isRH'] = TRUE;322 }323 if (StringUtils::contains(strtolower($nomeVaga), 'recursos')) {324 $vaga['isRH'] = TRUE;325 }326 if (StringUtils::contains(strtolower($nomeVaga), 'humanos')) {327 $vaga['isRH'] = TRUE;328 }329 if ($vaga['isRH']) {330 array_push($data, $vaga);331 }332 }333 }334 // Infojobs - https://www.infojobs.com.br/empregos-em-joinville,-sc.aspx335 $urlInfo = 'https://www.infojobs.com.br/empregos-em-joinville,-sc.aspx';336 $client = new Client();337 $response = $client->request('GET', $urlInfo, ['verify' => false]);338 $type = $response->getHeader('content-type');339 $parsed = Psr7\parse_header($type);340 $original_body = (string)$response->getBody();341 $utf8_body = mb_convert_encoding($original_body, 'UTF-8', $parsed[0]['charset'] ?: 'UTF-8');342 $html = $utf8_body; //(string) $response->getBody();343 $domCrawler = (new Dom)->load($html);344 $adicionado = FALSE;345 $divJobs = $domCrawler->find('.element-vaga.unstyled');346 foreach ($divJobs as $job) {347 if ($isDev && $adicionado) continue;348 $nomeVaga = '';349 $nomeEmpresa = 'Não informado';350 $tipoVaga = 'Efetivo'; // Efetivo, estágio..351 $miniTextoVaga = '';352 $dataPublicacao = 'Não informado';353 $urlVaga = '';354 $valorSalario = '';355 // Nome da vaga356 $divVaga = $job->find('.vaga')[0];357 if ($divVaga) {358 $aVagaTitle = $divVaga->find('.vagaTitle')[0];359 if ($aVagaTitle) {360 $h2 = $aVagaTitle->find('h2')[0];361 if ($h2) {362 $nomeVaga = StringUtils::getText(trim($h2->text));363 }364 }365 }366 $vaga = [367 'nomeVaga' => $nomeVaga,368 'urlVaga' => $urlVaga,369 'nomeEmpresa' => $nomeEmpresa,370 'tipoVaga' => $tipoVaga,371 'miniTextoVaga' => $miniTextoVaga,372 'dataPublicacao' => $dataPublicacao,373 'isRH' => FALSE,374 'origem' => 'Info Jobs',375 ];376 // Filtra as vagas de interesse...

Full Screen

Full Screen

BaseArchive.php

Source:BaseArchive.php Github

copy

Full Screen

...116 }117 //118 // public methods119 //120 public function getRoot(bool $trim = true, bool $pad = true): ?string {121 $list = $this->getFileInfoList(null, null, false, $trim);122 $names = $this->infoListToNames($list, $trim);123 return $this->getRootDirectoryName($names, $trim, $pad);124 }125 public function getExtension(): ?string {126 return pathinfo($this->path, PATHINFO_EXTENSION);127 }128 public function find(?string $path, string $filter = null, bool $recursive = false): ?string {129 $info = $this->getFileInfoList($path, $filter, $recursive);130 $names = $this->infoArrayToNames($info);131 if ($names) {132 $name = $names[0];133 // strip leading ./ from name134 //135 if (StringUtils::startsWith($name, './')) {136 $name = substr($name, 2);137 }138 return $name;139 }140 return null;141 }142 public function getListing(?string $path, string $filter = null, bool $recursive = false): array {143 $info = $this->getFileInfoList($path, $filter, $recursive);144 $names = $this->infoArrayToNames($info);145 // strip leading ./ from names146 //147 for ($i = 0; $i < sizeof($names); $i++) {148 if (StringUtils::startsWith($names[$i], './')) {149 $names[$i] = substr($names[$i], 2);150 }151 }152 return $names;153 }154 public function contains(?string $dirname, string $filename): bool {155 $this->normalizePaths($dirname, $filename);156 if (StringUtils::startsWith($dirname, './')) {157 $dirname = substr($names[$i], 2);158 }159 // look in top level of specified directory160 //161 if ($dirname && $dirname != '.') {162 $path = $dirname.$filename;163 } else {164 $path = $filename;165 }166 return in_array($path, $this->getListing($dirname));167 }168 public function search(?string $dirname, array $filenames, bool $recursive = true): ?string {169 foreach ($filenames as $filename) {170 $this->normalizePaths($dirname, $filename);171 }172 $info = $this->getFileInfoList($dirname, null, $recursive);173 $names = $this->infoArrayToNames($info);174 // strip leading ./ from names175 //176 for ($i = 0; $i < sizeof($names); $i++) {177 if (StringUtils::startsWith($names[$i], './')) {178 $names[$i] = substr($names[$i], 2);179 }180 }181 // sort names by nesting level, then alphabetically182 //183 usort($names, function($a, $b) {184 $aNesting = substr_count($a, '/');185 $bNesting = substr_count($b, '/');186 if ($aNesting != $bNesting) {187 return $aNesting > $bNesting;188 } else {189 return $a > $b;190 }191 });192 for ($i = 0; $i < sizeof($names); $i++) {193 $name = $names[$i];194 for ($j = 0; $j < sizeof($filenames); $j++) {195 if (basename($name) == $filenames[$j]) {196 return $name;197 }198 }199 }200 return null;201 }202 public function found(?string $dirname, ?string $filter, bool $recursive = false): bool {203 $this->normalizePaths($dirname, $filter);204 return sizeof($this->getFileInfoList($dirname, $filter, $recursive)) != 0;205 }206 public function getFileInfoTree(?string $dirname, ?string $filter): array {207 $list = $this->getFileInfoList($dirname, $filter);208 return $this->directoryInfoListToTree($list);209 }210 public function getDirectoryInfoTree(?string $dirname, ?string $filter): array {211 $list = $this->getDirectoryInfoList($dirname, $filter);212 return $this->directoryInfoListToTree($list);213 }214 //215 // protected directory utility methods216 //217 public function getRootDirectoryName(array $array, bool $trim = true, bool $pad = true): string {218 if (sizeof($array) == 0) {219 if (!$pad) {220 return '';221 } else {222 return './';223 }224 }225 // take the first item as initial prefix226 //227 $prefix = $array[0];228 $length = strlen($prefix);229 // find the common prefix230 //231 foreach ($array as $name) {232 // strip leading ./233 //234 if ($trim) {235 if (StringUtils::startsWith($name, './')) {236 $name = substr($name, 2);237 }238 }239 // check if there is a match; if not, decrease the prefix length by one240 //241 while ($length > 0 && substr($name, 0, $length) !== $prefix) {242 $length--;243 $prefix = substr($prefix, 0, $length);244 }245 }246 // find directory name of common prefix247 //248 $last = strpos($prefix, '/');249 if ($last != false) {250 $prefix = substr($prefix, 0, $last + 1);251 } else {252 $prefix = null;253 }254 if (!$prefix) {255 if (!$pad) {256 $prefix = '';257 } else {258 $prefix = './';259 }260 }261 return $prefix;262 }263 protected function isDirectoryName(?string $path): bool {264 return $path[strlen($path) - 1] == '/';265 }266 protected function addName(string $name, array &$dirnames) {267 if (!in_array($name, $dirnames)) {268 // add directory of name269 //270 $dirname = dirname($name);271 if ($dirname != '.' && $dirname != './') {272 $this->addName($dirname.'/', $dirnames);273 }274 // add name275 //276 array_push($dirnames, $name);277 }278 }279 protected function getFileAndDirectoryNames(array $names, bool $trim = true): array {280 $dirnames = [];281 for ($i = 0; $i < sizeof($names); $i++) {282 $name = $names[$i];283 // strip leading ./284 //285 if ($trim && StringUtils::startsWith($name, './')) {286 $name = substr($name, 2);287 }288 if ($name && !in_array($name, $dirnames)) {289 // add directory of name290 //291 $dirname = dirname($name);292 if ($dirname != '.') {293 $this->addName($dirname . '/', $dirnames);294 }295 // add file or directory296 //297 array_push($dirnames, $name);298 }299 }300 return $dirnames;301 }302 //303 // protected file and directory name filtering methods304 //305 protected function getDirectoryNames(array $names): array {306 $directoryNames = [];307 for ($i = 0; $i < sizeof($names); $i++) {308 $name = $names[$i];309 if ($this->isDirectoryName($name)) {310 // strip leading ./311 //312 if (StringUtils::startsWith($name, './')) {313 $name = substr($name, 2);314 }315 array_push($directoryNames, $name);316 }317 }318 return $directoryNames;319 }320 protected function getFileNames(array $names): array {321 $fileNames = [];322 for ($i = 0; $i < sizeof($names); $i++) {323 $name = $names[$i];324 if (!$this->isDirectoryName($name)) {325 // strip leading ./326 //327 if (StringUtils::startsWith($name, './')) {328 $name = substr($name, 2);329 }330 array_push($fileNames, $name);331 }332 }333 return $fileNames;334 }335 //336 // protected name / directory filtering methods337 //338 protected function getNamesInDirectory(array $names, string $dirname = null, bool $recursive = false, bool $trim = true): array {339 $dirnames = [];340 // make sure that dirname ends with a slash341 //342 if (!StringUtils::endsWith($dirname, '/')) {343 $dirname = $dirname.'/';344 }345 if (!$dirname) {346 if ($recursive) {347 // return all348 //349 for ($i = 0; $i < sizeof($names); $i++) {350 $name = $names[$i];351 // strip leading ./352 //353 if (StringUtils::startsWith($name, './')) {354 $name = substr($name, 2);355 }356 array_push($dirnames, $name);357 }358 return $dirnames;359 } else {360 // return top level items361 //362 for ($i = 0; $i < sizeof($names); $i++) {363 $name = $names[$i];364 // strip leading ./365 //366 if (StringUtils::startsWith($name, './')) {367 $name = substr($name, 2);368 }369 if (!StringUtils::contains($name, '/')) {370 array_push($dirnames, $name);371 }372 }373 return $dirnames;374 }375 }376 // get names that are part of target directory377 //378 for ($i = 0; $i < sizeof($names); $i++) {379 $name = $names[$i];380 // strip leading ./381 //382 if ($trim) {383 if (StringUtils::startsWith($name, './')) {384 $name = substr($name, 2);385 }386 }387 if ($recursive) {388 if (StringUtils::startsWith(dirname($name).'/', $dirname)) {389 array_push($dirnames, $name);390 }391 } else {392 if (dirname($name).'/' == $dirname) {393 array_push($dirnames, $name);394 }395 }396 }397 return $dirnames;398 }399 protected function getNamesNestedInDirectory(array $names, string $dirname = null): array {400 // return all if no dirname401 //402 if (!$dirname) {403 $dirnames = [];404 for ($i = 0; $i < sizeof($names); $i++) {405 $name = $names[$i];406 // strip leading ./407 //408 if (StringUtils::startsWith($name, './')) {409 $name = substr($name, 2);410 }411 array_push($dirnames, $name);412 }413 return $dirnames;414 }415 // get names that are part of target directory (nested)416 //417 $dirnames = [];418 for ($i = 0; $i < sizeof($names); $i++) {419 $name = $names[$i];420 // strip leading ./421 //422 if (StringUtils::startsWith($name, './')) {423 $name = substr($name, 2);424 }425 if (StringUtils::startsWith($name, $dirname)) {426 array_push($dirnames, $name);427 }428 }429 return $dirnames;430 }431 protected function getFilteredNames(array $names, string $filter): array {432 // return all if no filter433 //434 if (!$filter) {435 return $names;436 }437 // get names that are inside of target directory438 //439 $filteredNames = [];440 for ($i = 0; $i < sizeof($names); $i++) {441 $name = basename($names[$i]);442 if (StringUtils::startsWith($filter, '/')) {443 // use regular expression444 //445 if (preg_match($filter, $name)) {446 array_push($filteredNames, $names[$i]);447 } 448 } else {449 // use string match450 //451 if ($filter == $name || $filter == basename($name)) {452 array_push($filteredNames, $names[$i]);453 } 454 }455 }456 return $filteredNames;457 }458 //459 // protected file name / info conversion methods460 //461 protected function nameToInfo(string $name): array {462 return [463 'name' => $name464 ];465 }466 protected function namesToInfoArray(array $names): array {467 $info = [];468 foreach ($names as $name) {469 array_push($info, $this->nameToInfo($name));470 }471 return $info;472 }473 protected function infoArrayToNames(array $info): array {474 $names = [];475 foreach ($info as $item) {476 array_push($names, $item['name']);477 }478 return $names;479 }480 //481 // protected file type inspection methods482 //483 protected function getFileTypesFromNames(array $names): array {484 $fileTypes = [];485 for ($i = 0; $i < sizeof($names); $i++) {486 $name = $names[$i];487 $extension = pathinfo($name, PATHINFO_EXTENSION);488 if (array_key_exists($extension, $fileTypes)) {489 $fileTypes[$extension]++;490 } else {491 $fileTypes[$extension] = 1;492 }493 }494 return $fileTypes;495 }496 //497 // protected archive methods498 //499 protected function addPath(string $path, array &$names) {500 if ($path && $path != '.' && $path != '/' && !in_array($path, $names)) {501 // add parent dirname502 //503 $dirname = dirname($path);504 if ($dirname && $dirname != '.' && $dirname != '/') {505 $this->addPath($dirname.'/', $names);506 }507 // add path508 //509 array_push($names, $path);510 }511 }512 protected function containsDirectoryNames(string $names): bool {513 foreach ($names as $value) {514 if (StringUtils::endsWith($value, '/')) {515 return true;516 }517 }518 return false;519 }520 protected function inferDirectoryNames(array $names): array {521 foreach ($names as $value) {522 // for each file name523 //524 if (!StringUtils::endsWith($value, '/')) {525 $terms = explode('/', $value);526 if (sizeof($terms) > 1) {527 // iterate over directory names528 //529 $path = '';530 foreach (array_slice($terms, 0, -1) as $directory) {531 // compose path532 //533 $path .= $directory.'/'; 534 // add new paths to list535 //536 if (!in_array($path, $names)) {537 array_push($names, $path);538 }539 }540 }541 }542 }543 // sort names so that new paths are not at the end544 //545 sort($names);546 return $names;547 }548 //549 // protected directory list to tree conversion methods550 //551 public function infoListToNames(array $list, bool $trim = true): array {552 $names = [];553 for ($i = 0; $i < sizeof($list); $i++) {554 $name = $list[$i]['name'];555 // strip leading ./556 //557 if ($trim && StringUtils::startsWith($name, './')) {558 $name = substr($name, 2);559 }560 array_push($names, $name);561 }562 return $names;563 }564 protected function directoryInfoListToTree(array $list): array {565 $tree = [];566 function &findLeaf(&$tree, $name) {567 // strip leading ./568 //569 if (StringUtils::startsWith($name, './')) {570 $name = substr($name, 2);571 }...

Full Screen

Full Screen

StringUtilsTest.php

Source:StringUtilsTest.php Github

copy

Full Screen

...7{8 public function testTrimToNull(): void9 {10 $valueForCheckWorkWithToString = new ClassWithToString(" BB \t\t\v");11 $this->assertEquals(null, StringUtils::trimToNull(''));12 $this->assertEquals('AsD', StringUtils::trimToNull(' AsD '));13 $this->assertEquals(14 'A dd', StringUtils::trimToNull(" \t \n \t A dd \v\t ")15 );16 $this->assertEquals(null, StringUtils::trimToNull(null));17 $this->assertEquals(null, StringUtils::trimToNull(['aa']));18 $this->assertEquals(null, StringUtils::trimToNull(new \stdClass()));19 $this->assertEquals('-124434', StringUtils::trimToNull(-124434));20 $this->assertEquals(0, StringUtils::trimToNull(0));21 $this->assertEquals(22 'BB', StringUtils::trimToNull($valueForCheckWorkWithToString)23 );24 $this->assertEquals(25 'Мама мыла раму', StringUtils::trimToNull(' Мама мыла раму ')26 );27 }28 public function testTrimToEmpty(): void29 {30 $valueForCheckWorkWithToString = new ClassWithToString(" BB \t\t\v");31 $this->assertEquals('', StringUtils::trimToEmpty(''));32 $this->assertEquals('AsD', StringUtils::trimToEmpty(' AsD '));33 $this->assertEquals(34 'A dd', StringUtils::trimToEmpty(" \t \n \t A dd \v\t ")35 );36 $this->assertEquals('', StringUtils::trimToEmpty(null));37 $this->assertEquals('', StringUtils::trimToEmpty(['aa']));38 $this->assertEquals('', StringUtils::trimToEmpty(new \stdClass()));39 $this->assertEquals('-124434', StringUtils::trimToEmpty(-124434));40 $this->assertEquals(0, StringUtils::trimToEmpty(0));41 $this->assertEquals(42 'BB', StringUtils::trimToEmpty($valueForCheckWorkWithToString)43 );44 $this->assertEquals(45 'Мама мыла раму', StringUtils::trimToEmpty(' Мама мыла раму ')46 );47 }48 public function testStartsWith(): void49 {50 $this->assertTrue(StringUtils::startsWith('Строка для поиска', 'Строка'));51 $this->assertFalse(StringUtils::startsWith('Строка для поиска', 'Строка '));52 $this->assertFalse(StringUtils::startsWith('Строка для поиска', 'для'));53 $this->assertTrue(StringUtils::startsWith('Строка для поиска', ['строка', 'Строка']));54 $this->assertFalse(StringUtils::startsWith('Строка для поиска', ['строка']));55 $this->assertTrue(StringUtils::startsWith('Some string for searching', 'Some'));56 $this->assertFalse(StringUtils::startsWith('Some string for searching', 'Some '));57 $this->assertFalse(StringUtils::startsWith('Some string for searching', 'for'));58 $this->assertTrue(StringUtils::startsWith('Some string for searching', ['some', 'Some']));59 $this->assertFalse(StringUtils::startsWith('Some string for searching', ['some']));...

Full Screen

Full Screen

AuthHelper.php

Source:AuthHelper.php Github

copy

Full Screen

...31 while (!feof($h))32 {33 $line = fgets($h);34 if (!$ns && strpos($line, 'namespace') !== false) {35 $ns = trim(preg_replace('~\s*namespace\s+([\S]+).*~', '$1', $line));36 }37 if (!$class && strpos($line, 'class') !== false) {38 $class = trim(preg_replace('/\s*class\s+(\w+).+/', '$1', $line));39 }40 if (!empty($ns) && !empty($class)) {41 break;42 }43 }44 fclose($h);45 if (!empty($ns) && !empty($class)) {46 $ns = StringUtils::removeTail($ns, ";"); // bo dau ; cuoi cung )neu co47 $className = $ns . '\\' . $class;48 $controller = StringUtils::removeTail($class, "Controller");49 $controllerId = StringUtils::camel2Dash($controller);50 Yii::info("Controller found: " . $className . " (in $file)");51 $class = new ReflectionClass($className);52// $methods = $class->getMethods();53 $objInstance = $class->newInstanceArgs(['id' => 'dummy', 'module' => 'dummy']);54// echo $objInstance->id;55 $methods = (get_class_methods ($className));56 foreach ($methods as $method) {57 $action = StringUtils::removeHead($method, "action");58 $actionId = StringUtils::camel2Dash($action);59 if (StringUtils::startsWith($method, "action") && !StringUtils::equal($method, "actions")) {60 $route = new ActionPermission();61 $route->appAlias = $alias;62 $route->name = $controller . "." . $action;63 $route->controllerId = $controllerId;64 $route->controllerName = $controller;65 $route->actionId = $actionId;66 $route->actionName = $action;67 $route->actionType = ActionPermission::ACTION_TYPE_INLINE;68 $route->controllerClass = $className;69 $route->actionMethod = $method;70 $route->file = $file;71 $route->route = $controllerId . "/" .$actionId;72 if (!$notExistedOnly || !$route->isExisted()) {73 $res[] = $route;74 }75 Yii::info("Inline action found: " . $controllerId . "/" .$actionId);76 }77 }78 $standaloneActions = $objInstance->actions();79// VarDumper::dump($standaloneActions);80 if (!empty($standaloneActions)) {81 foreach ($standaloneActions as $actionName => $actionConfig) {82 $route = new ActionPermission();83 $route->appAlias = $alias;84 if (isset($actionConfig["class"])) {85 $route->actionClass = $actionConfig["class"];86 }87 $route->name = $controller . "." . $actionName;88 $route->actionType = ActionPermission::ACTION_TYPE_STANDALONE;89 $route->controllerId = $controllerId;90 $route->controllerName = $controller;91 $route->actionId = $actionName;92 $route->actionName = $actionName;93 $route->controllerClass = $className;94 $route->actionMethod = "";95 $route->file = $file;96 $route->route = $controllerId . "/" .$actionName;97 if (!$notExistedOnly || !!$route->isExisted()) {98 $res[] = $route;99 }100// echo "Standalone action found: " . $controllerId . "/" . $actionName . "\n";101 }102 }103 }104 else {105 Yii::info("Controller NOT found in $file");106 }107 }108 return $res;109 }110 /**111 * list route cua tat ca cac controller cua app chi dinh boi $alias112 * @param string $alias - application ('@backend', '@frontend', '@app', '@console'...), actions of which to be listed113 * @param bool $notExistedOnly114 * @return ControllerRole[]115 */116 public static function listControllers($alias = '@app', $notExistedOnly = false) {117 $res = [];118 $path = Yii::getAlias($alias) . "/controllers";119// echo $path . "\n";120 $controllerFiles = glob($path . "/*Controller.php");121// VarDumper::dump($controllerFiles);122 foreach ($controllerFiles as $file) {123 $h = fopen($file, 'r') or die('wtf');124 $ns = '';125 $class = '';126 while (!feof($h)) {127 $line = fgets($h);128 if (!$ns && strpos($line, 'namespace') !== false) {129 $ns = trim(preg_replace('~\s*namespace\s+([\S]+).*~', '$1', $line));130 }131 if (!$class && strpos($line, 'class') !== false) {132 $class = trim(preg_replace('/\s*class\s+(\w+).+/', '$1', $line));133 }134 if (!empty($ns) && !empty($class)) {135 break;136 }137 }138 fclose($h);139 if (!empty($ns) && !empty($class)) {140 $ns = StringUtils::removeTail($ns, ";"); // bo dau ; cuoi cung )neu co141 $className = $ns . '\\' . $class;142 $controller = StringUtils::removeTail($class, "Controller");143 $controllerId = StringUtils::camel2Dash($controller);144 Yii::info("Controller found: " . $className . " (in $file)");145 $route = new ControllerRole();146 $route->appAlias = $alias;...

Full Screen

Full Screen

CSSParser.class.php

Source:CSSParser.class.php Github

copy

Full Screen

...30 $contents = StringUtils::stripHTMLComment($this->contents);31 $contents = mb_ereg_replace('\\s+', ' ', $contents, 'm');32 $pattern = '([-[:alnum:].#:,>@ ]+?)\\s*{(.*?)}';33 foreach (StringUtils::eregMatchAll($pattern, $contents) as $matches) {34 $key = trim($matches[1]);35 $this[$key] = Tuple::create();36 foreach (StringUtils::explode(';', trim($matches[2])) as $prop) {37 $prop = StringUtils::explode(':', $prop);38 if (!StringUtils::isBlank($value = trim($prop[1]))) {39 $this[$key][trim($prop[0])] = $value;40 }41 }42 }43 }44}...

Full Screen

Full Screen

allTrimTest.php

Source:allTrimTest.php Github

copy

Full Screen

1<?php2namespace res\infrastructure\StringUtils;3use vsc\infrastructure\StringUtils;4/**5 * Class allTrimTest6 * @package res\infrastructure\StringUtils7 * @covers \vsc\infrastructure\StringUtils::allTrim()8 */9class allTrimTest extends \BaseUnitTest {10 public function testBasicAllTrim() {11 $test = 'ana are mere';12 $spaces = sprintf(' %s ', $test);13 $tabs = sprintf("\t\t%s\t\t\t", $test);14 $newlines = sprintf("\n\n%s\r\n\r\r", $test);15 $mixed = sprintf("\n\t \n \r \t%s\r\n \r\t\r", $test);16 $this->assertEquals($test, StringUtils::allTrim($spaces));17 $this->assertEquals($test, StringUtils::allTrim($tabs));18 $this->assertEquals($test, StringUtils::allTrim($newlines));19 $this->assertEquals($test, StringUtils::allTrim($mixed));20 }21}...

Full Screen

Full Screen

trim

Using AI Code Generation

copy

Full Screen

1$trim = new StringUtils();2echo $trim->trim(" Hello World ");3$ltrim = new StringUtils();4echo $ltrim->ltrim(" Hello World ");5$rtrim = new StringUtils();6echo $rtrim->rtrim(" Hello World ");

Full Screen

Full Screen

trim

Using AI Code Generation

copy

Full Screen

1require_once 'StringUtils.class.php';2$myString = new StringUtils();3$myString->setString(" Hello world ");4echo $myString->trim();5Related Posts: PHP | trim() function6PHP | ltrim() function7PHP | rtrim() function8PHP | str_replace() function9PHP | str_split() function10PHP | str_repeat() function11PHP | str_word_count() function12PHP | strrev() function13PHP | str_shuffle() function14PHP | strcasecmp() function15PHP | strnatcmp() function16PHP | strnatcasecmp() function17PHP | strcmp() function18PHP | strcoll() function19PHP | strcspn() function20PHP | strip_tags() function21PHP | stripcslashes() function22PHP | stripos() function23PHP | stristr() function24PHP | strlen() function25PHP | strpbrk() function26PHP | strpos() function27PHP | strrchr() function28PHP | strripos() function29PHP | strrpos() function30PHP | strspn() function31PHP | strstr() function32PHP | strtok() function33PHP | strtr() function34PHP | substr() function35PHP | substr_compare() function36PHP | substr_count() function37PHP | substr_replace() function

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gherkin-php automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger trim code on LambdaTest Cloud Grid

Execute automation tests with trim on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful