Config PHP Class Code Examples

This page contains top rated real world PHP examples of class Config extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: ConfiguratorTest.php Project: mickaelsteinberg/BackBee
0
 /**
  * test extend application config with and without context and environment.
  *
  * @covers ::__construct
  * @covers ::extend
  * @covers ::doApplicationConfigExtend
  */
 public function testExtendApplicationConfig()
 {
     $this->application->setBB_Dir(__DIR__ . '/ConfiguratorTest_Resources/bbdir');
     $this->application->setBase_Repository(__DIR__ . '/ConfiguratorTest_Resources/repository');
     $this->application->setOverrided_Config(false);
     // Test without context and without environment
     $config = new Config($this->application->getBBDir());
     $this->assertEquals(array('parameters' => array('base_directory' => 'bbdir', 'context' => 'default', 'environment' => '')), $config->getAllSections());
     $config_builder = new Configurator($this->application, $this->bundleLoader);
     $config_builder->extend(Configurator::APPLICATION_CONFIG, $config);
     $this->assertEquals(array('parameters' => array('base_directory' => 'repository', 'context' => 'default', 'environment' => '', 'foo' => 'bar')), $config->getAllSections());
     // Test with context and without environment
     $this->application->setContext('api');
     $config = new Config($this->application->getBBDir());
     $config_builder = new Configurator($this->application, $this->bundleLoader);
     $config_builder->extend(Configurator::APPLICATION_CONFIG, $config);
     $this->assertEquals(array('parameters' => array('base_directory' => 'repository', 'context' => 'api', 'environment' => '', 'foo' => 'bar', 'bar' => 'foo')), $config->getAllSections());
     // Test with context and with environment; test also with override config setted at true
     $this->application->setContext('api');
     $this->application->setEnvironment('preprod');
     $this->application->setOverrided_Config(true);
     $config = new Config($this->application->getBBDir());
     $config_builder = new Configurator($this->application, $this->bundleLoader);
     $config_builder->extend(Configurator::APPLICATION_CONFIG, $config);
     $this->assertEquals(array('parameters' => array('context' => 'api', 'environment' => 'preprod', 'overrided_config' => true)), $config->getAllSections());
 }
Example #2
Show file File: ConfigTests.php Project: mechiko/staff-october
0
 public function testGet()
 {
     $config = new Config();
     $this->assertFalse($config->has('setting'));
     $this->assertNull($config->get('setting'));
     $config->set('setting', 'value');
     $this->assertEquals('value', $config->get('setting'));
     $fallback = new Config(['fallback_setting' => 'fallback_value']);
     $config->setFallback($fallback);
     $this->assertEquals('fallback_value', $config->get('fallback_setting'));
 }
Example #3
Show file File: DynamicFieldsExtensionTest.php Project: Maksold/platform
0
 protected function setExpectationForGetFields($className, $fieldName, $fieldType)
 {
     $fieldId = new FieldConfigId('entity', $className, $fieldName, $fieldType);
     $extendConfig = new Config(new FieldConfigId('extend', $className, $fieldName, $fieldType));
     $extendConfig->set('owner', ExtendScope::OWNER_CUSTOM);
     $extendConfig->set('state', ExtendScope::STATE_ACTIVE);
     $extendConfig->set('is_deleted', false);
     $datagridConfig = new Config(new FieldConfigId('datagrid', $className, $fieldName, $fieldType));
     $datagridConfig->set('is_visible', true);
     $this->configManager->expects($this->once())->method('hasConfig')->with($className)->will($this->returnValue(true));
     $this->entityConfigProvider->expects($this->once())->method('getIds')->with($className)->will($this->returnValue([$fieldId]));
     $this->extendConfigProvider->expects($this->once())->method('getConfigById')->with($this->identicalTo($fieldId))->will($this->returnValue($extendConfig));
     $this->datagridConfigProvider->expects($this->once())->method('getConfigById')->with($this->identicalTo($fieldId))->will($this->returnValue($datagridConfig));
 }
