diff --git a/composer.json b/composer.json index 0e68db0d..309e7fd3 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ }, "autoload-dev": { "psr-4": { - "Ray\\Aop\\": ["tests/", "src-deprecated", "tests/Fake/", "src-deprecated"] + "Ray\\Aop\\": ["tests/", "tests/Fake/"] }, "files": ["tests/Fake/FakeGlobalNamespaced.php", "tests/Fake/FakeGlobalEmptyNamespaced.php"] }, diff --git a/src-deprecated/AopClass.php b/src-deprecated/AopClass.php deleted file mode 100644 index 861b2744..00000000 --- a/src-deprecated/AopClass.php +++ /dev/null @@ -1,66 +0,0 @@ -aopClassName = $aopClassName; - $this->codeGenMethod = new CodeGenMethod($parser, $factory); - $this->traitStmt = $factory->useTrait('\Ray\Aop\InterceptTrait')->getNode(); - } - - /** - * {@inheritDoc} - * - * @param ReflectionClass $sourceClass - */ - public function __invoke(CodeVisitor $visitor, ReflectionClass $sourceClass, BindInterface $bind): Class_ - { - assert($visitor->class instanceof Class_); - $methods = $this->codeGenMethod->getMethods($sourceClass, $bind, $visitor); - $classStm = $visitor->class; - assert(class_exists($sourceClass->name)); - $newClassName = ($this->aopClassName)($sourceClass->name, (string) $bind); - $shortClassName = strpos($newClassName, '\\') === false ? $newClassName : substr((string) strrchr($newClassName, '\\'), 1); - $classStm->name = new Identifier($shortClassName); - $classStm->extends = new Name('\\' . $sourceClass->name); - $classStm->implements[] = new Name('\Ray\Aop\WeavedInterface'); - /** @var Stmt $stmts */ - $stmts = array_merge([$this->traitStmt], $methods); - $classStm->stmts = $stmts; - - return $classStm; - } -} diff --git a/src-deprecated/AopClassName.php b/src-deprecated/AopClassName.php deleted file mode 100644 index f86a7460..00000000 --- a/src-deprecated/AopClassName.php +++ /dev/null @@ -1,29 +0,0 @@ -classDir = $classDir; - } - - /** @param class-string $class */ - public function __invoke(string $class, string $bindings): string - { - $fileTime = filemtime((string) (new ReflectionClass($class))->getFileName()); - - return sprintf('%s_%s', $class, crc32($fileTime . $bindings . $this->classDir)); - } -} diff --git a/src-deprecated/CallIntercept.php b/src-deprecated/CallIntercept.php deleted file mode 100644 index 6b30966a..00000000 --- a/src-deprecated/CallIntercept.php +++ /dev/null @@ -1,48 +0,0 @@ -_intercept(func_get_args(), __FUNCTION__); - * - * @var Expression - */ - private $expression; - - /** - * return $this->_intercept(func_get_args(), __FUNCTION__); - * - * @var Return_ - */ - private $return; - - public function __construct(BuilderFactory $factory) - { - $methodCall = $factory->methodCall( - $factory->var('this'), - '_intercept', - [$factory->funcCall('func_get_args'), $factory->constFetch('__FUNCTION__')] - ); - $this->expression = new Expression($methodCall); - $this->return = new Return_($methodCall); - } - - /** @return Return_|Return_ */ - public function getStmts(?NodeAbstract $returnType): array - { - $isVoid = $returnType instanceof Identifier && ($returnType->name === 'void' || $returnType->name === 'never'); - - return $isVoid ? [$this->expression] : [$this->return]; - } -} diff --git a/src-deprecated/Code.php b/src-deprecated/Code.php deleted file mode 100644 index 0cc995d7..00000000 --- a/src-deprecated/Code.php +++ /dev/null @@ -1,45 +0,0 @@ - $stmt */ - public function __construct(array $stmt) - { - $this->code = (new Standard(['shortArraySyntax' => true]))->prettyPrintFile($stmt) . PHP_EOL; - } - - public function save(string $filename): string - { - $tmpFile = tempnam(dirname($filename), 'swap'); - if (is_string($tmpFile) && file_put_contents($tmpFile, $this->code) && rename($tmpFile, $filename)) { - return $filename; - } - - // @codeCoverageIgnoreStart - @unlink((string) $tmpFile); - - throw new NotWritableException(sprintf('swap: %s, file: %s', $tmpFile, $filename)); - - // @codeCoverageIgnoreEnd - } -} diff --git a/src-deprecated/CodeGen.php b/src-deprecated/CodeGen.php deleted file mode 100644 index 48fbd9fe..00000000 --- a/src-deprecated/CodeGen.php +++ /dev/null @@ -1,60 +0,0 @@ -factory = $factory; - $this->visitoryFactory = $visitorFactory; - $this->aopClass = $aopClass; - } - - /** - * {@inheritDoc} - * - * @param ReflectionClass $sourceClass - */ - public function generate(ReflectionClass $sourceClass, BindInterface $bind): Code - { - $visitor = ($this->visitoryFactory)($sourceClass); - $classStm = ($this->aopClass)($visitor, $sourceClass, $bind); - $ns = $this->getNamespace($visitor); - $stmt = $this->factory->namespace($ns) - ->addStmts($visitor->use) - ->addStmt($classStm) - ->getNode(); - - return new Code(array_merge($visitor->declare, [$stmt])); - } - - /** @return string|null */ - private function getNamespace(CodeVisitor $source) - { - $parts = isset($source->namespace->name) ? $source->namespace->name->getParts() : []; - $ns = implode('\\', $parts); - - return $ns ? $ns : null; - } -} diff --git a/src-deprecated/CodeGenInterface.php b/src-deprecated/CodeGenInterface.php deleted file mode 100644 index d93d70d2..00000000 --- a/src-deprecated/CodeGenInterface.php +++ /dev/null @@ -1,14 +0,0 @@ - $sourceClass */ - public function generate(ReflectionClass $sourceClass, BindInterface $bind): Code; -} diff --git a/src-deprecated/CodeGenMethod.php b/src-deprecated/CodeGenMethod.php deleted file mode 100644 index 048ca3f3..00000000 --- a/src-deprecated/CodeGenMethod.php +++ /dev/null @@ -1,84 +0,0 @@ -visitorFactory = new VisitorFactory($parser); - $this->callIntercept = new CallIntercept($factory); - } - - /** - * @param ReflectionClass $reflectionClass - * - * @return array - */ - public function getMethods(ReflectionClass $reflectionClass, BindInterface $bind, CodeVisitor $code): array - { - $bindingMethods = array_keys($bind->getBindings()); - $reflectionMethods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC); - $methods = []; - foreach ($reflectionMethods as $reflectionMethod) { - $methodName = $reflectionMethod->getName(); - $isBindingMethod = in_array($methodName, $bindingMethods, true); - if ($isBindingMethod) { - $classMethod = $this->getClassMethod($reflectionClass, $reflectionMethod, $code); - // replace statements in the method - $classMethod->stmts = $this->callIntercept->getStmts($classMethod->getReturnType()); - $methods[] = new Nop(); - $methods[] = $classMethod; - } - } - - return $methods; - } - - /** @param ReflectionClass $sourceClass */ - private function getClassMethod( - ReflectionClass $sourceClass, - ReflectionMethod $bindingMethod, - CodeVisitor $code - ): ClassMethod { - $bindingMethodName = $bindingMethod->getName(); - foreach ($code->classMethod as $classMethod) { - if ($classMethod->name->name === $bindingMethodName) { - return $classMethod; - } - } - - $parentClass = $sourceClass->getParentClass(); - if ($parentClass === false) { - throw new InvalidSourceClassException($sourceClass->getName()); // @codeCoverageIgnore - } - - $code = ($this->visitorFactory)($parentClass); - - return $this->getClassMethod($parentClass, $bindingMethod, $code); - } -} diff --git a/src-deprecated/CodeVisitor.php b/src-deprecated/CodeVisitor.php deleted file mode 100644 index 5c2f598b..00000000 --- a/src-deprecated/CodeVisitor.php +++ /dev/null @@ -1,91 +0,0 @@ -declare[] = $node; - - return null; - } - - if ($node instanceof Use_) { - $this->addUse($node); - - return null; - } - - if ($node instanceof Namespace_) { - $this->namespace = $node; - - return null; - } - - return $this->enterNodeClass($node); - } - - private function validateClass(Class_ $class): void - { - $isClassAlreadyDeclared = $this->class instanceof Class_; - if ($isClassAlreadyDeclared) { - $name = $class->name instanceof Node\Identifier ? $class->name->name : ''; - - throw new MultipleClassInOneFileException($name); - } - } - - /** @return null */ - private function enterNodeClass(Node $node) - { - if ($node instanceof Class_ && $node->name !== null) { - $this->validateClass($node); - $this->class = $node; - - return null; - } - - if ($node instanceof ClassMethod) { - $this->classMethod[] = $node; - } - - return null; - } - - private function addUse(Use_ $use): void - { - $index = implode('\\', $use->uses[0]->name->getParts()); - $this->use[$index] = $use; - } -} diff --git a/src-deprecated/ParserFactory.php b/src-deprecated/ParserFactory.php deleted file mode 100644 index 3f341290..00000000 --- a/src-deprecated/ParserFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -create(PhpParserFactory::PREFER_PHP7); - } -} diff --git a/src-deprecated/README.md b/src-deprecated/README.md deleted file mode 100644 index 3a7914ba..00000000 --- a/src-deprecated/README.md +++ /dev/null @@ -1,7 +0,0 @@ -もしこれらのクラスが本当に必要ならcomposer.jsonの `"autoload": {"psr-4":` のセクションに以下のコードを追加してください。 - -```json -"psr-4": { - "Ray\\Aop\\": ["vendor/ray/aop/src-deprecated"] - }, -``` \ No newline at end of file diff --git a/src-deprecated/VisitorFactory.php b/src-deprecated/VisitorFactory.php deleted file mode 100644 index 49c62860..00000000 --- a/src-deprecated/VisitorFactory.php +++ /dev/null @@ -1,54 +0,0 @@ -parser = $parser; - } - - /** @param ReflectionClass $class */ - public function __invoke(ReflectionClass $class): CodeVisitor - { - $traverser = new NodeTraverser(); - $nameResolver = new NameResolver(); - $visitor = new CodeVisitor(); - $traverser->addVisitor($nameResolver); - $traverser->addVisitor($visitor); - $fileName = $class->getFileName(); - if (is_bool($fileName)) { - throw new InvalidSourceClassException(get_class($class)); - } - - $file = file_get_contents($fileName); - if ($file === false) { - throw new RuntimeException($fileName); // @codeCoverageIgnore - } - - $stmts = $this->parser->parse($file); - if (is_array($stmts)) { - $traverser->traverse($stmts); - } - - return $visitor; - } -}