-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed 'src/framework/' changes from 2da84a5e..ba1657b8
ba1657b8 Upstream travis ci config (#160) ffdb60e5 修复Json Validator会失效的BUG (#153) 4d788e9a 修复自定义注解无法使用Aop切面编程的BUG (#139) 405a83e3 Optimize (#143) b72e04ce 修复执行php bin/swoft stop命令时master进程异常未退出的问题,以及停止失败后,pid文件被删除的问题 (#134) a30bf589 修改`ComposerHelper::getDirByNamespace`匹配有误的BUG (#137) 43088e60 Update PoolHelper.php (#131) 82aadc28 Scan bean according to Composer settings (#115) 5e55e722 Add psysh for debug (#109) 93c3ec76 Parse namespace to dir path according to composer settings (#103) git-subtree-dir: src/framework git-subtree-split: ba1657b85d5d5f1e846333e8f5ad03e499b76db8
- Loading branch information
1 parent
740e211
commit 1fab514
Showing
15 changed files
with
213 additions
and
33 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
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,69 @@ | ||
<?php | ||
|
||
namespace Swoft\Helper; | ||
|
||
|
||
use Composer\Autoload\ClassLoader; | ||
|
||
class ComposerHelper | ||
{ | ||
|
||
/** | ||
* @var ClassLoader|mixed | ||
*/ | ||
static $loader; | ||
|
||
/** | ||
* @return ClassLoader | ||
*/ | ||
public static function getLoader(): ClassLoader | ||
{ | ||
if (! self::$loader) { | ||
$loader = self::findLoader(); | ||
$loader instanceof ClassLoader && self::$loader = $loader; | ||
} | ||
return self::$loader; | ||
} | ||
|
||
/** | ||
* @return ClassLoader | ||
* @throws \RuntimeException When Composer loader not found | ||
*/ | ||
public static function findLoader(): ClassLoader | ||
{ | ||
$composerClass = ''; | ||
foreach (get_declared_classes() as $declaredClass) { | ||
if (StringHelper::startsWith($declaredClass, 'ComposerAutoloaderInit') && method_exists($declaredClass, 'getLoader')) { | ||
$composerClass = $declaredClass; | ||
break; | ||
} | ||
} | ||
if (! $composerClass) { | ||
throw new \RuntimeException('Composer loader not found.'); | ||
} | ||
return $composerClass::getLoader(); | ||
} | ||
|
||
/** | ||
* @param string $namespace | ||
* @return string | ||
*/ | ||
public static function getDirByNamespace(string $namespace): string | ||
{ | ||
$dir = ''; | ||
$loader = self::findLoader(); | ||
$prefixesPsr4 = $loader->getPrefixesPsr4(); | ||
$maxLength = 0; | ||
foreach ($prefixesPsr4 as $prefix => $path) { | ||
if (StringHelper::startsWith($namespace, $prefix)) { | ||
$strLen = strlen($prefix); | ||
if ($strLen > $maxLength) { | ||
$dir = current($path) . DIRECTORY_SEPARATOR . substr($namespace, $strLen); | ||
$maxLength = $strLen; | ||
} | ||
} | ||
} | ||
return $dir; | ||
} | ||
|
||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace SwoftTest\Aop\Annotation; | ||
|
||
/** | ||
* Class DemoAnnotation | ||
* @Annotation | ||
* @Target("METHOD") | ||
* @package SwoftTest\Aop\Annotation | ||
*/ | ||
class DemoAnnotation | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
public function __construct(array $values) | ||
{ | ||
if (isset($values['name'])) { | ||
$this->name = $values['name']; | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
namespace SwoftTest\Aop\Collector; | ||
|
||
class DemoCollector | ||
{ | ||
/** | ||
* The annotations of method | ||
* | ||
* @var array | ||
*/ | ||
public static $methodAnnotations = []; | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace SwoftTest\Aop\Parser; | ||
|
||
use Swoft\Bean\Collector; | ||
use SwoftTest\Aop\Collector\DemoCollector; | ||
|
||
class DemoAnnotationParser | ||
{ | ||
public function parser(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null) | ||
{ | ||
Collector::$methodAnnotations[$className][$methodName][] = get_class($objectAnnotation); | ||
DemoCollector::$methodAnnotations[$className][$methodName] = $objectAnnotation; | ||
return null; | ||
} | ||
} |
Oops, something went wrong.