Skip to content

Commit

Permalink
Use phalcon_camelize for namesapce
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamsxin committed Mar 27, 2014
1 parent b9fd3b3 commit aa7a920
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ext/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ PHP_METHOD(Phalcon_Dispatcher, dispatch){
zval *exception = NULL;
zval *dependency_injector, *events_manager, *tmp;
zval *handler_suffix, *action_suffix, *namespace_name, *handler_name, *action_name;
zval *camelized_namespace = NULL;
int number_dispatches = 0;

PHALCON_MM_GROW();
Expand Down Expand Up @@ -710,7 +711,9 @@ PHP_METHOD(Phalcon_Dispatcher, dispatch){
if (phalcon_end_with_str(namespace_name, SL("\\"))) {
PHALCON_CONCAT_VVV(handler_class, namespace_name, camelized_class, handler_suffix);
} else {
PHALCON_CONCAT_VSVV(handler_class, namespace_name, "\\", camelized_class, handler_suffix);
PHALCON_INIT_VAR(camelized_namespace);
phalcon_camelize(camelized_namespace, namespace_name);
PHALCON_CONCAT_VSVV(handler_class, camelized_namespace, "\\", camelized_class, handler_suffix);
}
} else {
PHALCON_CONCAT_VV(handler_class, camelized_class, handler_suffix);
Expand Down Expand Up @@ -1097,6 +1100,7 @@ PHP_METHOD(Phalcon_Dispatcher, getHandlerClass){

zval *camelized_class = NULL;
zval *handler_suffix, *namespace_name, *handler_name;
zval *camelized_namespace;

PHALCON_MM_GROW();

Expand Down Expand Up @@ -1143,7 +1147,9 @@ PHP_METHOD(Phalcon_Dispatcher, getHandlerClass){
if (phalcon_end_with_str(namespace_name, SL("\\"))) {
PHALCON_CONCAT_VVV(return_value, namespace_name, camelized_class, handler_suffix);
} else {
PHALCON_CONCAT_VSVV(return_value, namespace_name, "\\", camelized_class, handler_suffix);
PHALCON_INIT_VAR(camelized_namespace);
phalcon_camelize(camelized_namespace, namespace_name);
PHALCON_CONCAT_VSVV(return_value, camelized_namespace, "\\", camelized_class, handler_suffix);
}
} else {
PHALCON_CONCAT_VV(return_value, camelized_class, handler_suffix);
Expand Down

3 comments on commit aa7a920

@ogarbe
Copy link
Contributor

@ogarbe ogarbe commented on aa7a920 Mar 31, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dreamsxin / @phalcon : since this change, i've got an error in my dispatcher :


Frontvpg\controllers\LoginController handler class cannot be loaded

#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('Frontvpg\contro...', 2)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 /nfs-dev-qnap03/FRANCE-VPG/ogarbe/www/frontvpg/web/index.php(100): Phalcon\Mvc\Application->handle()
#3 {main}

here is the code :

/**
 * Init autoloader
 */
$loader = new \Phalcon\Loader();
$namespaces = [
    'Frontvpg\Controllers' => $config->application->controllersDir,
    'Frontvpg\Library' => $config->application->libraryDir,
    'Frontvpg\Models\Common' => $config->application->modelsDir . 'common/',
    'Frontvpg\Models\Vpi' => $config->application->modelsDir . 'vpi/',
    'Frontvpg\Traits' => $config->application->traitsDir,
    'Frontvpg\Forms' => $config->application->formsDir,
    'Frontvpg\Tasks' => $config->application->tasksDir,
    'Phalcon' => $config->application->phalconIncubatorDir,
];
if (defined('DEBUG') && DEBUG === true) {
    $namespaces['PDW'] = $config->application->vendorDir . 'jymboche/phalcon-debug-widget/PDW/';
}
$loader->registerNamespaces($namespaces);
// Register the dispatcher setting a Namespace for controllers
$di->setShared(
    'dispatcher',
    function () {
        $dispatcher = new Dispatcher();
        $dispatcher->setDefaultNamespace('Frontvpg\Controllers');
        return $dispatcher;
    }
);

try {
    $application = new Application($di);
    echo $application->handle()->getContent();
} catch (\Exception $e) {
   [...]
}

seems that the loader changed the namespace Controllers to controllers

@kjdev
Copy link
Contributor

@kjdev kjdev commented on aa7a920 Apr 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoidance in the next patch.

--- a/ext/kernel/string.c
+++ b/ext/kernel/string.c
@@ -247,6 +247,12 @@ void phalcon_camelize(zval *return_value, const zval *str){

            smart_str_appendc(&camelize_str, toupper(*marker));
        }
+       else if (ch == '\\') {
+           smart_str_appendc(&camelize_str, *marker);
+           i++;
+           marker++;
+           smart_str_appendc(&camelize_str, toupper(*marker));
+       }
        else {
            smart_str_appendc(&camelize_str, tolower(*marker));
        }

@dreamsxin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change has to give up.

Please sign in to comment.