Example #4
Show file File: Application.php Project: control-corp/brands
0
 /**
  * Constructor
  * @param array | string $config
  * @throws CoreException
  */
 public function __construct($config, $name = 'app')
 {
     if (is_array($config)) {
         $config = new Config($config);
     } elseif (is_string($config) && file_exists($config)) {
         $config = new Config(include $config);
     } else {
         if (!$config instanceof Config) {
             throw new CoreException('[' . __METHOD__ . '] Config param must be valid file or array', 500);
         }
     }
     $this->set('config', $config);
     static::setInstance($name, $this);
 }
Example #5
Show file File: RelationBuilderTest.php Project: Maksold/platform
0
 public function testAddManyToOneRelationTargetSide()
 {
     $relationName = 'testRelation';
     $relationKey = 'manyToOne|Test\\SourceEntity|Test\\TargetEntity|testRelation';
     $extendConfig = new Config(new EntityConfigId('extend', self::TARGET_CLASS));
     $expectedExtendConfig = new Config(new EntityConfigId('extend', self::TARGET_CLASS));
     $expectedExtendConfig->set('relation', [$relationKey => ['target_field_id' => new FieldConfigId('extend', self::SOURCE_CLASS, $relationName, 'manyToOne'), 'owner' => false, 'target_entity' => self::SOURCE_CLASS, 'field_id' => false]]);
     $extendConfigProvider = $this->getConfigProviderMock();
     $extendConfigProvider->expects($this->once())->method('getConfig')->with(self::TARGET_CLASS)->will($this->returnValue($extendConfig));
     $this->configManager->expects($this->once())->method('persist')->with($this->identicalTo($extendConfig));
     $this->configManager->expects($this->any())->method('getProvider')->will($this->returnValueMap([['extend', $extendConfigProvider]]));
     $this->builder->addManyToOneRelationTargetSide(self::TARGET_CLASS, self::SOURCE_CLASS, $relationName, $relationKey);
     $this->assertEquals($expectedExtendConfig, $extendConfig);
 }
Example #6
Show file File: ExtendEntityAliasProviderTest.php Project: Maksold/platform
0
 /**
  * @dataProvider customEntityDataProvider
  */
 public function testGetEntityAliasForCustomEntity($entityClass, $expectedAlias)
 {
     $enumConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $enumConfig = new Config(new EntityConfigId('enum', $entityClass));
     $groupingConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $groupingConfig = new Config(new EntityConfigId('grouping', $entityClass));
     $this->configManager->expects($this->once())->method('hasConfig')->with($entityClass)->willReturn(true);
     $this->configManager->expects($this->exactly(2))->method('getProvider')->willReturnMap([['enum', $enumConfigProvider], ['grouping', $groupingConfigProvider]]);
     $enumConfigProvider->expects($this->once())->method('getConfig')->with($entityClass)->willReturn($enumConfig);
     $groupingConfigProvider->expects($this->once())->method('getConfig')->with($entityClass)->willReturn($groupingConfig);
     $result = $this->entityAliasProvider->getEntityAlias($entityClass);
     $this->assertEntityAlias($expectedAlias, $result);
 }
Example #7
Show file File: ConfigTest.php Project: aisuhua/phalcon-php
0
 public function testMerge()
 {
     //Simple merge
     $configA = new \Phalcon\Config(array('a' => 'b', 'c' => array('d', 'e')));
     $configB = new \Phalcon\Config(array('c' => 'f', 'g' => 'h'));
     $configA->merge($configB);
     $this->assertEquals($configA->toArray(), array('a' => 'b', 'c' => 'f', 'g' => 'h'));
     //Inherited merge
     $configC = new \Phalcon\Config(array('a' => new \Phalcon\Config(array('b' => 'c'))));
     $configD = new \Phalcon\Config(array('a' => new \Phalcon\Config(array('d' => 'e')), 'f' => new \Phalcon\Config(array('g' => 'h'))));
     $configC->merge($configD);
     $this->assertEquals($configC->toArray(), array('a' => array('b' => 'c', 'd' => 'e'), 'f' => array('g' => 'h')));
 }
