Macro implementation
See original GitHub issueFollowing up from my post on twitter yesterday (https://twitter.com/dbonner1987/status/889252632023490564) and my adventures down the rabbit hole with the routing system in Laravel.
I’m now using just a single Route::macro implementation that will add filtering to routes. Security through obscurity is not smart but I got a bee in my bonnet and became a bit engrossed in getting a macro working cleanly.
What I have settled on for the time being is:
// Usage
Route::blacklist()->name('tags.index')->get('/tags', 'TagsController@index');
// Implementation
Route::macro('blacklist', function () {
return new class($this) {
protected $router;
public function __construct($router)
{
$this->router = $router;
}
public function __call($method, $parameters)
{
call_user_func_array([$this->router, $method], $parameters);
if ($method === 'name') {
config()->set('ziggy.blacklist', array_merge(
config('ziggy.blacklist', []), [array_get($parameters, 0, null)]
));
}
return $this;
}
};
});
Currently this allows all methods chained on to blacklist to be in any order.
Looking for some thoughts on this implementation.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Macro and Micro Implementation - RAND Corporation
The macro problem of implementing centralized change involves differentiating among localities' capacities to change, and adopting policies to promote ...
Read more >An Introduction to Scheme and its Implementation - Macros
It's an extremely powerful mechanism for abstracting over programs and putting things together in special ways. As we'll see in a later chapter,...
Read more >Macros
Now the program is ready for compilation and execution or direct interpretation, depending on the particular implementation technology being used. It is here ......
Read more >Macro Implementation of a Structured Assembly Language
Macro Implementation of a Structured Assembly Language. Abstract: The feasibility of using macros to compile a linear assembly language is well established.
Read more >3.3. Macro Implementation | CIMPLICITY 10 Documentation
3.3. Macro Implementation. Procedure. Select a location on your spreadsheet where you want to enter the point's setpoint value. Make a note of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@DanielCoulbourne Excellent, hoping to get a look at implementing it over the weekend.
Sounds like a plan. Will get it done tomorrow – calling it a night.
Cheers.
On 3 Sep 2017, 00:44 +0100, Daniel Coulbourne notifications@github.com, wrote: