xp-forge / frontend

Web frontends
1 stars 1 forks source link

Two named subpatterns have the same name #3

Closed thekid closed 6 years ago

thekid commented 6 years ago
class Users {
  #[@get('/users/{id}')]
  public function find($id) { ... }

  #[@get('/users/{id}/avatar')]
  public function avatar($id) { ... }
}

preg_match_all(): Compilation failed: two named subpatterns have the same name

thekid commented 6 years ago

Affects the web.frontend.delegates.MarkBased implementation only.

thekid commented 6 years ago

The MarkBased implementation was supposed to be faster since no pattern iteration is necessary. For a real-world usecase, this doesn't prove to be true, though:

<?php

use util\profiling\Measurable;
use web\frontend\delegates\{MarkBased, PatternBased};
use web\frontend\unittest\Users;

class Routing extends Measurable {
  private $mark, $pattern;

  public function __construct($method, $arguments= []) {
    parent::__construct($method, $arguments);
    $users= new Users();
    $this->mark= new MarkBased($users);
    $this->pattern= new PatternBased($users);
  }

  #[@measure]
  public function mark() {
    return $this->mark->target('get', '/users/1549')[1]['id'];
  }

  #[@measure]
  public function pattern() {
    return $this->pattern->target('get', '/users/1549')[1]['id'];
  }
}
$ xp -m ../measure/ measure Routing -n 1000000
mark: 1000000 iteration(s), 1.245 seconds, result= "1549"
pattern: 1000000 iteration(s), 1.172 seconds, result= "1549"