pbyrne84 / DynamicReturnTypePlugin

135 stars 7 forks source link

Cannot support different handling for the same named method in different classes #43

Closed chasepeeler closed 8 years ago

chasepeeler commented 9 years ago

Given the following:

{
  "class": "\\ESP\\Model\\Factory",
  "method": "get",
  "position": 0,
  "fileReturnTypeReplacementCall": [
    "ESPReturnTypes.js",
    "replaceModelFactory"
   ]
},
{
  "class": "\\ESP\\Container",
  "method": "get",
  "position": 0,
  "fileReturnTypeReplacementCall": [
    "ESPReturnTypes.js",
    "replaceContainerGet"
  ]
}

Calls to both \ESP\Container::get and \ESP\Model\Factory::get are processed by the replaceModelFactory method. However, if I switch the order in which the two items appear, so that the one for \ESP\Container is first, then calls to both methods are processed by replaceContainerGet.

pbyrne84 commented 9 years ago

Can I have the js file? Cheers

dmeybohm commented 8 years ago

@pbyrne84 This happens also for masked methods:

namespace Namespace1 {
    class Controller {
        public function model($name) {
            $name = '\Namespace1\Model\\' . $name
            return new $name;
        }
    }
}
namespace Namespace1\Model {
    class Model1 {
        public function insideModel1() {

        }
    }
}
namespace Namespace2 {
    class Controller {
        public function model($name) {
            $name = '\Namespace2\Model\\' . $name;
            return new $name;
        }
    }
}
namespace Namespace2\Model {
    class Model1 {
        public $model2;
        public function insideModel2() {

        }
    }
}
namespace Namespace2 {
    $controllerOne = new \Namespace1\Controller();
    $controllerOne->model('Model1')->insideModel1();
    $controllerTwo = new \Namespace2\Controller();
    // this references the first model instead of the second:
    $controllerTwo->model('Model1')->
}

with config:

{
    "methodCalls"  : [
        {
            "class"   : "\\Namespace1\\Controller",
            "method"  : "model",
            "position": 0,
            "mask"    : "\\Namespace1\\Model\\%s"
        },
        {
            "class"   : "\\Namespace2\\Controller",
            "method"  : "model",
            "position": 0,
            "mask"    : "\\Namespace2\\Model\\%s"
        },
    ],
    "functionCalls": []
}
pbyrne84 commented 8 years ago

Many thanks for the example. I have started looking into it.

On 27 February 2016 at 22:43, David Meybohm notifications@github.com wrote:

@pbyrne84 https://github.com/pbyrne84 This happens also for masked methods:

namespace Namespace1 { class Controller { public function model($name) { $name = '\Namespace1\Model\' . $name return new $name; } }}namespace Namespace1\Model { class Model1 { public function insideModel1() { } }}namespace Namespace2 { class Controller { public function model($name) { $name = '\Namespace2\Model\' . $name; return new $name; } }}namespace Namespace2\Model { class Model1 { public $model2; public function insideModel2() { } }}namespace Namespace2 { $controllerOne = new \Namespace1\Controller(); $controllerOne->model('Model1')->insideModel1(); $controllerTwo = new \Namespace2\Controller(); // this references the first model instead of the second: $controllerTwo->model('Model1')->}

with config:

{ "methodCalls" : [ { "class" : "\Namespace1\Controller", "method" : "model", "position": 0, "mask" : "\Namespace1\Model\%s" }, { "class" : "\Namespace2\Controller", "method" : "model", "position": 0, "mask" : "\Namespace2\Model\%s" }, ], "functionCalls": [] }

— Reply to this email directly or view it on GitHub https://github.com/pbyrne84/DynamicReturnTypePlugin/issues/43#issuecomment-189742232 .

pbyrne84 commented 8 years ago

In theory the deployable here https://github.com/pbyrne84/DynamicReturnTypePlugin/raw/master/deploy/DynamicReturnTypePlugin.zip fixes the problem

locate your current DynamicReturnTypePlugin folder under plugins dir, delete and replace with the unzipped contents of this one and let me know if it works.

dmeybohm commented 8 years ago

It works. Thanks.

pbyrne84 commented 8 years ago

Thanks for the confirmation