Example #8
Show file File: classes.php Project: dakusinio/Sale
0
 public function GetAccesToken()
 {
     $conf = null;
     if ($_GET['password']) {
         $conf = new Config('kamil', $_GET['password']);
         return $conf;
     }
     if ($_SESSION['password']) {
         $conf = new Config('kamil', $_SESSION['password']);
         return $conf;
     }
     return $conf;
 }
Example #9
Show file File: ActivityManagerTest.php Project: Maksold/platform
0
 /**
  * Test that activity action is not returned id activity is enabled on UI but schema update is not performed yet
  */
 public function testGetActivityActionsNoSchemaUpdate()
 {
     $targetEntityClass = 'Test\\Entity';
     $activityClass = 'Test\\Activity';
     $targetEntityActivityConfig = new Config(new EntityConfigId('activity', $targetEntityClass));
     $targetEntityActivityConfig->set('activities', [$activityClass]);
     $activityExtendConfig = new Config(new EntityConfigId('extend', $activityClass));
     $activityExtendConfig->set('relation', []);
     $this->activityConfigProvider->expects($this->once())->method('getConfig')->with($targetEntityClass, null)->will($this->returnValue($targetEntityActivityConfig));
     $this->extendConfigProvider->expects($this->once())->method('getConfig')->with($activityClass, null)->will($this->returnValue($activityExtendConfig));
     $this->entityConfigProvider->expects($this->never())->method('getConfig');
     $this->assertEquals([], $this->manager->getActivityActions($targetEntityClass));
 }
Example #10
Show file File: Plugin.php Project: Spark-Eleven/revive-adserver
0
 /**
  * A method to write the configuration file for plugin. Also creates "fake"
  * configuration files when required by multi-host installations.
  *
  * @static
  * @param array $aConfig The configuration array to save as a configuration file.
  * @param string $module The plugin module name (i.e. /plugins/module directory).
  * @param string $package An optional plugin package name (i.e. /plugins/module/package
  *                        directory). If not given, writes the module level
  *                        configuration file path.
  * @param string $name An optional plugin name (i.e. /plugins/module/package/plugin.plugin.php).
  *                     If not given, writes the package level configuration file, or
  *                     the module level configuration file, depending on the $package
  *                     parameter.
  * @return boolean True on success, false otherwise.
  */
 function writePluginConfig($aConfig, $module, $package = null, $name = null)
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     // Prepare the config file for writing, using the delivery engine
     // host as the hostname for the "real" config file
     $url = @parse_url('http://' . $conf['webpath']['delivery']);
     if (!isset($url['host'])) {
         return false;
     }
     $deliveryHost = $url['host'];
     $configFileName = MAX_Plugin::getConfigFileName($module, $package, $name, false, $deliveryHost);
     if (!file_exists($configFileName)) {
         MAX_Plugin::copyDefaultConfig($module, $package, $name);
     }
     // Create a new config class, parse the config array, and write to disk
     $oConfig = new Config();
     $oConfig->parseConfig($aConfig, 'phpArray');
     $result = $oConfig->writeConfig($configFileName, 'inifile');
     if ($result == false || PEAR::isError($result)) {
         return false;
     }
     // Check the other possible host names, and write out the fake
     // configuration files if different
     $url = @parse_url('http://' . $conf['webpath']['admin']);
     if (isset($url['host'])) {
         $adminHost = $url['host'];
         if ($adminHost != $deliveryHost) {
             // Create fake file for this host
             $configFileName = MAX_Plugin::getConfigFileName($module, $package, $name, false, $adminHost);
             $aConfig = array('realConfig' => $deliveryHost);
             $oConfig = new Config();
             $oConfig->parseConfig($aConfig, 'phpArray');
             if (!$oConfig->writeConfig($configFileName, 'inifile')) {
                 return false;
             }
         }
     }
     $url = @parse_url('http://' . $conf['webpath']['deliverySSL']);
     if (isset($url['host'])) {
         $deliverySslHost = $url['host'];
         if ($deliverySslHost != $deliveryHost) {
             // Create fake file for this host
             $configFileName = MAX_Plugin::getConfigFileName($module, $package, $name, false, $deliverySslHost);
             $aConfig = array('realConfig' => $deliveryHost);
             $oConfig = new Config();
             $oConfig->parseConfig($aConfig, 'phpArray');
             if (!$oConfig->writeConfig($configFileName, 'inifile')) {
                 return false;
             }
         }
     }
     return true;
 }
