public function testToHtml() { $data = []; $id = 1; $nameInLayout = 'test-name'; $blockName = $nameInLayout . '-' . $id . '-button'; $expectedHtml = 'test html'; $blockButtonMock = $this->getMock(Container::DEFAULT_BUTTON, [], [], '', false); $blockButtonMock->expects($this->once())->method('toHtml')->willReturn($expectedHtml); $contextMock = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false); $eventManagerMock = $this->getMockForAbstractClass('Magento\\Framework\\Event\\ManagerInterface'); $contextMock->expects($this->any())->method('getEventManager')->willReturn($eventManagerMock); $scopeConfigMock = $this->getMockForAbstractClass('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $scopeConfigMock->expects($this->any())->method('getValue')->withAnyParameters()->willReturn(false); $contextMock->expects($this->any())->method('getScopeConfig')->willReturn($scopeConfigMock); $layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $layoutMock->expects($this->once())->method('createBlock')->with(Container::DEFAULT_BUTTON, $blockName)->willReturn($blockButtonMock); $contextMock->expects($this->any())->method('getLayout')->willReturn($layoutMock); $itemMock = $this->getMock('Magento\\Ui\\Component\\Control\\Item', [], [], '', false); $itemMock->expects($this->any())->method('getData')->willReturn($data); $itemMock->expects($this->any())->method('getId')->willReturn($id); $abstractContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->setMethods(['getNameInLayout'])->getMockForAbstractClass(); $abstractContextMock->expects($this->any())->method('getNameInLayout')->willReturn($nameInLayout); $container = new Container($contextMock); $container->setButtonItem($itemMock); $container->setData('context', $abstractContextMock); $this->assertEquals($expectedHtml, $container->toHtml()); }
private function renderFormFieldContent($renderApi, $unit) { $this->formSubmit = new \FormSubmit(); $fieldId = 'field' . $unit->getId(); $properties = $unit->getFormValues(); $labelText = $properties["fieldLabel"]; $listType = $properties["listType"]; //select, checkbox, radio $postRequest = $this->getPostValue($unit); $choiceBox = new \ChoiceBox(); if ($listType === \ListType::RADIO || $listType === \ListType::CHECKBOX) { $required = $renderApi->getFormValue($unit, 'enableRequired'); $formField = $choiceBox->getRadioCheckbox($renderApi, $unit, $fieldId, $postRequest, $required); } elseif ($listType === \ListType::DROP_DOWN) { $formField = $choiceBox->getSelectField($renderApi, $unit, $fieldId, $postRequest); } $label = new \Label(); $labelProperties = $label->getElementProperties(); $labelProperties->addAttribute("for", $fieldId); $label->add(new \Span($labelText)); if ($formField) { $elementProperties = $formField->getElementProperties(); $wrapper = new \Container(); $wrapper->add($label); $wrapper->add($formField); echo $wrapper->renderElement(); } $renderApi->renderChildren($unit); }
public function run() { $entityManager = null; if (is_array($_SERVER['argv'])) { foreach ($_SERVER['argv'] as $key => $value) { if (substr($value, 0, 5) === '--em=') { $entityManager = substr($value, 5); unset($_SERVER['argv'][$key]); if (is_int($_SERVER['argc'])) { $_SERVER['argc']--; } break; } } } $commands = $this->container->getDoctrine()->getCommands(); $helperSet = $this->container->getDoctrine()->getHelperSet($entityManager); if (!$helperSet instanceof HelperSet) { foreach ($GLOBALS as $helperSetCandidate) { if ($helperSetCandidate instanceof HelperSet) { $helperSet = $helperSetCandidate; break; } } } ConsoleRunner::run($helperSet, $commands); }
public function BuildTemplate($a_template) { // Load template $doc = new Template_Document($a_template); // Load all static modules $modules = $doc->getElementsByTag('CMS_MODULE'); foreach ($modules as $module) { // Build Module $c_module = new StaticModule($module, $this->m_pageid); $module_doc = $c_module->Build(); $module->replaceWith($module_doc); } // Load all modules $containers = $doc->getElementsByTag('CMS_CONTAINER'); foreach ($containers as $container) { $c_container = new Container($container, $this->m_pageid); $c_container->Build(); } // Plugin Hook $data_object = new stdClass(); $data_object->pageid = $this->m_pageid; $data_object->doc = $doc; ObjMgr::GetPluginMgr()->ExecuteHook("On_Compiler_BuiltTemplate", $data_object); return $doc; }
public function testFactoryExists() { $this->assertFalse($this->container->factoryExists('foo')); $this->container->factory('foo', function () { }); $this->assertTrue($this->container->factoryExists('foo')); }
/** * Getting required arguments with given parameters * * @param \ReflectionParameter[] $required Arguments * @param array $params Parameters * *@return array */ private function _resolveArgs($required, $params = array()) { $args = array(); foreach ($required as $param) { $name = $param->getName(); $type = $param->getClass(); if (isset($type)) { $type = $type->getName(); } if (isset($params[$name])) { $args[] = $params[$name]; } elseif (is_string($type) && isset($params[$type])) { $args[] = $params[$type]; } else { $content = $this->_container->get($name); if (isset($content)) { $args[] = $content; } elseif (is_string($type)) { $args[] = $this->_container->get($type); } else { $args[] = null; } } } return $args; }
public function warmUp($cacheDir) { // we need the directory no matter the hydrator cache generation strategy. $hydratorCacheDir = $this->container->getParameter('doctrine_mongodb.odm.hydrator_dir'); if (!file_exists($hydratorCacheDir)) { if (false === @mkdir($hydratorCacheDir, 0777, true)) { throw new \RuntimeException(sprintf('Unable to create the Doctrine Hydrator directory (%s)', dirname($hydratorCacheDir))); } } else { if (!is_writable($hydratorCacheDir)) { throw new \RuntimeException(sprintf('Doctrine Hydrator directory (%s) is not writable for the current system user.', $hydratorCacheDir)); } } // if hydrators are autogenerated we don't need to generate them in the cache warmer. if ($this->container->getParameter('doctrine_mongodb.odm.auto_generate_hydrator_classes') === true) { return; } /* @var $registry \Doctrine\Common\Persistence\ManagerRegistry */ $registry = $this->container->get('doctrine_mongodb'); foreach ($registry->getManagers() as $dm) { /* @var $dm \Doctrine\ODM\MongoDB\DocumentManager */ $classes = $dm->getMetadataFactory()->getAllMetadata(); $dm->getHydratorFactory()->generateHydratorClasses($classes); } }
public function getHtml() { $trace = $this->trace->addChild("HodnoteniaCallback"); $hodnotenia = $this->app->getHodnotenia($trace); $hodnoteniaTable = new Table(TableDefinitions::hodnotenia()); $priemeryCalculator = new PriemeryCalculator(); foreach (Sorter::sort($hodnotenia->getData(), array("semester" => -1, "nazov" => 1)) as $row) { if ($row['semester'] == 'L') { $class = 'leto'; $priemeryCalculator->add(PriemeryCalculator::SEMESTER_LETNY, $row['znamka'], $row['kredit']); } else { $class = 'zima'; $priemeryCalculator->add(PriemeryCalculator::SEMESTER_ZIMNY, $row['znamka'], $row['kredit']); } $hodnoteniaTable->addRow($row, array('class' => $class)); } $hodnoteniaCollapsible = new Collapsible(new HtmlHeader('Hodnotenia'), $hodnoteniaTable); $priemery = $this->app->getPriemery($trace); $priemeryTable = new Table(TableDefinitions::priemery()); $priemeryTable->addRows($priemery->getData()); $priemeryContainer = new Container(); $priemeryContainer->addChild(new Label('Nasledovné priemery sú prebraté z AISu, čiže to (ne)funguje presne rovnako:')); $priemeryContainer->addChild($priemeryTable); if ($priemeryCalculator->hasPriemer()) { $priemeryFajrText = '<p><br />Nasledovné vážené študijné priemery sú počítané Fajrom priebežne z tabuľky Hodnotenia, <strong>preto nemôžu byť považované ako oficiálne</strong>:<br /><br />'; $priemeryFajrText .= $priemeryCalculator->getHtml(); $priemeryFajrText .= '</p>'; $priemeryContainer->addChild(new Label($priemeryFajrText)); } $priemeryCollapsible = new Collapsible(new HtmlHeader('Priemery'), $priemeryContainer); return $hodnoteniaCollapsible->getHtml() . $priemeryCollapsible->getHtml(); }
public function testCanBindInterfaceUsingWhenNeedsGive() { $this->container->when('NetRivet\\Container\\Test\\Foo')->needs('NetRivet\\Container\\Test\\BarInterface')->give('NetRivet\\Container\\Test\\Bar2'); $foo = $this->container->make('NetRivet\\Container\\Test\\Foo'); $bar = $foo->getBar(); $this->assertInstanceOf('NetRivet\\Container\\Test\\Bar2', $bar); }
/** * Write table * * @return string */ public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Table) { return ''; } $content = ''; $rows = $this->element->getRows(); $rowCount = count($rows); if ($rowCount > 0) { $content .= '<table>' . PHP_EOL; foreach ($rows as $row) { /** @var $row \PhpOffice\PhpWord\Element\Row Type hint */ $rowStyle = $row->getStyle(); // $height = $row->getHeight(); $tblHeader = $rowStyle->isTblHeader(); $content .= '<tr>' . PHP_EOL; foreach ($row->getCells() as $cell) { $writer = new Container($this->parentWriter, $cell); $cellTag = $tblHeader ? 'th' : 'td'; $content .= "<{$cellTag}>" . PHP_EOL; $content .= $writer->write(); $content .= "</{$cellTag}>" . PHP_EOL; } $content .= '</tr>' . PHP_EOL; } $content .= '</table>' . PHP_EOL; } return $content; }
/** * Running testcase testRepresent(). * * @return void */ public function testConstructList() { $test_array = array(new Integer(3), new Integer(4)); $this->object->expects($this->at(0))->method('contain')->with($this->equalTo($test_array[0])); $this->object->expects($this->at(1))->method('contain')->with($this->equalTo($test_array[1])); $this->object->__construct($test_array); }
protected function setUp() { $this->application = new Application(); $this->application->add(new OrganizeFileCommand()); $this->command = $this->application->find('organizer:files'); $this->commandTester = new CommandTester($this->command); }
public function __construct() { if (!isset($this->sessao)) { $this->sessao = new Sessao('ip' . str_replace('.', '_', $_SERVER['REMOTE_ADDR'])); $this->sessao->setExpirationSeconds(86400); //24h to expire } }
private function inject(Container $model, $arg) { $sitemap = ''; foreach ($model->getModels() as $key => $value) { $sitemap .= $this->visit($value, $arg . '/' . $key, false); } return '<div class="sitemap-sub-level"><ul>' . $sitemap . '</ul>'; }
public function container(Container $model, $arg, $bool) { $string = ''; foreach ($model->getModels() as $m) { $string .= $this->visit($m, $arg, $bool); } return $string; }
/** * * @param Collection|Container $model * @param int $arg * @return string */ public function container(Container $model, $arg) { $sitemap = ''; foreach ($model->getModels() as $key => $value) { $sitemap .= $this->visit($value, $arg . '/' . $key); } return '<li><p><a href="' . $arg . '">' . $model->config['name'] . '</a></p><div class="sitemap-sub-level"><ul>' . $sitemap . '</ul></div></li>'; }
public function testContainerToCallback() { $c = new Container(); $c->share('service', function (Container $container) { return $container; }); $this->assertInstanceOf(Container::class, $c->get('service')); }
/** * Load services from PHP file. * * @param string * @return self */ public function load($file) { $items = (array) (include $file); foreach ($items as $id => $service) { $this->container->set($id, $service); } return $this; }
/** * Initialize the router object. * * @param Container $container */ public function __construct($container) { $this->container = $container; $this->request = new Request($container->get('request')); $this->response = new Response($this->request->getCallType(), $this->request->isUpload()); $this->defaultAccess = $container->getParameter('direct.api.default_access'); $this->session = $this->container->get('session')->get($container->getParameter('direct.api.session_attribute')); }
public function testGetObjectConstructorArguments() { $container = new Container(); $container->set('foo', new \stdClass()); $container->set('foo_bar', new \stdClass()); $builder = new ObjectBuilder($container); $object = $builder->getObject('PSX\\Dependency\\FooService', array('foo'), 'PSX\\Dependency\\FooService'); $this->assertEquals('foo', $object->getProperty()); }
public function executeCron(Container $cron, $unqueue = true) { $date = $cron->getDate(); if ($date <= time()) { $_REQUEST = unserialize($cron->getData()); context()->dispatch($cron); return true === $unqueue ? $this->unqueueCron($cron) : $this; } }
/** * Write text run * * @return string */ public function write() { $content = ''; $content .= $this->writeOpening(); $writer = new Container($this->parentWriter, $this->element); $content .= $writer->write(); $content .= $this->writeClosing(); return $content; }
public function __construct($app) { $this->app = $app; $this->container = new Container(); $this->defineEnv($this->container); $this->defineApp(); $this->container->init(); Profile::Checkpoint('Container has been Created'); }
/** * Write textrun element */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); $this->writeOpeningWP(); $containerWriter = new Container($xmlWriter, $element); $containerWriter->write(); $this->writeClosingWP(); }
/** * Write element */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); $xmlWriter->startElement('text:p'); $containerWriter = new Container($xmlWriter, $element); $containerWriter->write(); $xmlWriter->endElement(); }
/** * Runs the migrations for devise in our sqlite memory db * * @return void */ public static function runMigrations() { $migrations = static::$application->make('migration.repository'); if (!$migrations->repositoryExists()) { $migrations->createRepository(); } $migrator = static::$application->make('migrator'); $migrator->run(__DIR__ . '/../src/migrations'); }
public function __invoke($object, string $typeName, Container $container) { $object = ($this->callback)(...$container->populateArguments($this->ref, [$object], new InjectionPoint($typeName))) ?? $object; if (!$object instanceof $typeName) { $type = \is_object($object) ? \get_class($object) : \gettype($object); throw new ContextLookupException(\sprintf('Decorator must return an instance of %s, returned value is %s', $typeName, $type)); } return $object; }
public function testGettingImageStorage() { eval($this->compiler->compile()); /** @var \Nette\DI\Container $container */ $container = new Container(); $this->assertNotNull($class = $container->getByType(\WebChemistry\Images\IImageStorage::class)); $this->assertInstanceOf(\WebChemistry\Images\IImageStorage::class, $class); $this->assertInstanceOf(\WebChemistry\Images\AbstractStorage::class, $class); }
public function testSingletonWithPersistence() { $container = new Container(); $container->singleton('mySingleton', '\\stdClass'); $stdClass = $container->build('mySingleton'); $stdClass->testVar = 'value'; $stdClass2 = $container->build('mySingleton'); $this->assertEquals('value', $stdClass2->testVar); }
public function __construct() { parent::__construct(); $this->path = __DIR__ . '/../../../../../../www/imobiliaria/arquivos/imoveis/img/'; if (!isset($this->sessao)) { $this->sessao = new Sessao('ip' . str_replace('.', '_', $_SERVER['REMOTE_ADDR'])); $this->sessao->setExpirationSeconds(86400); //24h to expire } }