/** * Creates a syslog connection. * * @param string $configName The name of the configuration to use. * @param \YapepBase\Syslog\ISyslogConnection $connection The Syslog connection to use. * * @todo Remove the possibility to set config options. Use only the set connection [emul] */ public function __construct($configName, \YapepBase\Syslog\ISyslogConnection $connection = null) { $config = Config::getInstance(); $properties = array('applicationIdent', 'facility', 'includeSapiName', 'addPid'); foreach ($properties as $property) { try { $this->configOptions[$property] = $config->get('resource.log.' . $configName . '.' . $property, false); } catch (ConfigException $e) { // We just swallow this because we don't know what properties do we need in advance } } $this->verifyConfig($configName); if ($connection) { $this->connection = $connection; //@codeCoverageIgnoreStart } elseif (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $this->connection = new \YapepBase\Syslog\LegacySyslogConnection(); } else { $this->connection = new \YapepBase\Syslog\NativeSyslogConnection(); } //@codeCoverageIgnoreEnd $ident = $this->configOptions['applicationIdent']; if (isset($this->configOptions['includeSapiName']) && $this->configOptions['includeSapiName']) { $ident .= '-' . PHP_SAPI; } // TODO: Can be dangerous as it can override an already set value [emul] $this->connection->setIdent($ident); $this->connection->setFacility($this->configOptions['facility']); $options = 0; if (isset($this->configOptions['addPid']) && $this->configOptions['addPid']) { $options += \YapepBase\Syslog\ISyslogConnection::LOG_PID; } $this->connection->setOptions($options); $this->connection->open(); }
public function testOptions() { $this->object->setOptions(ISyslogConnection::LOG_PID); $this->assertEquals(ISyslogConnection::LOG_PID, $this->object->getOptions()); }