Example #11
Show file File: ConfigTests.php Project: xamiro-dev/xamiro
0
 public function testGet()
 {
     $config = new Config();
     $this->assertNull($config->get('setting'));
     $config->set('setting', 'value');
     $this->assertEquals('value', $config->get('setting'));
     $fallback = new Config(array('fallback_setting' => 'fallback_value'));
     $config->setFallback($fallback);
     $this->assertEquals('fallback_value', $config->get('fallback_setting'));
 }
Example #12
Show file File: configtest.php Project: enoch85/owncloud-testserver
0
 /**
  * @dataProvider isEnabledData
  */
 public function testIsEnabled($isEnabled)
 {
     $config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock();
     $userSession = $this->getMockBuilder('\\OCP\\IUserSession')->disableOriginalConstructor()->getMock();
     $user = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock();
     if ($isEnabled === true) {
         $user->expects($this->once())->method('getUID')->will($this->returnValue('user123'));
         $userSession->expects($this->once())->method('getUser')->will($this->returnValue($user));
         $config->expects($this->once())->method('getUserValue')->with('user123', 'firstrunwizard', 'show', 1)->will($this->returnValue(1));
         $c = new Config($config, $userSession);
         $this->assertEquals(true, $c->isEnabled());
     } elseif ($isEnabled === false) {
         $user->expects($this->once())->method('getUID')->will($this->returnValue('user123'));
         $userSession->expects($this->once())->method('getUser')->will($this->returnValue($user));
         $config->expects($this->once())->method('getUserValue')->with('user123', 'firstrunwizard', 'show', 1)->will($this->returnValue(0));
         $c = new Config($config, $userSession);
         $this->assertEquals(false, $c->isEnabled());
     } elseif ($isEnabled === null) {
         $userSession->expects($this->once())->method('getUser')->will($this->returnValue(null));
         $user->expects($this->never())->method('getUID');
         $config->expects($this->never())->method('getUserValue');
         $c = new Config($config, $userSession);
         $this->assertEquals(false, $c->isEnabled());
     }
 }
Example #13
Show file File: FieldConfigStorage.php Project: papillon-cendre/d8
0
 /**
  * {@inheritdoc}
  */
 public function importDelete($name, Config $new_config, Config $old_config)
 {
     // If the field storage has been deleted in the same import, the field will
     // be deleted by then, and there is nothing left to do. Just return TRUE so
     // that the file does not get written to active store.
     if (!$old_config->get()) {
         return TRUE;
     }
     return parent::importDelete($name, $new_config, $old_config);
 }
