Skip to content
Permalink
Browse files

//

  • Loading branch information
rodolfoberrios committed Feb 10, 2020
1 parent bee4e14 commit ad80ff973bcfc2cfe45526f9134a15a936ce8f49
Showing with 597 additions and 557 deletions.
  1. +2 −1 .gitignore
  2. +1 −2 .php-cs → .php_cs.dist
  3. +5 −8 components/Api/ApiMaker.php
  4. +0 −54 components/Assert/AssertString.php
  5. +0 −5 components/Bootstrap/Bootstrap.php
  6. +4 −6 components/Controller/Inspect.php
  7. +2 −3 components/ExceptionHandler/TraceEntry.php
  8. +6 −5 components/Filesystem/AppPath.php
  9. +4 −2 components/Filesystem/File.php
  10. +4 −6 components/Filesystem/FileReturn.php
  11. +0 −2 components/Filesystem/Path.php
  12. +2 −2 components/Filesystem/PathFormat.php
  13. +4 −4 components/Route/PathUri.php
  14. +6 −3 components/Route/Wildcard.php
  15. +2 −2 components/Router/RouterGroups.php
  16. +3 −3 components/Router/RouterNamed.php
  17. +2 −2 components/Runtime/Traits/SetTrait.php
  18. +1 −2 components/Stopwatch/Tests/StopwatchTest.php
  19. +3 −3 components/{Assert/Exceptions/AssertStringException.php → Str/Exceptions/StrAssertException.php}
  20. +4 −4 components/{Assert/Interfaces/AssertStringnterface.php → Str/Interfaces/StrAssertInterface.php}
  21. +31 −0 components/Str/Interfaces/StrBoolInterface.php
  22. +46 −0 components/Str/Interfaces/StrInterface.php
  23. +130 −0 components/Str/Str.php
  24. +202 −0 components/Str/StrAssert.php
  25. +70 −0 components/Str/StrBool.php
  26. +9 −9 components/{Assert → Str}/Tests/AssertStringTest.php
  27. +1 −2 components/Time/Tests/TimeHrTest.php
  28. +4 −2 components/VarDump/Outputters/HtmlOutputter.php
  29. +2 −3 components/VarDump/Processors/ObjectProcessor.php
  30. +0 −1 components/VarDump/VarDumpeable.php
  31. +2 −2 components/VarDump/VarFormat.php
  32. +45 −48 composer.json
  33. +0 −371 resources/functions/ChevereFn/string.php
@@ -2,4 +2,5 @@
/composer.lock
/.phpunit.result.cache
/build/
/Chevere/TestApp/app/
/Chevere/TestApp/app/
.php_cs.cache
@@ -9,8 +9,6 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

$header = <<<'EOF'
This file is part of Chevere.
@@ -70,4 +68,5 @@ return PhpCsFixer\Config::create()
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
])
->setRiskyAllowed(true)
->setLineEnding("\n");
@@ -35,16 +35,13 @@
use Chevere\Components\Cache\Interfaces\CacheInterface;
use Chevere\Components\Http\Interfaces\MethodInterface;
use Chevere\Components\Filesystem\Interfaces\Path\PathInterface;
use Chevere\Components\Str\Str;
use Chevere\Components\Route\Interfaces\RouteInterface;
use LogicException;
use OuterIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Throwable;
use function ChevereFn\stringForwardSlashes;
use function ChevereFn\stringLeftTail;
use function ChevereFn\stringReplaceFirst;
use function ChevereFn\stringReplaceLast;

