<commit_before><?php

namespace CirclicalAutoWire\Service;

use CirclicalAutoWire\Annotations\Route;
use CirclicalAutoWire\Model\AnnotatedRoute;
use Doctrine\Common\Annotations\AnnotationReader;
use Zend\Router\Http\TreeRouteStack;
use Doctrine\Common\Annotations\AnnotationRegistry;

/**
 * Class RouterService
 * @package CirclicalAutoWire\Service
 *
 * This service's purpose, is to bridge annotations with the Zend SM router
 */
final class RouterService
{
    private $router;

    private $reader;

    public static $routesParsed = 0;

    private $productionMode;

    private $annotations;

    public function __construct(TreeRouteStack $router, bool $productionMode)
    {
        AnnotationRegistry::registerAutoloadNamespace("CirclicalAutoWire\\Annotations", realpath(__DIR__ . "/../../"));
        $this->router = $router;
        $this->reader = new AnnotationReader();
        $this->productionMode = $productionMode;
        $this->annotations = [];
    }

    /**
     * Reset the annotations variable
     */
    public function reset()
    {
        $this->annotations = [];
    }

    public function getAnnotations(): array
    {
        return $this->annotations;
    }

    /**
     * Parse a controller, storing results into the 'annotations' class variable
     *
     * @param string $controllerClass
     */
    public function parseController(string $controllerClass)
    {
        $class = new \ReflectionClass($controllerClass);
        /** @var Route $classAnnotation */
        $classAnnotation = $this->reader->getClassAnnotation($class, Route::class);

        // First, get all annotations for this controller

        /** @var \ReflectionMethod $method */
        foreach ($class->getMethods() as $method) {
            if ($method->getDeclaringClass()->getName() == $controllerClass) {
                $set = $this->reader->getMethodAnnotations($method);
                /** @var Route $routerAnnotation */
                foreach ($set as $routerAnnotation) {
                    if (!$routerAnnotation instanceof Route) {
                        continue;
                    }

                    if ($classAnnotation) {
                        $routerAnnotation->setPrefix($classAnnotation->value);
                    }
                    $routeName = $routerAnnotation->name ?? 'route-' . static::$routesParsed++;
                    if ($routerAnnotation->parent) {
                        $routeName = $routerAnnotation->parent . '/' . $routeName;
                    }<commit_msg>Padding routes to preserve module load order.<commit_after><?php

namespace CirclicalAutoWire\Service;

use CirclicalAutoWire\Annotations\Route;
use CirclicalAutoWire\Model\AnnotatedRoute;
use Doctrine\Common\Annotations\AnnotationReader;
use Zend\Router\Http\TreeRouteStack;
use Doctrine\Common\Annotations\AnnotationRegistry;

/**
 * Class RouterService
 * @package CirclicalAutoWire\Service
 *
 * This service's purpose, is to bridge annotations with the Zend SM router
 */
final class RouterService
{
    private $router;

    private $reader;

    public static $routesParsed = 0;

    private $productionMode;

    private $annotations;

    public function __construct(TreeRouteStack $router, bool $productionMode)
    {
        AnnotationRegistry::registerAutoloadNamespace("CirclicalAutoWire\\Annotations", realpath(__DIR__ . "/../../"));
        $this->router = $router;
        $this->reader = new AnnotationReader();
        $this->productionMode = $productionMode;
        $this->annotations = [];
    }

    /**
     * Reset the annotations variable
     */
    public function reset()
    {
        $this->annotations = [];
    }

    public function getAnnotations(): array
    {
        return $this->annotations;
    }

    /**
     * Parse a controller, storing results into the 'annotations' class variable
     *
     * @param string $controllerClass
     */
    public function parseController(string $controllerClass)
    {
        $class = new \ReflectionClass($controllerClass);
        /** @var Route $classAnnotation */
        $classAnnotation = $this->reader->getClassAnnotation($class, Route::class);

        // First, get all annotations for this controller

        /** @var \ReflectionMethod $method */
        foreach ($class->getMethods() as $method) {
            if ($method->getDeclaringClass()->getName() == $controllerClass) {
                $set = $this->reader->getMethodAnnotations($method);
                /** @var Route $routerAnnotation */
                foreach ($set as $routerAnnotation) {
                    if (!$routerAnnotation instanceof Route) {
                        continue;
                    }

                    if ($classAnnotation) {
                        $routerAnnotation->setPrefix($classAnnotation->value);
                    }
                    $routeName = $routerAnnotation->name ?? 'route-' . str_pad(static::$routesParsed++, 5, '0', STR_PAD_LEFT);
                    if ($routerAnnotation->parent) {
                        $routeName = $routerAnnotation->parent . '/' . $routeName;
                    }
{'fraction_non_alphanumeric': 0.11521187268111698, 'fraction_numerical': 0.0007810974419058778, 'mean_word_length': 2.3368078175895763, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2882816', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1238, 'n_words': 295}