Example #14
Show file File: ConfigSubscriberTest.php Project: Maksold/platform
0
 /**
  * @dataProvider postSubmitProvider
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testPostSubmit($data, $isValid, $model, $trans, $expectedConfigData, $expectedTrans)
 {
     $provider1 = $this->getConfigProvider('entity', ['entity' => ['items' => ['icon' => [], 'label' => ['options' => ['translatable' => true]]]]], isset($data['entity']));
     $config1 = new Config(new EntityConfigId('entity', 'Entity\\Test'));
     $config1->set('label', 'label_key');
     if (isset($data['entity'])) {
         $provider1->expects($this->once())->method('getConfigById')->with($config1->getId())->will($this->returnValue($config1));
     } else {
         $provider1->expects($this->never())->method('getConfigById');
     }
     $providers = new ArrayCollection();
     $providers->add($provider1);
     $this->configManager->expects($this->any())->method('getConfigIdByModel')->will($this->returnCallback(function ($configModel, $scope) {
         return new EntityConfigId($scope, 'Entity\\Test');
     }));
     $this->translator->expects($this->any())->method('trans')->will($this->returnCallback(function ($id) use(&$trans) {
         if (isset($trans[$id])) {
             return $trans[$id];
         } else {
             return $id;
         }
     }));
     $form = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface');
     $event = $this->getFormEvent($data, $model, $form);
     $this->configManager->expects($this->once())->method('getProviders')->will($this->returnValue($providers));
     if (null === $expectedConfigData) {
         $this->configManager->expects($this->never())->method('persist');
     } else {
         $expectedConfig = new Config(new EntityConfigId('entity', 'Entity\\Test'));
         foreach ($expectedConfigData as $code => $val) {
             $expectedConfig->set($code, $val);
         }
         $this->configManager->expects($this->once())->method('persist')->with($expectedConfig);
     }
     $form->expects($this->once())->method('isValid')->will($this->returnValue($isValid));
     if (null === $expectedTrans) {
         $this->translator->expects($this->never())->method('getLocale');
         $this->dbTranslationMetadataCache->expects($this->never())->method('updateTimestamp');
     } else {
         $translationEm = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
         $translationValue = new Translation();
         $this->translator->expects($this->once())->method('getLocale')->will($this->returnValue('testLocale'));
         $this->dbTranslationMetadataCache->expects($this->once())->method('updateTimestamp')->with('testLocale');
         $repo = $this->getMockBuilder('Oro\\Bundle\\TranslationBundle\\Entity\\Repository\\TranslationRepository')->disableOriginalConstructor()->getMock();
         $this->doctrine->expects($this->once())->method('getManagerForClass')->with(Translation::ENTITY_NAME)->will($this->returnValue($translationEm));
         $translationEm->expects($this->once())->method('getRepository')->with(Translation::ENTITY_NAME)->will($this->returnValue($repo));
         $repo->expects($this->once())->method('saveValue')->with($expectedTrans[0], $expectedTrans[1], $expectedTrans[2], TranslationRepository::DEFAULT_DOMAIN, Translation::SCOPE_UI)->willReturn($translationValue);
         $translationEm->expects($this->once())->method('flush')->with([$translationValue]);
     }
     if ($isValid) {
         $this->configManager->expects($this->once())->method('flush');
     } else {
         $this->configManager->expects($this->never())->method('flush');
     }
     $this->subscriber->postSubmit($event);
 }
Example #15
Show file File: Manager.php Project: bbeckman/NDL-VuFind2
0
 /**
  * Constructor.
  *
  * Add file cache for record descriptions loaded from external sources.
  *
  * @param Config $config       Main VuFind configuration
  * @param Config $searchConfig Search configuration
  */
 public function __construct(Config $config, Config $searchConfig)
 {
     parent::__construct($config, $searchConfig);
     $cacheBase = $this->getCacheDir();
     $ids = ['feed', 'description', 'organisation-info', 'stylesheet'];
     foreach ($ids as $cache) {
         $this->createFileCache($cache, $cacheBase . $cache . 's');
     }
 }
Example #16
Show file File: UnitTest.php Project: starsw001/cphalcon
0
 public function testConfigMerge()
 {
     $config1 = new \Phalcon\Config(array("controllersDir" => "../x/y/z", "modelsDir" => "../x/y/z", "database" => array("adapter" => "Mysql", "host" => "localhost", "username" => "scott", "password" => "cheetah", "name" => "test_db", "charset" => array("primary" => "utf8"), "alternatives" => array("primary" => "latin1", "second" => "latin1"))));
     $config2 = new \Phalcon\Config(array("modelsDir" => "../x/y/z", "database" => array("adapter" => "Postgresql", "host" => "localhost", "username" => "peter", "options" => array("case" => "lower"), "alternatives" => array("primary" => "swedish", "third" => "american"))));
     $config1->merge($config2);
     $expected = \Phalcon\Config::__set_state(array('controllersDir' => '../x/y/z', 'modelsDir' => '../x/y/z', 'database' => \Phalcon\Config::__set_state(array('adapter' => 'Postgresql', 'host' => 'localhost', 'username' => 'peter', 'password' => 'cheetah', 'name' => 'test_db', 'charset' => \Phalcon\Config::__set_state(array('primary' => 'utf8')), 'alternatives' => \Phalcon\Config::__set_state(array('primary' => 'swedish', 'second' => 'latin1', 'third' => 'american')), 'options' => \Phalcon\Config::__set_state(array('case' => 'lower'))))));
     $this->assertEquals($expected, $config1);
 }
