question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Macro implementation

See original GitHub issue

Following 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
davidianbonnercommented, Aug 30, 2017

@DanielCoulbourne Excellent, hoping to get a look at implementing it over the weekend.

0reactions
davidianbonnercommented, Sep 3, 2017

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:

@dbonner1987 Could you open a PR to this repo but just add [WIP] to the name so I know it’s in progress? That way I can look over a diff and we can keep discussion inside this repo so other contributors can get involved? Thanks so much! -DC — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found