-
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.
Merge pull request #15 from php-etl/feature/utf-8-functions
replace standard php functions with utf8-compatible functions
- Loading branch information
Showing
6 changed files
with
210 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kiboko\Component\StringExpressionLanguage; | ||
|
||
use Symfony\Component\ExpressionLanguage\ExpressionFunction; | ||
|
||
final class Capitalize extends ExpressionFunction | ||
{ | ||
public function __construct($name) | ||
{ | ||
parent::__construct( | ||
$name, | ||
\Closure::fromCallable($this->compile(...))->bindTo($this), | ||
\Closure::fromCallable($this->evaluate(...))->bindTo($this) | ||
); | ||
} | ||
|
||
private function compile(string $input): string | ||
{ | ||
return <<<PHP | ||
( | ||
!\\is_string({$input}) ? | ||
null : | ||
( | ||
mb_convert_case(mb_substr({$input}, 0, 1), \\MB_CASE_UPPER) . mb_substr({$input}, 1, -1) | ||
) | ||
) | ||
PHP; | ||
} | ||
|
||
private function evaluate(array $context, string $input) | ||
{ | ||
return !\is_string($input) ? | ||
null : | ||
( | ||
mb_convert_case(mb_substr($input, 0, 1), \MB_CASE_UPPER).mb_substr($input, 1, -1) | ||
); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kiboko\Component\StringExpressionLanguage; | ||
|
||
use Symfony\Component\ExpressionLanguage\ExpressionFunction; | ||
|
||
final class CapitalizeWords extends ExpressionFunction | ||
{ | ||
public function __construct($name) | ||
{ | ||
parent::__construct( | ||
$name, | ||
\Closure::fromCallable($this->compile(...))->bindTo($this), | ||
\Closure::fromCallable($this->evaluate(...))->bindTo($this) | ||
); | ||
} | ||
|
||
private function compile(string $input): string | ||
{ | ||
return <<<PHP | ||
( | ||
!\\is_string({$input}) ? | ||
null : | ||
( | ||
mb_convert_case({$input}, \\MB_CASE_TITLE) | ||
) | ||
) | ||
PHP; | ||
} | ||
|
||
private function evaluate(array $context, string $input) | ||
{ | ||
return !\is_string($input) ? | ||
null : | ||
( | ||
mb_convert_case($input, \MB_CASE_TITLE) | ||
); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kiboko\Component\StringExpressionLanguage; | ||
|
||
use Symfony\Component\ExpressionLanguage\ExpressionFunction; | ||
|
||
final class ToLowerCase extends ExpressionFunction | ||
{ | ||
public function __construct($name) | ||
{ | ||
parent::__construct( | ||
$name, | ||
\Closure::fromCallable($this->compile(...))->bindTo($this), | ||
\Closure::fromCallable($this->evaluate(...))->bindTo($this) | ||
); | ||
} | ||
|
||
private function compile(string $input): string | ||
{ | ||
return <<<PHP | ||
( | ||
!\\is_string({$input}) ? | ||
null : | ||
( | ||
mb_convert_case({$input}, \\MB_CASE_LOWER) | ||
) | ||
) | ||
PHP; | ||
} | ||
|
||
private function evaluate(array $context, string $input) | ||
{ | ||
return !\is_string($input) ? | ||
null : | ||
( | ||
mb_convert_case($input, \MB_CASE_LOWER) | ||
); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kiboko\Component\StringExpressionLanguage; | ||
|
||
use Symfony\Component\ExpressionLanguage\ExpressionFunction; | ||
|
||
final class ToUpperCase extends ExpressionFunction | ||
{ | ||
public function __construct($name) | ||
{ | ||
parent::__construct( | ||
$name, | ||
\Closure::fromCallable($this->compile(...))->bindTo($this), | ||
\Closure::fromCallable($this->evaluate(...))->bindTo($this) | ||
); | ||
} | ||
|
||
private function compile(string $input): string | ||
{ | ||
return <<<PHP | ||
( | ||
!\\is_string({$input}) ? | ||
null : | ||
( | ||
mb_convert_case({$input}, \\MB_CASE_UPPER) | ||
) | ||
) | ||
PHP; | ||
} | ||
|
||
private function evaluate(array $context, string $input) | ||
{ | ||
return !\is_string($input) ? | ||
null : | ||
( | ||
mb_convert_case($input, \MB_CASE_UPPER) | ||
); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kiboko\Component\StringExpressionLanguage; | ||
|
||
use Symfony\Component\ExpressionLanguage\ExpressionFunction; | ||
|
||
final class Truncate extends ExpressionFunction | ||
{ | ||
public function __construct($name) | ||
{ | ||
parent::__construct( | ||
$name, | ||
\Closure::fromCallable($this->compile(...))->bindTo($this), | ||
\Closure::fromCallable($this->evaluate(...))->bindTo($this) | ||
); | ||
} | ||
|
||
private function compile(string $input, string $limit): string | ||
{ | ||
return <<<PHP | ||
( | ||
!\\is_string({$input}) ? | ||
null : | ||
( | ||
rtrim(mb_substr({$input}, 0, {$limit} - 1)) . '…' | ||
) | ||
) | ||
PHP; | ||
} | ||
|
||
private function evaluate(array $context, string $input, int $limit) | ||
{ | ||
return !\is_string($input) ? | ||
null : | ||
( | ||
rtrim(mb_substr($input, 0, $limit - 1)).'…' | ||
); | ||
} | ||
} |