Example #17
Show file File: IndexEntityConfigDumperExtensionTest.php Project: Maksold/platform
0
 public function testPreUpdateForNoChanges()
 {
     $config = new Config(new EntityConfigId('extend', 'Test\\Entity1'));
     $config->set('is_extend', true);
     $config->set('index', ['field1' => true]);
     $fieldConfig1 = new Config(new FieldConfigId('extend', $config->getId()->getClassName(), 'field1', 'string'));
     $fieldConfig1->set('is_extend', true);
     $fieldConfig2 = new Config(new FieldConfigId('extend', $config->getId()->getClassName(), 'field2', 'string'));
     $fieldConfig2->set('is_extend', true);
     $datagridFieldConfig1 = new Config(new FieldConfigId('datagrid', $config->getId()->getClassName(), 'field1', 'string'));
     $datagridFieldConfig1->set('is_visible', true);
     $datagridFieldConfig2 = new Config(new FieldConfigId('datagrid', $config->getId()->getClassName(), 'field2', 'string'));
     $extendConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $datagridConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $this->configManager->expects($this->exactly(4))->method('getProvider')->will($this->returnValueMap([['extend', $extendConfigProvider], ['datagrid', $datagridConfigProvider]]));
     $extendConfigProvider->expects($this->exactly(2))->method('getConfigs')->will($this->returnCallback(function ($className) use($config, $fieldConfig1, $fieldConfig2) {
         if (empty($className)) {
             return [$config];
         }
         return [$fieldConfig1, $fieldConfig2];
     }));
     $datagridConfigProvider->expects($this->at(0))->method('hasConfig')->with($datagridFieldConfig1->getId()->getClassName(), $datagridFieldConfig1->getId()->getFieldName())->will($this->returnValue(true));
     $datagridConfigProvider->expects($this->at(1))->method('getConfig')->with($datagridFieldConfig1->getId()->getClassName(), $datagridFieldConfig1->getId()->getFieldName())->will($this->returnValue($datagridFieldConfig1));
     $datagridConfigProvider->expects($this->at(2))->method('hasConfig')->with($datagridFieldConfig2->getId()->getClassName(), $datagridFieldConfig2->getId()->getFieldName())->will($this->returnValue(true));
     $datagridConfigProvider->expects($this->at(3))->method('getConfig')->with($datagridFieldConfig2->getId()->getClassName(), $datagridFieldConfig2->getId()->getFieldName())->will($this->returnValue($datagridFieldConfig2));
     $this->configManager->expects($this->never())->method('persist');
     $this->extension->preUpdate();
 }
