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

add parameters support to getContentFunc Minify_Source callbacks #69

Closed
wants to merge 1 commit into from

Conversation

glensc
Copy link
Collaborator

@glensc glensc commented Sep 1, 2013

This is useful for getContent in Minify_Source if you need to pass extra data when building response content. Without this, I would have to duplicate logic in foo, so this would help to reuse existing variables, objects...

    public static function foo($configpath, $app, $opts = array()) {
        /* @var $config */
        require $configpath;
        $cb = foobar::create($config, $app);
        $lastModified = Minify_HTML_Helper::getLastModified($cb->getDependencies());

        $config['load_module'] = !empty($_GET['cb']) ? (string)$_GET['cb'] : $config['instance'];

        $opts = array(
            'id' => $configpath . ':' . $app . ':'. $config['load_module'],
            'lastModified' => $lastModified,
            'getContentFunc' => array(__CLASS__, 'foo_callback'),
            'getContentFuncParams' => array(
                $cb,
                $config,
            ),
        );

        $file = new Minify_Source($opts);
        return $file;
    }

    public static function foo_callback($id, $cb, $config) {
        return $cb->get($config);
    }

@mrclay
Copy link
Owner

mrclay commented Sep 1, 2013

There are two solutions to this already

  1. Create a class object with props and have the callback be to a method
  2. Make your content function anonymous and send in vars via use () from the surrounding scope

I kind of think option 1 sounds better than adding argument support since it encourages OO design. Thoughts?

@mrclay
Copy link
Owner

mrclay commented Sep 1, 2013

Third alternative: extend Minify_Source and have your own logic in getContent(). I'd like to move in the direction of simplifying that component; it's responsible for way too much logic.

@mrclay mrclay closed this Nov 12, 2013
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