This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
352 additions
and
207 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Selami\Stdlib; | ||
|
||
use function basename; | ||
use function strpos; | ||
use function substr; | ||
use function trim; | ||
|
||
class BaseUrlExtractor | ||
{ | ||
public static function getBaseUrl(array $httpServerData) : string | ||
public static function getBaseUrl(array $httpServerData): string | ||
{ | ||
$protocol = self::getProtocol($httpServerData); | ||
$host = self::getHost($httpServerData); | ||
$uriPath = $httpServerData['REQUEST_URI'] ?? ''; | ||
$filename = $httpServerData['SCRIPT_FILENAME'] ?? ''; | ||
$protocol = self::getProtocol($httpServerData); | ||
$host = self::getHost($httpServerData); | ||
$uriPath = $httpServerData['REQUEST_URI'] ?? ''; | ||
$filename = $httpServerData['SCRIPT_FILENAME'] ?? ''; | ||
$scriptName = $httpServerData['SCRIPT_NAME']; | ||
$phpSelf = $httpServerData['PHP_SELF']; | ||
$baseUrl = self::getRelativeBaseUrl($scriptName, $phpSelf, $filename); | ||
$phpSelf = $httpServerData['PHP_SELF']; | ||
$baseUrl = self::getRelativeBaseUrl($scriptName, $phpSelf, $filename); | ||
|
||
return trim($protocol . '://' . $host . $baseUrl, '/'); | ||
} | ||
|
||
|
||
|
||
public static function getProtocol(array $httpServerData) : string | ||
public static function getProtocol(array $httpServerData): string | ||
{ | ||
if (isset($httpServerData['HTTP_X_FORWARDED_PROTO'])) { | ||
return $httpServerData['HTTP_X_FORWARDED_PROTO']; | ||
} | ||
return isset($httpServerData['HTTPS']) && $httpServerData['HTTPS'] !== 'Off' ? 'https': 'http'; | ||
|
||
return isset($httpServerData['HTTPS']) && $httpServerData['HTTPS'] !== 'Off' ? 'https' : 'http'; | ||
} | ||
|
||
public static function getHost($httpServerData) : string | ||
public static function getHost($httpServerData): string | ||
{ | ||
return $httpServerData['HTTP_HOST']; | ||
} | ||
|
||
public static function getRelativeBaseUrl($scriptName, $phpSelf, $filename) : string | ||
public static function getRelativeBaseUrl($scriptName, $phpSelf, $filename): string | ||
{ | ||
|
||
// Backtrack up the SCRIPT_FILENAME to find the portion | ||
// matching PHP_SELF. | ||
$baseUrl = '/'; | ||
$basename = basename($filename); | ||
if ($basename) { | ||
$path = ($phpSelf ? trim($phpSelf, '/') : ''); | ||
$basePos = strpos($path, $basename) ?: 0; | ||
$baseUrl .= substr($path, 0, $basePos) ; | ||
$baseUrl .= substr($path, 0, $basePos); | ||
} | ||
|
||
return $baseUrl; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,53 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Selami\Stdlib; | ||
|
||
use function lcfirst; | ||
use function mb_convert_case; | ||
use function mb_strtolower; | ||
use function preg_replace; | ||
use function str_replace; | ||
use function trim; | ||
|
||
use const MB_CASE_TITLE; | ||
|
||
class CaseConverter | ||
{ | ||
/** | ||
* Returns PascalCase string | ||
* | ||
* @param string $source | ||
* @param string $separator | ||
* @return string | ||
* | ||
*/ | ||
public static function toPascalCase(string $source, string $separator = '_') : string | ||
public static function toPascalCase(string $source, string $separator = '_'): string | ||
{ | ||
// If the string is snake case | ||
$modified = str_replace($separator, ' ', $source); | ||
$lowercase = mb_strtolower($modified); | ||
$modified = str_replace($separator, ' ', $source); | ||
$lowercase = mb_strtolower($modified); | ||
$uppercaseFirstLetters = mb_convert_case($lowercase, MB_CASE_TITLE); | ||
|
||
return str_replace(' ', '', $uppercaseFirstLetters); | ||
} | ||
|
||
/** | ||
* Returns camelCase string | ||
* | ||
* @param string $source | ||
* @param string $separator | ||
* @return string | ||
* | ||
*/ | ||
public static function toCamelCase(string $source, string $separator = '_') : string | ||
public static function toCamelCase(string $source, string $separator = '_'): string | ||
{ | ||
return lcfirst(self::toPascalCase($source, $separator)); | ||
} | ||
|
||
/** | ||
* Returns snake_case string | ||
* | ||
* @param string $source | ||
* @param string $separator | ||
* @return string | ||
* | ||
*/ | ||
public static function toSnakeCase(string $source, string $separator = '_') : string | ||
public static function toSnakeCase(string $source, string $separator = '_'): string | ||
{ | ||
// If the string is pascal/camel case | ||
$modified = str_replace(' ', ' ', preg_replace('/[A-Z]+/', ' $0', $source)); | ||
$modified = str_replace(' ', ' ', preg_replace('/[A-Z]+/', ' $0', $source)); | ||
$lowercase = mb_strtolower(trim($modified)); | ||
|
||
return str_replace(' ', $separator, $lowercase); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Selami\Stdlib\Exception; | ||
|
||
class ClassOrMethodCouldNotBeFound extends \InvalidArgumentException | ||
{ | ||
use InvalidArgumentException; | ||
|
||
class ClassOrMethodCouldNotBeFound extends InvalidArgumentException | ||
{ | ||
} |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Selami\Stdlib\Exception; | ||
|
||
class InvalidArgumentException extends \InvalidArgumentException | ||
{ | ||
|
||
} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Selami\Stdlib\Exception; | ||
|
||
class InvalidSemverPatternException extends \InvalidArgumentException | ||
{ | ||
use InvalidArgumentException; | ||
|
||
class InvalidSemverPatternException extends InvalidArgumentException | ||
{ | ||
} |
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 |
---|---|---|
@@ -1,13 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Selami\Stdlib\Git; | ||
|
||
use function exec; | ||
|
||
final class Version | ||
{ | ||
public static function short() | ||
{ | ||
exec('git describe --always', $versionMiniHash); | ||
|
||
return $versionMiniHash[0]; | ||
} | ||
} |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Selami\Stdlib\Pipeline; | ||
|
||
use Exception; | ||
|
||
class InvalidStageException extends Exception | ||
{ | ||
} |
Oops, something went wrong.