Example #18
Show file File: BuildWorker.php Project: ntoniazzi/PHPCI
0
 /**
  * Start the worker.
  */
 public function startWorker()
 {
     $this->pheanstalk->watch($this->queue);
     $this->pheanstalk->ignore('default');
     $buildStore = Factory::getStore('Build');
     while ($this->run) {
         // Get a job from the queue:
         $job = $this->pheanstalk->reserve();
         $this->checkJobLimit();
         // Get the job data and run the job:
         $jobData = json_decode($job->getData(), true);
         if (!$this->verifyJob($job, $jobData)) {
             continue;
         }
         $this->logger->addInfo('Received build #' . $jobData['build_id'] . ' from Beanstalkd');
         // If the job comes with config data, reset our config and database connections
         // and then make sure we kill the worker afterwards:
         if (!empty($jobData['config'])) {
             $this->logger->addDebug('Using job-specific config.');
             $currentConfig = Config::getInstance()->getArray();
             $config = new Config($jobData['config']);
             Database::reset($config);
         }
         try {
             $build = BuildFactory::getBuildById($jobData['build_id']);
         } catch (\Exception $ex) {
             $this->logger->addWarning('Build #' . $jobData['build_id'] . ' does not exist in the database.');
             $this->pheanstalk->delete($job);
         }
         try {
             // Logging relevant to this build should be stored
             // against the build itself.
             $buildDbLog = new BuildDBLogHandler($build, Logger::INFO);
             $this->logger->pushHandler($buildDbLog);
             $builder = new Builder($build, $this->logger);
             $builder->execute();
             // After execution we no longer want to record the information
             // back to this specific build so the handler should be removed.
             $this->logger->popHandler($buildDbLog);
         } catch (\PDOException $ex) {
             // If we've caught a PDO Exception, it is probably not the fault of the build, but of a failed
             // connection or similar. Release the job and kill the worker.
             $this->run = false;
             $this->pheanstalk->release($job);
         } catch (\Exception $ex) {
             $build->setStatus(Build::STATUS_FAILED);
             $build->setFinished(new \DateTime());
             $build->setLog($build->getLog() . PHP_EOL . PHP_EOL . $ex->getMessage());
             $buildStore->save($build);
             $build->sendStatusPostback();
         }
         // Reset the config back to how it was prior to running this job:
         if (!empty($currentConfig)) {
             $config = new Config($currentConfig);
             Database::reset($config);
         }
         // Delete the job when we're done:
         $this->pheanstalk->delete($job);
     }
 }
Example #19
Show file File: Factory.php Project: rabellamy/flo
0
 /**
  * Creates a Flo instance.
  *
  * @return Flo
  *   A configured Flo instance.
  */
 private function createFlo()
 {
     $flo = new Flo();
     // Get config from env variables or files.
     if ($config_env = getenv('FLO')) {
         $config_env = Yaml::parse($config_env);
         $config = new Config($config_env);
     } else {
         $fs = new Filesystem();
         $user_config = array();
         $user_config_file = getenv("HOME") . '/.config/flo';
         if ($fs->exists($user_config_file)) {
             $user_config = Yaml::parse($user_config_file);
         }
         $project_config = array();
         $process = new Process('git rev-parse --show-toplevel');
         $process->run();
         if ($process->isSuccessful()) {
             $project_config_file = trim($process->getOutput()) . '/flo.yml';
             if ($fs->exists($project_config_file)) {
                 $project_config = Yaml::parse($project_config_file);
             }
         }
         $config = new Config($user_config, $project_config);
     }
     $flo->setConfig($config);
     return $flo;
 }
Example #20
Show file File: ini_class_inc.php Project: ookwudili/chisimba
0
 /**
  * Create config for adm
  *
  */
 public function createAdmConfig($servarray)
 {
     //check for the directory structure
     if (!file_exists($this->objConfig->getcontentBasePath() . 'adm/')) {
         mkdir($this->objConfig->getcontentBasePath() . 'adm/', 0777);
     }
     // write the server list file
     $cfile = $this->objConfig->getcontentBasePath() . 'adm/adm.xml';
     if (!file_exists($cfile)) {
         $conf = new Config_Container('section', 'adm');
         //$servarray['name']);
         $conf_serv =& $conf->createSection($servarray['name']);
         $conf_serv->createDirective('servername', $servarray['name']);
         $conf_serv->createDirective('serverapiurl', $servarray['url']);
         $conf_serv->createDirective('serveremail', $servarray['email']);
         $conf_serv->createDirective('regtime', date('r'));
         $config = new Config();
         $config->setRoot($conf);
         // write the container to an XML document
         $config->writeConfig($cfile, 'XML');
     } else {
         // update the xml with the new server
         $root =& $config->parseConfig($cfile, 'XML', array('name' => 'adm'));
         log_debug($root);
         $conf_serv =& $root->createSection($servarray['name']);
         $conf_serv->createDirective('servername', $servarray['name']);
         $conf_serv->createDirective('serverapiurl', $servarray['url']);
         $conf_serv->createDirective('serveremail', $servarray['email']);
         $conf_serv->createDirective('regtime', date('r'));
         $config = new Config();
         $config->setRoot($root);
         // write the container to an XML document
         $config->writeConfig($cfile, 'XML');
     }
 }
