Пример #1
0
 /**
  * Applies to scaffold all build instructions
  * that have specified build phase.
  *
  * @param Scaffold $scaffold
  * @param int $phase
  */
 protected function applyInstructions(Scaffold $scaffold, $phase)
 {
     $instructions = $this->blueprint->getInstructions($phase);
     foreach ($instructions as $instruction) {
         $instruction->apply($scaffold);
     }
 }
Пример #2
0
 public function test()
 {
     # test class inialization
     $this->assertEquals('SomeClass', $this->bp->class);
     # test getting instructions
     $this->assertTrue(in_array($this->instr1, $this->bp->getInstructions(Instruction::PHASE_FINAL)));
     $this->assertEmpty($this->bp->getInstructions(Instruction::PHASE_PRE_INST));
     # test adding instruction
     $this->bp->add($this->instr2);
     $this->assertTrue(in_array($this->instr2, $this->bp->getInstructions(Instruction::PHASE_PRE_INST)));
     $this->assertEmpty($this->bp->getInstructions(Instruction::PHASE_POST_INST));
     # test adding closure
     $fn = function () {
     };
     $this->bp->add($fn);
     $list = $this->bp->getInstructions(Instruction::PHASE_POST_INST);
     $instr = array_pop($list);
     $this->assertTrue($instr instanceof CustomInstruction);
 }
Пример #3
0
 /**
  * Creates blueprint for grid components.
  *
  * @return Blueprint
  */
 protected function makeComponentBlueprint()
 {
     $blueprint = new Blueprint(self::COMPONENT_CLASS, [new CustomInstruction(function (Scaffold $s) {
         if ($s->input instanceof Closure) {
             $s->class = 'Nayjest\\Grids\\Components\\RenderFunc';
             $s->constructor_arguments = [$s->input];
             $s->input = [];
         } elseif (is_string($s->input)) {
             $s->class = 'Nayjest\\Grids\\Components\\RenderFunc';
             $out = $s->input;
             $s->constructor_arguments = [function () use($out) {
                 return $out;
             }];
             $s->input = [];
         }
     }, Instruction::PHASE_PRE_INST), new CustomMapping('type', function ($type, Scaffold $s) {
         if (strpos($type, '\\') !== false) {
             $s->class = $type;
         } else {
             $s->class = 'Nayjest\\Grids\\Components\\' . str_replace(' ', '', ucwords(str_replace(array('-', '_'), ' ', $type)));
         }
     }, null, Instruction::PHASE_PRE_INST)]);
     $blueprint->add(new BuildChildren('components', $blueprint));
     $blueprint->add(new Rename('component', 'add_component'));
     $blueprint->add(new Build('add_component', $blueprint));
     $blueprint->add(new CallMethodWith('add_component', 'addComponent'));
     return $blueprint;
 }