Monday, February 2, 2015

Re: Cake 3.0 - Convenient way to retrieve if the current Table/Behavior is part of a plugin or not

that "probably" gives me chills :P

what do you think about this solution?

//in my table class
public function plugin()
{
foreach (Configure::read('App.paths.plugins') as $pluginPath) {
if (is_numeric(strpos(strtolower(__FILE__), strtolower($pluginPath)))) {
return string_between(strtolower(__FILE__), strtolower($pluginPath), DS);
}
}
}

//somewhere
function string_between($string, $start, $end)
{
$string = " " . $string;
$ini = strpos($string, $start);
if ($ini == 0) {
return "";
} else {
$ini += strlen($start);
return substr($string, $ini, strpos($string, $end, $ini) - $ini);
}
}

Il giorno venerdì 30 gennaio 2015 23:16:11 UTC+1, José Lorenzo ha scritto:
Check the namespace of the class:

list($namespace, $class) = namespaceSplit(get_class($table));

if ($namespace !== 'App\Model\Table')  // Probably a plugin :)

On Friday, January 30, 2015 at 4:10:31 PM UTC+1, Ernesto wrote:
Hi all

is there a convenient way to retrieve if the current Table/Behavior is part of a plugin or not?

in Controllers and Helpers i can inspect the request object and get it done.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: