Esempio n. 1
0
 public function testGetByName()
 {
     $articleService = new \stdClass();
     $container = $this->getMockForAbstractClass('MetaModel\\DataSource\\Container');
     $container->expects($this->once())->method('get')->with('ArticleService')->will($this->returnValue($articleService));
     $this->metaModel->addContainer($container);
     $result = $this->metaModel->run('ArticleService');
     $this->assertSame($articleService, $result);
 }
Esempio n. 2
0
 /**
  * Executes a foreach expression.
  *
  * The expression has the form: 'foo as bar', where foo is an array and bar the value.
  *
  * @param string $expression foreach expression
  * @param scope $scope
  *
  * @throws ParsingException
  * @return Scope[]
  */
 public function execute($expression, Scope $scope)
 {
     $metaModel = new MetaModel();
     $metaModel->addContainer($scope);
     $subScopes = [];
     $parseResult = $this->forEachParser->parse($expression);
     if (is_array($parseResult['array'])) {
         $functionName = $scope->getFunction($parseResult['array']['functionName']);
         $array = call_user_func_array($functionName, array_map(function ($parameter) use($metaModel) {
             return $metaModel->run($parameter);
         }, $parseResult['array']['parameters']));
     } else {
         $array = $metaModel->run($parseResult['array']);
     }
     foreach ($array as $key => $value) {
         // New sub-scope
         $subScope = new Scope($scope);
         $subScope->bind($parseResult['value'], $value);
         if (isset($parseResult['key'])) {
             $subScope->bind($parseResult['key'], $key);
         }
         $subScopes[] = $subScope;
     }
     return $subScopes;
 }