protected function createService(Definition $pDefinition) { // create reflection class $rflClass = new \ReflectionClass($pDefinition->getClassName()); // create service with constructor arguments if ($pDefinition->hasConstructArguments() === true) { // build constructor arguments $constructArguments = $this->buildArguments($pDefinition->getConstructArguments()); // build service $serviceClass = $rflClass->newInstanceArgs($constructArguments); // create service without construct arguments } else { // build service $serviceClass = $rflClass->newInstance(); } // call methods on the class foreach ($pDefinition->getMethodCalls() as $methodName => $arguments) { $this->callMethod($serviceClass, $methodName, $arguments); } // return service return $serviceClass; }