.gitattributes000064400000000054151360551170007442 0ustar00/tests export-ignore /.github export-ignore .gitignore000064400000000044151360551170006536 0ustar00/vendor/ composer.lock *.cache *.log.php-cs-fixer.php000064400000005113151360551170007644 0ustar00setRiskyAllowed(true) ->setRules([ '@PSR2' => true, '@Symfony' => true, '@DoctrineAnnotation' => true, '@PhpCsFixer' => true, 'header_comment' => [ 'comment_type' => 'PHPDoc', 'header' => $header, 'separate' => 'none', 'location' => 'after_declare_strict', ], 'array_syntax' => [ 'syntax' => 'short' ], 'list_syntax' => [ 'syntax' => 'short' ], 'concat_space' => [ 'spacing' => 'one' ], 'blank_line_before_statement' => [ 'statements' => [ 'declare', ], ], 'general_phpdoc_annotation_remove' => [ 'annotations' => [ 'author' ], ], 'ordered_imports' => [ 'imports_order' => [ 'class', 'function', 'const', ], 'sort_algorithm' => 'alpha', ], 'single_line_comment_style' => [ 'comment_types' => [ ], ], 'yoda_style' => [ 'always_move_variable' => false, 'equal' => false, 'identical' => false, ], 'phpdoc_align' => [ 'align' => 'left', ], 'multiline_whitespace_before_semicolons' => [ 'strategy' => 'no_multi_line', ], 'constant_case' => [ 'case' => 'lower', ], 'class_attributes_separation' => true, 'combine_consecutive_unsets' => true, 'declare_strict_types' => true, 'linebreak_after_opening_tag' => true, 'lowercase_static_reference' => true, 'no_useless_else' => true, 'no_unused_imports' => true, 'not_operator_with_successor_space' => true, 'not_operator_with_space' => false, 'ordered_class_elements' => true, 'php_unit_strict' => false, 'phpdoc_separation' => false, 'single_quote' => true, 'standardize_not_equals' => true, 'multiline_comment_opening_closing' => true, ]) ->setFinder( PhpCsFixer\Finder::create() ->exclude('bin') ->exclude('public') ->exclude('runtime') ->exclude('vendor') ->in(__DIR__) ) ->setUsingCache(false); .phpstorm.meta.php000064400000000164151360551170010141 0ustar00 [ 'scan' => [ 'paths' => [ BASE_PATH . '/app', ], 'ignore_annotations' => [ 'mixin', ], 'class_map' => [ ], ], ], 'aspects' => [ // 在此配置可用的 Aspect ], ]; ``` 2. 修改入口文件 ```php [ 'scan' => [ 'paths' => [ BASE_PATH . '/app', ], 'ignore_annotations' => [ 'mixin', ], 'class_map' => [ ], 'collectors' => [ AspectCollector::class ], ], ], 'aspects' => [ // 这里写入对应的 Aspect app\aspect\DebugAspect::class, ] ]; ``` ### 配置入口文件 start.php > 我们将初始化方法,放到 timezone 下方,以下省略其他代码 ```php use Hyperf\AopIntegration\ClassLoader; if ($timezone = config('app.default_timezone')) { date_default_timezone_set($timezone); } // 初始化 ClassLoader::init(); ``` ### 测试 首先让我们编写待切入类 ```php 1]; } } ``` 其次新增对应的 `DebugAspect` ```php process(); } } ``` 接下来编辑控制器 `app\controller\Index` ```php 0, 'msg' => 'ok', 'data' => (new UserService())->first()]); } } ``` 最后启动服务,并测试。 ```shell php start.php start curl http://127.0.0.1:8787/index/json ``` composer.json000064400000002000151360551170007262 0ustar00{ "name": "hyperf/aop-integration", "type": "library", "license": "MIT", "keywords": [ "php", "hyperf", "AOP" ], "description": "AopIntegration", "autoload": { "psr-4": { "Hyperf\\AopIntegration\\": "src/" } }, "autoload-dev": { "psr-4": { "HyperfTest\\": "tests" } }, "require": { "php": ">=8.0", "hyperf/di": "^3.0", "hyperf/pimple": "^2.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.0", "phpstan/phpstan": "^1.0", "hyperf/testing": "^3.0", "swoole/ide-helper": "dev-master" }, "minimum-stability": "dev", "prefer-stable": true, "config": { "optimize-autoloader": true, "sort-packages": true }, "scripts": { "test": "phpunit -c phpunit.xml --colors=always", "analyse": "phpstan analyse --memory-limit 1024M -l 0 ./src", "cs-fix": "php-cs-fixer fix $1" } } phpunit.xml000064400000000755151360551170006770 0ustar00 ./tests/ src/ClassLoader.php000064400000002072151360551170010245 0ustar00set(ContainerInterface::class, $container); $container->set(Psr\Container\ContainerInterface::class, $container); } }