From 4b59ca4330bbb15d3bbf8e45f124962ba160e096 Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 26 Apr 2014 17:23:21 +0800 Subject: [PATCH] toActionClass method --- src/ActionKit/ActionRunner.php | 5 ++--- src/ActionKit/Utils.php | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ActionKit/ActionRunner.php b/src/ActionKit/ActionRunner.php index 9cc16255..c7648b03 100644 --- a/src/ActionKit/ActionRunner.php +++ b/src/ActionKit/ActionRunner.php @@ -89,13 +89,12 @@ public function __construct($options = array()) { * */ public function run($actionName, $arguments = array() ) { - if ( $this->isInvalidActionName( $actionName ) ) { + if ( ! Utils::validateActionName( $actionName ) ) { throw new Exception( "Invalid action name: $actionName." ); } /* translate :: into php namespace */ - $class = $this->getActionClass( $actionName ); - + $class = Utils::toActionClass($actionName); /* register results into hash */ if ( $action = $this->createAction( $class , $arguments ) ) { diff --git a/src/ActionKit/Utils.php b/src/ActionKit/Utils.php index 89abac88..9f6c80af 100644 --- a/src/ActionKit/Utils.php +++ b/src/ActionKit/Utils.php @@ -9,6 +9,11 @@ class Utils public static function validateActionName($actionName) { return ! preg_match( '/[^A-Za-z0-9:]/i' , $actionName ); } + + public static function toActionClass( $sig ) { + // replace :: with '\' + return str_replace( '::' , '\\' , $sig ); + } }