{"record":{"id":"c62cc0e413ea0f0f","repo":"phalcon/cphalcon","slug":"the-dependency-injector-is-invalid","errorCode":null,"errorMessage":"The dependency injector is invalid","messagePattern":"The dependency injector is invalid","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\MetaData\\Exceptions\\InvalidContainer","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/MetaData/Strategy/Annotations.zep","lineNumber":34,"sourceCode":"use Phalcon\\Mvc\\Model\\MetaData\\Exceptions\\InvalidContainer;\nuse Phalcon\\Mvc\\Model\\MetaData\\Exceptions\\NoAnnotationsForClass;\nuse Phalcon\\Mvc\\Model\\MetaData\\Exceptions\\NoPropertyAnnotationsForClass;\nuse Phalcon\\Mvc\\ModelInterface;\n\nclass Annotations implements StrategyInterface\n{\n    /**\n     * Read the model's column map, this can't be inferred\n     */\n    final public function getColumnMaps(<ModelInterface> model, <DiInterface> container) -> array\n    {\n        var annotations, className, reflection, propertiesAnnotations, property,\n            propAnnotations, columnAnnotation, columnName;\n        array orderedColumnMap, reversedColumnMap;\n        bool hasReversedColumn;\n\n        if unlikely typeof container != \"object\" {\n            throw new InvalidContainer();\n        }\n\n        let annotations = container->get(\"annotations\");\n\n        let className = get_class(model),\n            reflection = annotations->get(className);\n\n        if unlikely typeof reflection != \"object\" {\n            throw new NoAnnotationsForClass(className);\n        }\n\n        /**\n         * Get the properties defined in\n         */\n        let propertiesAnnotations = reflection->getPropertiesAnnotations();\n\n        if unlikely empty propertiesAnnotations {\n            throw new NoPropertyAnnotationsForClass(className);","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/MetaData/Strategy/Annotations.zep#L16-L52","documentation":"The annotations-based metadata strategy (Phalcon\\Mvc\\Model\\MetaData\\Strategy\\Annotations) resolves column maps by fetching the 'annotations' service from the DI container passed into getColumnMaps(). If that container is not an object (null or scalar), the strategy cannot resolve its dependencies and throws InvalidContainer before any parsing happens.","triggerScenarios":"Calling $strategy->getColumnMaps($model, $container) or getMetaData() directly with null or a non-object container — custom strategies or test code invoking the strategy outside the metadata pipeline; a custom modelsMetadata implementation that forwards an unset container variable to the strategy.","commonSituations":"Unit tests exercising the Annotations strategy directly; custom StrategyInterface implementations reusing Annotations::getColumnMaps(); refactors that drop the container argument along the call chain.","solutions":["Pass a valid Phalcon\\Di\\DiInterface instance — normally the one obtained from $metaData->getDI().","Set the container on the MetaData component ($metaData->setDI($di)) and let initializeColumnMap() hand the strategy the container itself.","In tests, build a minimal FactoryDefault that registers an 'annotations' service before invoking the strategy."],"exampleFix":"// before\n$strategy = new Phalcon\\Mvc\\Model\\MetaData\\Strategy\\Annotations();\n$maps = $strategy->getColumnMaps(new Invoices(), null); // InvalidContainer\n\n// after\n$di = new Phalcon\\Di\\FactoryDefault(); // includes 'annotations' service\n$maps = $strategy->getColumnMaps(new Invoices(), $di);","handlingStrategy":"type-guard","validationCode":"if (!$container instanceof \\Phalcon\\Di\\DiInterface || !$container->has('annotations')) {\n    throw new RuntimeException('Annotations strategy needs a DI container with an \"annotations\" service');\n}","typeGuard":"use Phalcon\\Di\\DiInterface;\n\nfunction hasUsableContainer(mixed $container): bool\n{\n    return $container instanceof DiInterface;\n}","tryCatchPattern":"use Phalcon\\Mvc\\Model\\Exceptions\\InvalidContainer;\n\ntry {\n    $maps = $strategy->getColumnMaps($model, $container);\n} catch (InvalidContainer $e) {\n    $maps = $strategy->getColumnMaps($model, Phalcon\\Di\\Di::getDefault());\n}","preventionTips":["Source the container from $metaData->getDI() instead of passing variables that may be null.","Register an 'annotations' service in every DI passed to the strategy, including test containers.","Type-hint DiInterface on custom strategy methods so misuse fails at compile time."],"tags":["phalcon","orm","annotations","metadata","dependency-injection"],"backgroundTag":"missing-di-container","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}