本文整理汇总了PHP中Properties::fromString方法的典型用法代码示例。如果您正苦于以下问题:PHP Properties::fromString方法的具体用法?PHP Properties::fromString怎么用?PHP Properties::fromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Properties
的用法示例。
在下文中一共展示了Properties::fromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
/**
* Main
*
* Exitcodes used:
* <ul>
* <li>127: Archive referenced in -xar [...] does not exist</li>
* <li>126: No manifest or manifest does not have a main-class</li>
* </ul>
*
* @see http://tldp.org/LDP/abs/html/exitcodes.html
* @param string[] args
* @return int
*/
public static function main(array $args)
{
// Open archive
$f = new File(array_shift($args));
if (!$f->exists()) {
Console::$err->writeLine('*** Cannot find archive ' . $f->getURI());
return 127;
}
// Register class loader
$cl = ClassLoader::registerLoader(new ArchiveClassLoader(new Archive($f)));
if (!$cl->providesResource(self::MANIFEST)) {
Console::$err->writeLine('*** Archive ' . $f->getURI() . ' does not have a manifest');
return 126;
}
// Load manifest
$pr = Properties::fromString($cl->getResource(self::MANIFEST));
if (NULL === ($class = $pr->readString('archive', 'main-class', NULL))) {
Console::$err->writeLine('*** Archive ' . $f->getURI() . '\'s manifest does not have a main class');
return 126;
}
// Run main()
try {
return XPClass::forName($class, $cl)->getMethod('main')->invoke(NULL, array($args));
} catch (TargetInvocationException $e) {
throw $e->getCause();
}
}
示例2: prepare
/**
* Prepare "environment" for invocation on bean method. Configures
* the PropertyManager (always), the Logger (if log.ini has been provided
* with the bean) and ConnectionManager (if database.ini has been provided
* with the bean).
*
*/
protected function prepare()
{
if ($this->configuration['log.ini']) {
Logger::getInstance()->configure(Properties::fromString($this->configuration['cl']->getResource('etc/log.ini')));
}
if ($this->configuration['database.ini']) {
ConnectionManager::getInstance()->configure(Properties::fromString($this->configuration['cl']->getResource('etc/database.ini')));
}
}
示例3: instanceWith
/**
* Returns an instance with a given number of DSNs
*
* @param [:string] dsns
* @return rdbms.ConnectionManager
*/
protected function instanceWith($dsns)
{
$properties = '';
foreach ($dsns as $name => $dsn) {
$properties .= '[' . $name . "]\ndsn=\"" . $dsn . "\"\n";
}
$cm = ConnectionManager::getInstance();
$cm->configure(Properties::fromString($properties));
return $cm;
}
示例4: setUp
/**
* Set up testcase
*
*/
public function setUp()
{
$this->dsn = Properties::fromString($this->getClass()->getPackage()->getResource('database.ini'))->readString($this->_dsn(), 'dsn', NULL);
if (NULL === $this->dsn) {
throw new PrerequisitesNotMetError('No credentials for ' . $this->getClassName());
}
try {
$this->conn = DriverManager::getConnection($this->dsn);
} catch (Throwable $t) {
throw new PrerequisitesNotMetError($t->getMessage(), $t);
}
}
示例5: setUp
/**
* Sets up test case
*
*/
public function setUp()
{
$this->dsn = Properties::fromString($this->getClass()->getPackage()->getResource('database.ini'))->readString($this->_dsn(), 'dsn', NULL);
if (NULL === $this->dsn) {
throw new PrerequisitesNotMetError('No credentials for ' . $this->getClassName());
}
try {
$this->dropTables();
$this->createTables();
} catch (Throwable $e) {
throw new PrerequisitesNotMetError($e->getMessage(), $e);
}
}
示例6: scanDeployments
/**
* Get a list of deployments
*
* @return remote.server.deploy.Deployable[]
*/
public function scanDeployments()
{
clearstatcache();
$this->changed = FALSE;
while ($entry = $this->folder->getEntry()) {
if (!preg_match($this->pattern, $entry)) {
continue;
}
$f = new File($this->folder->getURI() . $entry);
if (isset($this->files[$entry]) && $f->lastModified() <= $this->files[$entry]) {
// File already deployed
continue;
}
$this->changed = TRUE;
$ear = new Archive(new File($this->folder->getURI() . $entry));
try {
$ear->open(ARCHIVE_READ) && ($meta = $ear->extract('META-INF/bean.properties'));
} catch (Throwable $e) {
$this->deployments[$entry] = new IncompleteDeployment($entry, $e);
continue;
}
$prop = Properties::fromString($meta);
$beanclass = $prop->readString('bean', 'class');
if (!$beanclass) {
$this->deployments[$entry] = new IncompleteDeployment($entry, new FormatException('bean.class property missing!'));
continue;
}
$d = new Deployment($entry);
$d->setClassLoader(new ArchiveClassLoader($ear));
$d->setImplementation($beanclass);
$d->setInterface($prop->readString('bean', 'remote'));
$d->setDirectoryName($prop->readString('bean', 'lookup'));
$this->deployments[$entry] = $d;
$this->files[$entry] = time();
delete($f);
}
// Check existing deployments
foreach (array_keys($this->deployments) as $entry) {
$f = new File($this->folder->getURI() . $entry);
if (!$f->exists()) {
unset($this->deployments[$entry], $this->files[$entry]);
$this->changed = TRUE;
}
delete($f);
}
$this->folder->close();
return $this->changed;
}
示例7: run
//.........这里部分代码省略.........
$context->setResource(NULL);
$context->setParams($params->string);
}
$instance = $class->newInstance();
$instance->in = self::$in;
$instance->out = self::$out;
$instance->err = self::$err;
$methods = $class->getMethods();
// Injection
foreach ($methods as $method) {
if (!$method->hasAnnotation('inject')) {
continue;
}
$inject = $method->getAnnotation('inject');
if (isset($inject['type'])) {
$type = $inject['type'];
} else {
if ($restriction = $method->getParameter(0)->getTypeRestriction()) {
$type = $restriction->getName();
} else {
$type = $method->getParameter(0)->getType()->getName();
}
}
try {
switch ($type) {
case 'rdbms.DBConnection':
$args = array($cm->getByHost($inject['name'], 0));
break;
case 'util.Properties':
$p = $pm->getProperties($inject['name']);
// If a PropertyAccess is retrieved which is not a util.Properties,
// then, for BC sake, convert it into a util.Properties
if ($p instanceof PropertyAccess && !$p instanceof Properties) {
$convert = Properties::fromString('');
$section = $p->getFirstSection();
while ($section) {
// HACK: Properties::writeSection() would first attempts to
// read the whole file, we cannot make use of it.
$convert->_data[$section] = $p->readSection($section);
$section = $p->getNextSection();
}
$args = array($convert);
} else {
$args = array($p);
}
break;
case 'util.log.LogCategory':
$args = array($l->getCategory($inject['name']));
break;
default:
self::$err->writeLine('*** Unknown injection type "' . $type . '" at method "' . $method->getName() . '"');
return 2;
}
$method->invoke($instance, $args);
} catch (TargetInvocationException $e) {
self::$err->writeLine('*** Error injecting ' . $type . ' ' . $inject['name'] . ': ' . $e->getCause()->compoundMessage());
return 2;
} catch (Throwable $e) {
self::$err->writeLine('*** Error injecting ' . $type . ' ' . $inject['name'] . ': ' . $e->compoundMessage());
return 2;
}
}
// Arguments
foreach ($methods as $method) {
if ($method->hasAnnotation('args')) {
// Pass all arguments
示例8: mappingWithoutCorrespondingSection
public function mappingWithoutCorrespondingSection()
{
with($p = Properties::fromString(''));
$p->writeSection('app');
$p->writeString('app', 'map.service', '/service');
create(new xp·scriptlet·WebConfiguration($p))->mappedApplications();
}
示例9: memoryPropertiesAlwaysHavePrecendenceInCompositeProperties
public function memoryPropertiesAlwaysHavePrecendenceInCompositeProperties()
{
$fixture = $this->preconfigured();
$this->assertEquals('value', $fixture->getProperties('example')->readString('section', 'key'));
$fixture->register('example', Properties::fromString('[section]
key="overwritten value"'));
$this->assertEquals('overwritten value', $fixture->getProperties('example')->readString('section', 'key'));
}
示例10: injectCompositeProperties
public function injectCompositeProperties()
{
$command = newinstance('util.cmd.Command', array(), '{
#[@inject(name= "debug")]
public function setTrace(Properties $prop) {
$this->out->write("Have ", $prop->readString("section", "key"));
}
public function run() {
// Intentionally empty
}
}');
$this->runWith(array($command->getClassName()), '', array(new RegisteredPropertySource('debug', Properties::fromString('[section]
key=overwritten_value')), new FilesystemPropertySource(__DIR__)));
$this->assertEquals('', $this->err->getBytes());
$this->assertEquals('Have overwritten_value', $this->out->getBytes());
}
示例11: equalsReturnsTrueForSameInnerPropertiesAndName
public function equalsReturnsTrueForSameInnerPropertiesAndName()
{
$p1 = new RegisteredPropertySource('name1', Properties::fromString('[section]'));
$p2 = new RegisteredPropertySource('name1', Properties::fromString('[section]'));
$this->assertEquals($p1, $p2);
}
示例12: newPropertiesFrom
/**
* Create a new properties object from a string source
*
* @param string source
* @return util.Properties
*/
protected function newPropertiesFrom($source)
{
return Properties::fromString($source);
}
示例13: configureWithContext
public function configureWithContext()
{
$this->logger->configure(Properties::fromString(trim('
[context]
appenders="util.log.FileAppender"
context="util.log.context.NestedLogContext"
appender.util.log.FileAppender.params="filename"
appender.util.log.FileAppender.param.filename="/var/log/xp/default.log"
')));
with($cat = $this->logger->getCategory('context'));
$this->assertTrue($cat->hasContext());
$this->assertInstanceOf('util.log.context.NestedLogContext', $cat->getContext());
}
示例14: addingToCompositeResetsIterationPointer
public function addingToCompositeResetsIterationPointer()
{
$fixture = $this->getThirdSection();
$fixture->add(Properties::fromString('[unknown]'));
$this->assertEquals(NULL, $fixture->getNextSection());
}
示例15: noApplication
public function noApplication()
{
with($p = Properties::fromString(''));
$p->writeSection('app');
$p->writeString('app', 'map.service', '/service');
$p->writeSection('app::service');
$r = new xp新criptlet愛unner('/htdocs');
$r->configure($p);
$r->applicationAt('/');
}