final class ApiMaker implements ApiMakerInterface
{
@@ -224,7 +221,7 @@ private function assertPath(): void
private function processRecursiveIterator(): void
{
foreach ($this->recursiveIterator as $filename) {
$filepathAbsolute = stringForwardSlashes((string) $filename);
$filepathAbsolute = (string) (new Str((string) $filename))->forwardSlashes();
$className = $this->getClassNameFromFilepath($filepathAbsolute);
$inspected = new Inspect($className);
// $this->controllersMap[$className] = $inspected;
@@ -248,7 +245,7 @@ private function processRoutesMap(): void
{
foreach ($this->routesMap as $pathComponent => $httpMethods) {
/** Full qualified route key for $pathComponent like /api/users/{user} */
$endpointRouteKey = stringLeftTail($pathComponent, '/');
$endpointRouteKey = (string) (new Str($pathComponent))->leftTail('/');
$this->route = new Route(new PathUri($endpointRouteKey));
foreach ($httpMethods as $httpMethod => $controller) {
$this->route = $this->route
@@ -278,8 +275,8 @@ private function processRoutesMap(): void
private function getClassNameFromFilepath(string $filepath): string
{
$filepathRelative = (new AppPath($filepath))->relative();
$filepathNoExt = stringReplaceLast('.php', '', $filepathRelative);
$filepathReplaceNS = stringReplaceFirst('app/src/', 'App\\', $filepathNoExt);
$filepathNoExt = (new Str($filepathRelative))->replaceLast('.php', '');
$filepathReplaceNS = (string) (new Str($filepathNoExt))->replaceFirst('app/src/', 'App\\');

return str_replace('/', '\\', $filepathReplaceNS);
}

This file was deleted.

@@ -14,17 +14,12 @@
namespace Chevere\Components\Bootstrap;

use Chevere\Components\Bootstrap\Exceptions\BootstrapDirException;
use Chevere\Components\Bootstrap\Exceptions\BootstrapException;
use Chevere\Components\Bootstrap\Interfaces\BootstrapInterface;
use Chevere\Components\Console\Interfaces\ConsoleInterface;
use Chevere\Components\Filesystem\Interfaces\Dir\DirInterface;
use Chevere\Components\Filesystem\Interfaces\Path\PathInterface;
use Chevere\Components\Filesystem\Path;
use Chevere\Components\Message\Message;
use Exception;
use Throwable;
use function ChevereFn\stringReplaceFirst;
use function ChevereFn\stringStartsWith;

final class Bootstrap implements BootstrapInterface
{
@@ -18,9 +18,7 @@
use Chevere\Components\Message\Message;
use Chevere\Components\Controller\Interfaces\ControllerInterface;
use Chevere\Components\Controller\Interfaces\InspectInterface;
use function ChevereFn\stringForwardSlashes;
use function ChevereFn\stringReplaceFirst;
use function ChevereFn\stringReplaceLast;
use Chevere\Components\Str\Str;

/**
* Provides information about any Controller implementing ControllerInterface interface.
@@ -259,9 +257,9 @@ private function processPathComponent(): void
private function getPathComponent(string $className): string
{
$classShortName = substr($className, strrpos($className, '\\') + 1);
$classNamespace = stringReplaceLast('\\' . $classShortName, '', $className);
$classNamespaceNoApp = stringReplaceFirst('App\\', '', $classNamespace);
$classNamespace = (string) (new Str($className))->replaceLast('\\' . $classShortName, '');
$classNamespaceNoApp = (string) (new Str($classNamespace))->replaceFirst('App\\', '');

return strtolower(stringForwardSlashes($classNamespaceNoApp));
return (string) (new Str($classNamespaceNoApp))->forwardSlashes()->lowercase();
}
}
@@ -17,9 +17,8 @@
use ReflectionMethod;
use Chevere\Components\ExceptionHandler\Interfaces\TraceEntryInterface;
use Chevere\Components\Message\Message;
use Chevere\Components\Str\StrBool;
use Chevere\Components\VarDump\Interfaces\VarFormatInterface;
use function ChevereFn\stringReplaceFirst;
use function ChevereFn\stringStartsWith;

/**
* Allows to interact with trace entries thrown by Exceptions.
@@ -141,7 +140,7 @@ private function handleMissingClassFile()

private function handleAnonClass()
{
if (stringStartsWith(VarFormatInterface::_CLASS_ANON, $this->class)) {
if ((new StrBool($this->class))->startsWith(VarFormatInterface::_CLASS_ANON) === true) {
preg_match('#^class@anonymous(.*):(\d+)#', $this->class, $matches);
$this->class = VarFormatInterface::_CLASS_ANON;
$this->file = $matches[1];
@@ -19,8 +19,8 @@
use Chevere\Components\Filesystem\Exceptions\Path\PathNotAllowedException;
use Chevere\Components\Filesystem\Interfaces\Path\AppPathInterface;
use Chevere\Components\Filesystem\Interfaces\Path\PathInterface;
use function ChevereFn\stringReplaceFirst;
use function ChevereFn\stringStartsWith;
use Chevere\Components\Str\Str;
use Chevere\Components\Str\StrBool;

/**
* A proxy class to handle paths in the application context.
@@ -123,15 +123,16 @@ public function getChild(string $path): PathInterface

private function handleRelative(): void
{
if (stringStartsWith('/', $this->path)) {
if ((new StrBool($this->path))->startsWith('/') === true) {
$this->assertAbsolutePath();
$this->relative = ltrim(stringReplaceFirst($this->rootDir->path()->absolute(), '', $this->path), '/');
$string = (string) (new Str($this->path))->replaceFirst($this->rootDir->path()->absolute(), '');
$this->relative = ltrim($string, '/');
}
}

private function assertAbsolutePath(): void
{
if (!stringStartsWith($this->rootDir->path()->absolute(), $this->path)) {
if ((new StrBool($this->path))->startsWith($this->rootDir->path()->absolute()) === false) {
throw new PathNotAllowedException(
(new Message('Only absolute paths in the app path %root% are allowed, path %path% provided'))
->code('%root%', $this->rootDir->path()->absolute())
@@ -13,6 +13,8 @@

namespace Chevere\Components\Filesystem;

use Chevere\Components\Str\StringAssert;
use Chevere\Components\Str\Exceptions\StrAssertException;
use Chevere\Components\Filesystem\Dir;
use Chevere\Components\Filesystem\Exceptions\File\FileExistsException;
use Chevere\Components\Filesystem\Exceptions\File\FileNotFoundException;
@@ -25,9 +27,9 @@
use Chevere\Components\Filesystem\Interfaces\File\FileInterface;
use Chevere\Components\Filesystem\Interfaces\Path\PathInterface;
use Chevere\Components\Filesystem\Path;
use Chevere\Components\Str\StrBool;
use Exception;
use Throwable;
use function ChevereFn\stringEndsWith;

/**
* This class provides interactions for a file in the application namespace.
@@ -46,7 +48,7 @@ final class File implements FileInterface
public function __construct(PathInterface $path)
{
$this->path = $path;
$this->isPhp = stringEndsWith('.php', $this->path->absolute());
$this->isPhp = (new StrBool($this->path->absolute()))->endsWith('.php');
$this->assertIsNotDir();
}

@@ -13,8 +13,7 @@

namespace Chevere\Components\Filesystem;

use Chevere\Components\Assert\AssertString;
use Chevere\Components\Assert\Exceptions\AssertStringException;
use Chevere\Components\Str\Exceptions\StrAssertException;
use Chevere\Components\Filesystem\Exceptions\File\FileHandleException;
use Chevere\Components\Filesystem\Exceptions\File\FileInvalidContentsException;
use Chevere\Components\Filesystem\Exceptions\File\FileWithoutContentsException;
@@ -23,9 +22,8 @@
use Chevere\Components\Serialize\Unserialize;
use Chevere\Components\Filesystem\Interfaces\File\FilePhpInterface;
use Chevere\Components\Filesystem\Interfaces\File\FileReturnInterface;
use Chevere\Components\Str\StrAssert;
use Chevere\Components\Variable\Interfaces\VariableExportInterface;
use LogicException;
use Throwable;

/**
* FileReturn interacts with PHP files that return something.
@@ -170,8 +168,8 @@ private function validateNonStrict(): void
{
$contents = $this->filePhp()->file()->contents();
try {
(new AssertString($contents))->notEmpty()->notCtypeSpace();
} catch (AssertStringException $e) {
(new StrAssert($contents))->notEmpty()->notCtypeSpace();
} catch (StrAssertException $e) {
throw new FileWithoutContentsException(
(new Message("The file at %path% doesn't have any contents (non-strict validation)"))
->code('%path%', $this->filePhp()->file()->path()->absolute())
@@ -16,9 +16,7 @@
use Chevere\Components\Filesystem\Exceptions\Path\PathUnableToChmodException;
use Chevere\Components\Filesystem\Exceptions\Path\PathDoesntExistsException;
use Chevere\Components\Message\Message;
use Chevere\Components\Filesystem\Exceptions\Path\PathInvalidException;
use Chevere\Components\Filesystem\Interfaces\Path\PathInterface;
use function ChevereFn\stringStartsWith;

/**
* Handles paths with context.
@@ -19,7 +19,7 @@
use Chevere\Components\Filesystem\Exceptions\Path\PathExtraSlashesException;
use Chevere\Components\Filesystem\Exceptions\Path\PathNotAbsoluteException;
use Chevere\Components\Filesystem\Interfaces\Path\PathFormatInterface;
use function ChevereFn\stringStartsWith;
use Chevere\Components\Str\StrBool;

final class PathFormat implements PathFormatInterface
{
@@ -36,7 +36,7 @@ public function __construct(string $path)

private function assertAbsolutePath(): void
{
if (!stringStartsWith('/', $this->path)) {
if ((new StrBool($this->path))->startsWith('/') === false) {
throw new PathNotAbsoluteException(
(new Message('Path %path% must start with %char%'))
->code('%path%', $this->path)
@@ -21,8 +21,8 @@
use Chevere\Components\Route\Exceptions\WildcardRepeatException;
use Chevere\Components\Route\Exceptions\WildcardReservedException;
use Chevere\Components\Route\Interfaces\PathUriInterface;
use function ChevereFn\stringReplaceFirst;
use function ChevereFn\stringStartsWith;
use Chevere\Components\Str\Str;
use Chevere\Components\Str\StrBool;

final class PathUri implements PathUriInterface
{
@@ -88,7 +88,7 @@ public function wildcards(): array

private function assertFormat(): void
{
if (!stringStartsWith('/', $this->path)) {
if ((new StrBool($this->path))->startsWith('/') === false) {
throw new PathUriForwardSlashException(
(new Message('Route path %path% must start with a forward slash'))
->code('%path%', $this->path)
@@ -179,7 +179,7 @@ private function handleWildcards(): void
foreach ($this->wildcardsMatch[0] as $key => $val) {
// Change {wildcard} to {n} (n is the wildcard index)
if (isset($this->key)) {
$this->key = stringReplaceFirst($val, "{{$key}}", $this->key);
$this->key = (string) (new Str($this->key))->replaceFirst($val, "{{$key}}");
}
$wildcard = $this->wildcardsMatch[1][$key];
if (in_array($wildcard, $this->wildcards ?? [])) {
@@ -13,14 +13,15 @@

namespace Chevere\Components\Route;

use Chevere\Components\Str\Exceptions\StrAssertException;
use Chevere\Components\Route\Exceptions\WildcardInvalidCharsException;
use Chevere\Components\Message\Message;
use Chevere\Components\Route\Exceptions\WildcardNotFoundException;
use Chevere\Components\Route\Exceptions\WildcardStartWithNumberException;
use Chevere\Components\Route\Interfaces\WildcardMatchInterface;
use Chevere\Components\Route\Interfaces\PathUriInterface;
use Chevere\Components\Route\Interfaces\WildcardInterface;
use function ChevereFn\stringStartsWithNumeric;
use Chevere\Components\Str\StrAssert;

final class Wildcard implements WildcardInterface
{
@@ -87,9 +88,11 @@ public function assertPathUri(PathUriInterface $pathUri): void

private function assertName(): void
{
if (stringStartsWithNumeric($this->name)) {
try {
(new StrAssert($this->name))->notStartsWithCtypeDigit();
} catch (StrAssertException $e) {
throw new WildcardStartWithNumberException(
(new Message("String %string% shouldn't start with a numeric value"))
(new Message('String %string% must not start with a numeric value'))
->code('%string%', $this->name)
->toString()
);
@@ -14,7 +14,7 @@
namespace Chevere\Components\Router;

use BadMethodCallException;
use Chevere\Components\Assert\AssertString;
use Chevere\Components\Str\StrAssert;
use Chevere\Components\Message\Message;
use Chevere\Components\Router\Interfaces\RouterGroupsInterface;

@@ -24,7 +24,7 @@ final class RouterGroups implements RouterGroupsInterface

public function withAdded(string $group, int $id): RouterGroupsInterface
{
(new AssertString($group))->notEmpty()->notCtypeSpace();
(new StrAssert($group))->notEmpty()->notCtypeSpace();
$new = clone $this;
if (!array_key_exists($group, $new->array)) {
$new->array[$group] = [];

0 comments on commit ad80ff9

Please sign in to comment.
You can’t perform that action at this time.