Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the global functions to a closure #1

Closed
wants to merge 11 commits into from
Closed

Move the global functions to a closure #1

wants to merge 11 commits into from

Conversation

harikt
Copy link

@harikt harikt commented Oct 31, 2014

Hi Ryan Weaver,

Nice work on the Kumbaya framework. I would like a few changes, which can bring much more better things than global functions, and slowly moving the views from the controller.

The idea is to follow "refactoring to architectural change" : https://github.com/auraphp/Aura.Dispatcher#refactoring-to-architecture-changes . I don't know if there is some better component out there to do with other than aura.

Somethings I don't know are

  1. How to make a lazy object via pimple.

Eg :

<?php
class AttendeesController
{
    protected $pdo;

    protected $request;

    public function function(Request $request, PDO $pdo) 
    {
        $this->pdo = $pdo;
        $this->request = $request;
    }

    public function __invoke()
    {
        $sql = 'SELECT * FROM php_camp';
        $content = '<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />';
        $content .= '<h1>PHP Camp Attendees</h1>';
        $content .= '<table class="table" style="width: 300px;">';
        foreach ($pdo->query($sql) as $row) {
            $content .= sprintf(
                '<tr><td style="font-size: 24px;">%s</td><td><img src="%s" height="120" /></td></tr>',
                $row['attendee'],
                $row['avatar_url']
            );
        }
        $content .= '</table>';

        return new Response($content);
    }
}
<?php
$dispatcher->setObject('attendees_controller', $c['AttendeesController']);

I don't need to instantiate the object of AttendeesController when setting the object. Is there a way in Pimple ?

In that case I would like to move all the closures to a class and may a folder controllers.

What do you think?

Thank you.

weaverryan and others added 11 commits October 30, 2014 09:30
…y-httpfoundation' as we walk forward through the steps

* _tuts/master/start:
  Formatting in README
  Another README update
  Updating README
  Removing some dead code��:wq
…uts/master/aura-router' as we walk forward through the steps

* _tuts/master/symfony-httpfoundation:
  Formatting in README
  Another README update
  Updating README
  Removing some dead code��:wq
…pimple-dic' as we walk forward through the steps

* _tuts/master/aura-router:
  Formatting in README
  Another README update
  Updating README
  Removing some dead code��:wq
…f-logger' as we walk forward through the steps

* _tuts/master/pimple-dic:
  Formatting in README
  Another README update
  Updating README
  Removing some dead code��:wq
…organization' as we walk forward through the steps

* _tuts/master/zf-logger:
  Formatting in README
  Another README update
  Updating README
  Removing some dead code��:wq
@weaverryan
Copy link
Owner

Hi Hari!

First, apologies because I've re-pushed this branch and made the changelog look crazy on this PR. Fortunately, I studied it carefully before - but I wish I could reference it now!

Ok, so I did not include these changes. But not because I disagreed with them - they were a clear step forward. But for the purposes of the presentation, I wanted to drive the point that your framework maps a URI to a controller function. Having the call_user_func_array is a very direct way to illustrate this. Your proposal made the framework richer, but I don't think it added enough to overcome the fact that it was now a bit less obvious what was happening.

Though it wasn't part of this PR, I did take your advice and add a section about removing the HTML from the controller. That was just a messy-enough thing to still have in there that I agreed it was worth fixing. Btw, I updated the slides at https://speakerdeck.com/weaverryan/the-great-framework-kumbaya (they may still be processing). Aura.Router is still front-and-center, which is a credit to it being decoupled (a few years ago, I used Lithium's router, which was much more hacky).

Thanks!

@weaverryan weaverryan closed this Nov 13, 2014
@harikt
Copy link
Author

harikt commented Nov 13, 2014

Thank you @weaverryan . No problem at all. I will check the slides and see the changes that are reflected.

Thank you.

@harikt
Copy link
Author

harikt commented Nov 13, 2014

Looks nice :) .

UPDATE : about slides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants