protected function getMethodConfig($methodName) { $methods = $this->options->get(self::OPT_METHODS, array()); if (!isset($methods[$methodName]) || !is_array($methods[$methodName])) { throw new Method\Exception\InvalidAuthenticationMethodException($methodName); } return $methods[$methodName]; }
/** * Returns the serializer adapter. * * @throws Exception\MissingAdapterException * @throws Exception\MissingOptionException * @return \Zend\Serializer\Adapter\AdapterInterface */ public function getAdapter() { if (!$this->_adapter instanceof \Zend\Serializer\Adapter\AdapterInterface) { $adapterConfig = $this->_options->get('adapter'); if (!$adapterConfig) { throw new Exception\MissingAdapterException(); } if (!isset($adapterConfig['name'])) { throw new Exception\MissingOptionException('adapter/name'); } $name = $adapterConfig['name']; $options = array(); if (isset($adapterConfig['options']) && is_array($adapterConfig['options'])) { $options = $adapterConfig['options']; } $this->_adapter = \Zend\Serializer\Serializer::factory($name, $options); } return $this->_adapter; }
/** * Returns raw client data as an array. * * @throws Exception\LoadDataException * @return array */ protected function _loadData() { $jsonFile = $this->_options->get('json_file'); if (!$jsonFile) { throw new Exception\LoadDataException("Missing configuration option 'json_file'"); } if (!file_exists($jsonFile)) { throw new Exception\LoadDataException(sprintf("File not found '%s'", $jsonFile)); } if (!is_file($jsonFile) || !is_readable($jsonFile)) { throw new Exception\LoadDataException(sprintf("Invalid file '%s'", $jsonFile)); } $contents = file_get_contents($jsonFile); if (FALSE === $contents) { throw new Exception\LoadDataException(sprintf("Error reading from file '%s'", $jsonFile)); } try { $data = \Zend\Json\Json::decode($contents, \Zend\Json\Json::TYPE_ARRAY); } catch (\Exception $e) { throw new Exception\LoadDataException(sprintf("Exception while decoding JSON: [%s] %s", get_class($e), $e->getMessage())); } //_dump($data); return $data; }
/** * Returns the required option value. * * @param string $name * @param mixed $defaultValue * @return mixed */ public function getOption($name, $defaultValue = null) { return $this->_options->get($name, $defaultValue); }
public function testSetter() { $options = new Options(); $options->set('foo', 'bar'); $this->assertEquals('bar', $options->get('foo')); }