<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: wrapper code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 03:48:41 GMT</pubDate>
    <description>DZone Snippets: wrapper code</description>
    <item>
      <title>PHP: Dynamically call a function from list of allowed actions</title>
      <link>http://snippets.dzone.com/posts/show/3234</link>
      <description>This function simply calls another function based on the argument, assuming that argument ($action) is in the "allowed" list of actions.&lt;br /&gt;&lt;br /&gt;settings-config.php&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$settings['actions'] = "list,view,delete,update";&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Catalog-class.php&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public function process_action($action) {&lt;br /&gt;	global $settings;&lt;br /&gt;	&lt;br /&gt;	$allowed_actions = explode(",",$settings['actions']);&lt;br /&gt;	if (is_numeric(array_search($action, $allowed_actions))) {&lt;br /&gt;		$f_name = "product_" . $action;&lt;br /&gt;		$this-&gt;$f_name();&lt;br /&gt;	} else {&lt;br /&gt;		$this-&gt;error_msg = 'ACTION_NOT_ALLOWED';&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;private function product_list() {&lt;br /&gt;}&lt;br /&gt;private function product_view() {&lt;br /&gt;}&lt;br /&gt;private function product_delete() {&lt;br /&gt;}&lt;br /&gt;private function product_update() {&lt;br /&gt;}&lt;br /&gt;private function product_create() {&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Even if product_create() exists, if you do process_action('create'), it will not work... it's basically like a function wrapper.. or something like that...&lt;br /&gt;&lt;br /&gt;UPDATE: Yes I know I could have created an array like &lt;code&gt;$settions['actions'] = array('list','view','delete','update');&lt;/code&gt; but I've modified this code a bit for snippet/display purposes... anyways this is just a reminder for myself, not of actual use or interest for others... comments are welcome though :D&lt;br /&gt;</description>
      <pubDate>Wed, 03 Jan 2007 12:15:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3234</guid>
      <author>alexwilliams (Alex Williams)</author>
    </item>
  </channel>
</rss>
