<?php

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
namespace CloudObjects\PhpMAE\DI;

use Psr\Http\Message\RequestInterface;
use CloudObjects\SDK\ObjectRetriever;
use CloudObjects\PhpMAE\Engine, CloudObjects\PhpMAE\ClassRepository;

/**
 * The DynamicLoader allows accessing other classes that are not
 * statically defined as dependencies.
 */
class DynamicLoader {

    private $retriever;
    private $repository;

    public function __construct(ObjectRetriever $retriever, ClassRepository $repository) {
        $this->retriever = $retriever;
        $this->repository = $repository;
    }

    public function get($coid, RequestInterface $request = null) {
        $object = $this->retriever->get($coid);
        return isset($object)
            ? $this->repository->createInstance($object, $request)->get(Engine::SKEY)
            : null;
    }

}

<?php

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
namespace CloudObjects\PhpMAE\DI;

use CloudObjects\SDK\ObjectRetriever;
use CloudObjects\PhpMAE\Engine, CloudObjects\PhpMAE\ClassRepository;

/**
 * The DynamicLoader allows accessing other classes that are not
 * statically defined as dependencies.
 */
class DynamicLoader {

    private $retriever;
    private $repository;

    public function __construct(ObjectRetriever $retriever, ClassRepository $repository) {
        $this->retriever = $retriever;
        $this->repository = $repository;
    }

    public function get($coid) {
        $object = $this->retriever->get($coid);
        return isset($object)
            ? $this->repository->createInstance($object)->get(Engine::SKEY)
            : null;
    }

}

--- 
+++ 
@@ -6,6 +6,7 @@
  
 namespace CloudObjects\PhpMAE\DI;
 
+use Psr\Http\Message\RequestInterface;
 use CloudObjects\SDK\ObjectRetriever;
 use CloudObjects\PhpMAE\Engine, CloudObjects\PhpMAE\ClassRepository;
 
@@ -23,10 +24,10 @@
         $this->repository = $repository;
     }
 
-    public function get($coid) {
+    public function get($coid, RequestInterface $request = null) {
         $object = $this->retriever->get($coid);
         return isset($object)
-            ? $this->repository->createInstance($object)->get(Engine::SKEY)
+            ? $this->repository->createInstance($object, $request)->get(Engine::SKEY)
             : null;
     }
 
Support passing request dynamically loaded classes
