From 40a60c6fc8e9d46bd4f23b61b692a7538247f66a Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 21 Jan 2026 19:11:26 +0100 Subject: [PATCH] Add gitignore, update composer.json, and add agent file --- .gitignore | 25 +++++++++++++ AGENT.md | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++ composer.json | 15 ++++++-- 3 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 AGENT.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5bf66b4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +build +composer.lock +docs +vendor + +# cache directories +Thumbs.db +*.DS_Store +*.empty + +#phpstorm project files +.idea + +#netbeans project files +nbproject + +#eclipse, zend studio, aptana or other eclipse like project files +.buildpath +.project +.settings + + +# mac deployment helpers +switch +index \ No newline at end of file diff --git a/AGENT.md b/AGENT.md new file mode 100644 index 0000000..3e49c85 --- /dev/null +++ b/AGENT.md @@ -0,0 +1,98 @@ +# yii2-user Project Guidelines + +## Project Overview +- **Package**: cgsmith/yii2-user v1.0.0 +- **Type**: Yii2 user management extension module +- **PHP Version**: 8.2+ (strict requirement) +- **Yii2 Version**: 2.0.45+ +- **Namespace**: `cgsmith\user\*` +- **Architecture**: Service-oriented with dependency injection + +## Code Style +- `declare(strict_types=1);` required on all PHP files +- PSR-4 autoloading +- Constructor property promotion for DI +- PHPDoc comments on classes and public methods +- Typed properties and return types throughout +- PHPStan for static analysis + +## Directory Structure +``` +src/ +├── commands/ # Console commands (UserController, MigrateFromDektriumController) +├── contracts/ # Interfaces (UserInterface) +├── controllers/ # Web controllers (Security, Registration, Settings, Admin, Recovery, Gdpr) +├── events/ # Event classes (FormEvent, UserEvent, RegistrationEvent) +├── filters/ # Access control (AccessRule) +├── helpers/ # Utilities (Password) +├── messages/ # i18n translations +├── migrations/ # Database migrations +├── models/ # ActiveRecord + Form models +│ └── query/ # Custom query builders +├── services/ # Business logic (User, Registration, Recovery, Token, Mailer) +├── views/ # View templates +├── Bootstrap.php # Module bootstrap +└── Module.php # Main module class +``` + +## Key Patterns + +### Service Layer +Business logic lives in services, not controllers: +- `UserService` - User CRUD, block/unblock +- `RegistrationService` - Registration workflow with transactions +- `RecoveryService` - Password recovery flow +- `TokenService` - Token generation/validation +- `MailerService` - Email sending abstraction + +### Custom Query Builders +Fluent interface methods in `models/query/`: +- `active()`, `confirmed()`, `unconfirmed()`, `blocked()`, `pending()` +- `canLogin()`, `byEmail()`, `byUsername()` + +### Event System +Controllers trigger events for extensibility: +- `EVENT_BEFORE_LOGIN`, `EVENT_AFTER_LOGIN` +- `EVENT_BEFORE_REGISTER`, `EVENT_AFTER_REGISTER` +- `EVENT_BEFORE_CONFIRM`, `EVENT_AFTER_CONFIRM` + +### Model Customization +Override models via `modelMap` configuration in Module. + +## Database Tables +- `user` - User accounts with status, IP tracking, timestamps +- `user_profile` - Extended user info (bio, avatar, gravatar) +- `user_token` - Confirmation and recovery tokens +- `user_social_account` - Reserved for future OAuth + +## Console Commands +```bash +php yii user/create [password] +php yii user/delete +php yii user/confirm +php yii user/password [password] +php yii user/block +php yii user/unblock +php yii migrate-from-dektrium/migrate +``` + +## Testing +- PHPUnit 10.0+ configured +- PHPStan 1.10+ for static analysis +- Run tests: `./vendor/bin/phpunit` +- Run static analysis: `./vendor/bin/phpstan analyse` + +## Important Entry Points +- `Module.php` - Configuration and model factory +- `Bootstrap.php` - DI container bindings and route registration +- `controllers/SecurityController.php` - Login/logout +- `controllers/RegistrationController.php` - User registration +- `models/User.php` - Core user model implementing IdentityInterface + +## When Making Changes +1. Maintain strict typing with proper return types +2. Use service layer for business logic, keep controllers thin +3. Trigger events for extensibility +4. Use custom query methods for database queries +5. Support model map configuration for overridable models +6. Add PHPDoc for new classes/public methods \ No newline at end of file diff --git a/composer.json b/composer.json index 513a002..3703417 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "authors": [ { "name": "Chris Smith", - "email": "chris@cgsmith.net" + "email": "cgsmith105@gmail.com" } ], "support": { @@ -16,7 +16,7 @@ }, "require": { "php": ">=8.2", - "yiisoft/yii2": "^2.0.45" + "yiisoft/yii2": "~2.0.0" }, "require-dev": { "phpunit/phpunit": "^10.0", @@ -35,7 +35,16 @@ "extra": { "bootstrap": "cgsmith\\user\\Bootstrap" }, + "repositories": [ + { + "type": "composer", + "url": "https://asset-packagist.org" + } + ], "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "yiisoft/yii2-composer": true + } } }