PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
← All changes | vendor/wpfluent/framework/src/WPFluent/Http/Router.php +44 -2 1.6.3 → 1.6.5 View file →
@@ -69,8 +69,14 @@
69 69 */
70 70 protected $groupCount = 0;
71 71
72 72 /**
73 + * Weak references to groups pending execution.
74 + * @var array
75 + */
76 + protected $pendingGroups = [];
77 +
78 + /**
73 79 * Construct the routet instance
74 80 * @param \FluentCart\Framework\Foundation\Application $app
75 81 */
76 82 public function __construct($app)
@@ -262,10 +268,42 @@
262 268 return $this;
263 269 }
264 270
265 271 /**
272 + * Track a group so any instance kept alive past its statement
273 + * can still be executed before routes are registered. A weak
274 + * reference keeps the destructor firing at end of statement.
275 + *
276 + * @param Group $group
277 + * @return null
278 + */
279 + public function trackGroup(Group $group)
280 + {
281 + if (class_exists(\WeakReference::class)) {
282 + $this->pendingGroups[] = \WeakReference::create($group);
283 + }
284 + }
285 +
286 + /**
287 + * Execute any groups still pending execution because a
288 + * reference to them was held beyond their statement.
289 + *
290 + * @return null
291 + */
292 + protected function executePendingGroups()
293 + {
294 + while ($this->pendingGroups) {
295 + $reference = array_shift($this->pendingGroups);
296 +
297 + if ($group = $reference->get()) {
298 + $group->execute();
299 + }
300 + }
301 + }
302 +
303 + /**
266 304 * Execute the route group callback
267 - *
305 + *
268 306 * @param Closure $callback
269 307 * @return null
270 308 */
271 309 public function executeGroupCallback($callback)
@@ -467,9 +505,13 @@
467 505 * @return null
468 506 */
469 507 public function registerRoutes()
470 508 {
471 - foreach ($this->routes as $route) $route->register();
509 + $this->executePendingGroups();
510 +
511 + foreach ($this->getRoutes() as $route) {
512 + $route->register();
513 + }
472 514 }
473 515
474 516 /**
475 517 * Get all ther registered routes