-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15851 from niden/T15850-camelize-lowercase
T15850 camelize lowercase
- Loading branch information
Showing
48 changed files
with
537 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
/** | ||
* This file is part of the Phalcon. | ||
* | ||
* (c) Phalcon Team <team@phalcon.io> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Phalcon\Support\Helper\Str; | ||
|
||
/** | ||
* Converts strings to kebab-case style | ||
*/ | ||
class KebabCase extends PascalCase | ||
{ | ||
/** | ||
* @param string $text | ||
* @param string|null $delimiters | ||
* | ||
* @return string | ||
*/ | ||
public function __invoke( | ||
string text, | ||
string delimiters = null | ||
) -> string { | ||
var output; | ||
|
||
let output = this->processArray(text, delimiters); | ||
|
||
return implode("_", output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
/** | ||
* This file is part of the Phalcon. | ||
* | ||
* (c) Phalcon Team <team@phalcon.io> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Phalcon\Support\Helper\Str; | ||
|
||
/** | ||
* Converts strings to PascalCase style | ||
*/ | ||
class PascalCase | ||
{ | ||
/** | ||
* @param string $text | ||
* @param string|null $delimiters | ||
* | ||
* @return string | ||
*/ | ||
public function __invoke( | ||
string text, | ||
string delimiters = null | ||
) -> string { | ||
var exploded, output; | ||
|
||
let exploded = this->processArray(text, delimiters); | ||
|
||
let output = array_map( | ||
function (element) { | ||
return ucfirst(mb_strtolower(element)); | ||
}, | ||
exploded | ||
); | ||
|
||
return implode("", output); | ||
} | ||
|
||
/** | ||
* @param string $text | ||
* @param string|null $delimiters | ||
* | ||
* @return array | ||
*/ | ||
protected function processArray(string text, string delimiters = null) -> array | ||
{ | ||
var result; | ||
|
||
if delimiters === null { | ||
let delimiters = "-_"; | ||
} | ||
|
||
/** | ||
* Escape the `-` if it exists so that it does not get interpreted | ||
* as a range. First remove any escaping for the `-` if present and then | ||
* add it again - just to be on the safe side | ||
*/ | ||
if strpos(delimiters, "\\-") !== false || strpos(delimiters, "-") !== false { | ||
let delimiters = str_replace(["\\-", "-"], ["", ""], delimiters), | ||
delimiters = "-" . $delimiters; | ||
} | ||
|
||
let result = preg_split( | ||
"/[" . delimiters . "]+/", | ||
text, | ||
-1, | ||
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY | ||
); | ||
|
||
return (false === result) ? [] : result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
/** | ||
* This file is part of the Phalcon. | ||
* | ||
* (c) Phalcon Team <team@phalcon.io> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Phalcon\Support\Helper\Str; | ||
|
||
/** | ||
* Converts strings to snake_case style | ||
*/ | ||
class SnakeCase extends PascalCase | ||
{ | ||
/** | ||
* @param string $text | ||
* @param string|null $delimiters | ||
* | ||
* @return string | ||
*/ | ||
public function __invoke( | ||
string text, | ||
string delimiters = null | ||
) -> string { | ||
var output; | ||
|
||
let output = this->processArray(text, delimiters); | ||
|
||
return implode("-", output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.