-
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.
feat: complate the sql to md tool commands
- Loading branch information
Showing
24 changed files
with
994 additions
and
575 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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Inhere\Kite\Concern; | ||
|
||
use InvalidArgumentException; | ||
use function explode; | ||
use function str_contains; | ||
use function str_replace; | ||
|
||
/** | ||
* Class PathAliasTrait | ||
*/ | ||
trait StaticPathAliasTrait | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected static array $aliases = []; | ||
|
||
/** | ||
* get real value by alias | ||
* | ||
* @param string $alias | ||
* @return string | ||
*/ | ||
public static function alias(string $alias): string | ||
{ | ||
// Not an alias | ||
if (!$alias || $alias[0] !== '@') { | ||
return $alias; | ||
} | ||
|
||
$sep = '/'; | ||
$other = ''; | ||
$alias = str_replace('\\', $sep, $alias); | ||
|
||
// have other partial. e.g: @project/temp/logs | ||
if (str_contains($alias, $sep)) { | ||
[$alias, $other] = explode($sep, $alias, 2); | ||
} | ||
|
||
if (!isset(self::$aliases[$alias])) { | ||
throw new InvalidArgumentException("The alias name '$alias' is not registered!"); | ||
} | ||
|
||
return self::$aliases[$alias] . ($other ? $sep . $other : ''); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @return bool | ||
*/ | ||
public static function hasAlias(string $name): bool | ||
{ | ||
return isset(self::$aliases[$name]); | ||
} | ||
|
||
/** | ||
* @param string $alias | ||
* @param string $value | ||
* @throws InvalidArgumentException | ||
*/ | ||
public static function setAlias(string $alias, string $value): void | ||
{ | ||
self::$aliases[$alias] = self::alias($value); | ||
} | ||
|
||
/** | ||
* @param array $aliases | ||
* @throws InvalidArgumentException | ||
*/ | ||
public static function setAliases(array $aliases): void | ||
{ | ||
foreach ($aliases as $alias => $realPath) { | ||
// the 1th char must is '@' | ||
if (!$alias || $alias[0] !== '@') { | ||
continue; | ||
} | ||
|
||
self::$aliases[$alias] = self::alias($realPath); | ||
} | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getAliases(): array | ||
{ | ||
return self::$aliases; | ||
} | ||
} |
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,19 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Inhere\Kite\Console\Component; | ||
|
||
/** | ||
* class ContentsAutoWriter | ||
*/ | ||
class ContentsAutoWriter | ||
{ | ||
/** | ||
* @param string $contents | ||
* | ||
* @return bool | ||
*/ | ||
public function write(string $contents): bool | ||
{ | ||
return true; | ||
} | ||
} |
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.