Files
michaelschiemer/src/Framework/Metrics/FrameworkCounters.php
Michael Schiemer 5050c7d73a docs: consolidate documentation into organized structure
- Move 12 markdown files from root to docs/ subdirectories
- Organize documentation by category:
  • docs/troubleshooting/ (1 file)  - Technical troubleshooting guides
  • docs/deployment/      (4 files) - Deployment and security documentation
  • docs/guides/          (3 files) - Feature-specific guides
  • docs/planning/        (4 files) - Planning and improvement proposals

Root directory cleanup:
- Reduced from 16 to 4 markdown files in root
- Only essential project files remain:
  • CLAUDE.md (AI instructions)
  • README.md (Main project readme)
  • CLEANUP_PLAN.md (Current cleanup plan)
  • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements)

This improves:
 Documentation discoverability
 Logical organization by purpose
 Clean root directory
 Better maintainability
2025-10-05 11:05:04 +02:00

93 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Framework\Metrics;
/**
* Immutable registry of Counter value objects
* Framework-internal counters without Prometheus overhead
*/
final readonly class FrameworkCounters
{
/**
* @param array<string, Counter> $counters
*/
public function __construct(
private array $counters = []
) {
}
public function get(string $name): Counter
{
return $this->counters[$name] ?? new Counter($name, 0);
}
public function increment(string $name, int $by = 1): self
{
$current = $this->get($name);
$updated = $current->increment($by);
return new self([
...$this->counters,
$name => $updated,
]);
}
public function reset(string $name): self
{
$current = $this->get($name);
$updated = $current->reset();
return new self([
...$this->counters,
$name => $updated,
]);
}
public function resetAll(): self
{
return new self([]);
}
/**
* Get all counters
* @return array<string, Counter>
*/
public function all(): array
{
return $this->counters;
}
/**
* Convert to simple array for serialization
* @return array<string, int>
*/
public function toArray(): array
{
return array_map(
fn (Counter $counter) => $counter->value,
$this->counters
);
}
/**
* Export counters as MetricsCollection for Prometheus compatibility
*/
public function toMetricsCollection(): MetricsCollection
{
$collection = new MetricsCollection();
foreach ($this->counters as $counter) {
$collection->counter(
name: "framework_{$counter->name}",
value: (float) $counter->value,
help: "Framework internal counter: {$counter->name}",
labels: ['type' => 'internal']
);
}
return $collection;
}
}