Example #21
Show file File: FlushConfigManagerTest.php Project: Maksold/platform
0
 public function testFlush()
 {
     $model = new EntityConfigModel(self::ENTITY_CLASS);
     $entityConfigId = new EntityConfigId('entity', self::ENTITY_CLASS);
     $entityConfig = new Config($entityConfigId);
     $entityConfig->set('icon', 'test_icon');
     $entityConfig->set('label', 'test_label');
     $entityPropertyConfig = new PropertyConfigContainer(['entity' => ['items' => ['icon' => [], 'label' => ['options' => ['indexed' => true]]]]]);
     $this->entityConfigProvider->expects($this->once())->method('getPropertyConfig')->will($this->returnValue($entityPropertyConfig));
     $testConfigId = new EntityConfigId('test', self::ENTITY_CLASS);
     $testConfig = new Config($testConfigId);
     $testConfig->set('attr1', 'test_attr1');
     $testPropertyConfig = new PropertyConfigContainer(['entity' => ['items' => ['attr1' => []]]]);
     $this->testConfigProvider->expects($this->once())->method('getPropertyConfig')->will($this->returnValue($testPropertyConfig));
     $this->modelManager->expects($this->once())->method('getEntityModel')->with($entityConfigId->getClassName())->will($this->returnValue($model));
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->modelManager->expects($this->any())->method('getEntityManager')->will($this->returnValue($em));
     $this->setFlushExpectations($em, [$model]);
     $this->eventDispatcher->expects($this->at(2))->method('dispatch')->with(Events::PRE_FLUSH, new PreFlushConfigEvent(['entity' => $entityConfig, 'test' => $testConfig], $this->configManager));
     $this->configManager->persist($entityConfig);
     $this->configManager->persist($testConfig);
     $this->configManager->flush();
     $this->assertEquals(['icon' => 'test_icon', 'label' => 'test_label'], $model->toArray('entity'));
     $this->assertEquals(['attr1' => 'test_attr1'], $model->toArray('test'));
     $this->assertCount(3, $model->getIndexedValues());
     $this->assertEquals('entity_config', $model->getIndexedValues()[0]->getScope());
     $this->assertEquals('module_name', $model->getIndexedValues()[0]->getCode());
     $this->assertEquals('entity_config', $model->getIndexedValues()[1]->getScope());
     $this->assertEquals('entity_name', $model->getIndexedValues()[1]->getCode());
     $this->assertEquals('entity', $model->getIndexedValues()[2]->getScope());
     $this->assertEquals('label', $model->getIndexedValues()[2]->getCode());
 }
Example #22
Show file File: TalkControllerTest.php Project: hilltool/opencfp
0
 protected function setup()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     ob_start();
     $this->app->run();
     ob_end_clean();
     // Override things so that Spot2 is using in-memory tables
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $this->app['spot'] = new \Spot\Locator($cfg);
     // Initialize the talk table in the sqlite database
     $talk_mapper = $this->app['spot']->mapper('OpenCFP\\Domain\\Entity\\Talk');
     $talk_mapper->migrate();
     // Set things up so Sentry believes we're logged in
     $user = m::mock('StdClass');
     $user->shouldReceive('getId')->andReturn(uniqid());
     $user->shouldReceive('getLogin')->andReturn(uniqid() . '@grumpy-learning.com');
     // Create a test double for Sentry
     $sentry = m::mock('StdClass');
     $sentry->shouldReceive('check')->andReturn(true);
     $sentry->shouldReceive('getUser')->andReturn($user);
     $this->app['sentry'] = $sentry;
     // Create a test double for sessions so we can control what happens
     $this->app['session'] = new SessionDouble();
     // Create our test double for the request object
     $this->req = m::mock('Symfony\\Component\\HttpFoundation\\Request');
 }
Frequently Used Methods