Skip to content

Commit 73dc7df

Browse files
committed
Added CLI commands.
1 parent c22930a commit 73dc7df

File tree

8 files changed

+1415
-3
lines changed

8 files changed

+1415
-3
lines changed

composer.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
"ext-json": "*",
1616
"neuron-php/application": "0.6.*",
1717
"neuron-php/routing": "^0.6.8",
18-
"symfony/yaml": "^6.4",
1918
"league/commonmark": "^2.6",
20-
"mikey179/vfsstream": "^1.6"
19+
"neuron-php/cli": "0.1.*"
2120
},
2221
"require-dev": {
2322
"phpunit/phpunit": "9.*",
24-
"phpmd/phpmd": "^2.15"
23+
"phpmd/phpmd": "^2.15",
24+
"mikey179/vfsstream": "^1.6"
2525
},
2626
"autoload": {
2727
"files": [
@@ -35,5 +35,10 @@
3535
"psr-4": {
3636
"Mvc\\": "tests/Mvc"
3737
}
38+
},
39+
"extra": {
40+
"neuron": {
41+
"cli-provider": "Neuron\\Mvc\\Cli\\Provider"
42+
}
3843
}
3944
}

readme.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A lightweight MVC (Model-View-Controller) framework component for PHP 8.4+ that
1111
- [Configuration](#configuration)
1212
- [Usage Examples](#usage-examples)
1313
- [Advanced Features](#advanced-features)
14+
- [CLI Commands](#cli-commands)
1415
- [API Reference](#api-reference)
1516
- [Testing](#testing)
1617
- [More Information](#more-information)
@@ -406,6 +407,8 @@ echo "Removed $removed expired cache entries";
406407
$app->getViewCache()->clear();
407408
```
408409

410+
You can also manage cache using the CLI commands. See [CLI Commands](#cli-commands) section for details.
411+
409412
### Custom View Implementations
410413

411414
Create custom view types by implementing `IView`:
@@ -437,6 +440,143 @@ listeners:
437440
method: logNotFound
438441
```
439442

443+
## CLI Commands
444+
445+
The MVC component includes several CLI commands for managing cache and routes. These commands are available when using the Neuron CLI tool.
446+
447+
### Cache Management Commands
448+
449+
#### mvc:cache:clear
450+
451+
Clear view cache entries.
452+
453+
**Options:**
454+
- `--type, -t VALUE` - Clear specific cache type (html, json, xml, markdown)
455+
- `--expired, -e` - Only clear expired entries
456+
- `--force, -f` - Clear without confirmation
457+
- `--config, -c PATH` - Path to configuration directory
458+
459+
**Examples:**
460+
461+
```bash
462+
# Clear all cache entries (with confirmation)
463+
neuron mvc:cache:clear
464+
465+
# Clear only expired entries
466+
neuron mvc:cache:clear --expired
467+
468+
# Clear specific cache type
469+
neuron mvc:cache:clear --type=html
470+
471+
# Force clear without confirmation
472+
neuron mvc:cache:clear --force
473+
474+
# Specify custom config path
475+
neuron mvc:cache:clear --config=/path/to/config
476+
```
477+
478+
#### mvc:cache:stats
479+
480+
Display comprehensive cache statistics.
481+
482+
**Options:**
483+
- `--config, -c PATH` - Path to configuration directory
484+
- `--json, -j` - Output statistics in JSON format
485+
- `--detailed, -d` - Show detailed breakdown by view type
486+
487+
**Examples:**
488+
489+
```bash
490+
# Display cache statistics
491+
neuron mvc:cache:stats
492+
493+
# Show detailed statistics with view type breakdown
494+
neuron mvc:cache:stats --detailed
495+
496+
# Output as JSON for scripting
497+
neuron mvc:cache:stats --json
498+
499+
# Detailed JSON output
500+
neuron mvc:cache:stats --detailed --json
501+
```
502+
503+
**Sample Output:**
504+
505+
```
506+
MVC View Cache Statistics
507+
==================================================
508+
Configuration:
509+
Cache Path: /path/to/cache/views
510+
Cache Enabled: Yes
511+
Default TTL: 3600 seconds (1 hour)
512+
513+
Overall Statistics:
514+
Total Cache Entries: 247
515+
Valid Entries: 189
516+
Expired Entries: 58
517+
Total Cache Size: 2.4 MB
518+
Average Entry Size: 10.2 KB
519+
Oldest Entry: 2025-08-10 14:23:15
520+
Newest Entry: 2025-08-13 09:45:32
521+
522+
Recommendations:
523+
- 58 expired entries can be cleared (saving ~580 KB)
524+
Run: neuron mvc:cache:clear --expired
525+
```
526+
527+
### Route Management Commands
528+
529+
#### mvc:routes:list
530+
531+
List all registered routes with filtering options.
532+
533+
**Options:**
534+
- `--config, -c PATH` - Path to configuration directory
535+
- `--controller VALUE` - Filter by controller name
536+
- `--method, -m VALUE` - Filter by HTTP method (GET, POST, PUT, DELETE, etc.)
537+
- `--pattern, -p VALUE` - Search routes by pattern
538+
- `--json, -j` - Output routes in JSON format
539+
540+
**Examples:**
541+
542+
```bash
543+
# List all routes
544+
neuron mvc:routes:list
545+
546+
# Filter by controller
547+
neuron mvc:routes:list --controller=UserController
548+
549+
# Filter by HTTP method
550+
neuron mvc:routes:list --method=POST
551+
552+
# Search by pattern
553+
neuron mvc:routes:list --pattern=/api/
554+
555+
# Combine filters
556+
neuron mvc:routes:list --controller=Api --method=GET
557+
558+
# Output as JSON for processing
559+
neuron mvc:routes:list --json
560+
```
561+
562+
**Sample Output:**
563+
564+
```
565+
MVC Routes
566+
================================================================================
567+
Pattern | Method | Controller | Action | Parameters
568+
--------------------------------------------------------------------------------
569+
/ | GET | HomeController | index | -
570+
/user/{id} | GET | UserController | profile | id
571+
/api/users | GET | Api\UserController | list | -
572+
/api/users | POST | Api\UserController | create | name, email
573+
/products | GET | ProductController | list | -
574+
/products/{id} | GET | ProductController | details | id
575+
576+
Total routes: 6
577+
Methods: GET: 4, POST: 2
578+
```
579+
440580
## API Reference
441581

442582
### Bootstrap Functions

0 commit comments

Comments
 (0)