/** * Returns this user as a GenericUser * * @param \stdClass|array $profile * * @throws \DreamFactory\Oasys\Exceptions\ProviderException * @throws \InvalidArgumentException * @return UserLike */ public function getUserData($profile = null) { $_result = parent::getUserData(); if (empty($_result)) { throw new \InvalidArgumentException('No profile available to convert.'); } if (null === ($_profile = Option::get($_result, 'result'))) { throw new ProviderException('No profile available to convert.'); } // Log::debug( 'Profile retrieved: ' . print_r( $_profile, true ) ); $_profileId = Option::get($_profile, 'id'); $_login = Option::get($_profile, 'login'); $_formatted = Option::get($_profile, 'name', $_login); $_parts = explode(' ', $_formatted); $_name = array('formatted' => $_formatted); if (!empty($_parts)) { if (sizeof($_parts) >= 1) { $_name['givenName'] = $_parts[0]; } if (sizeof($_parts) > 1) { $_name['familyName'] = $_parts[1]; } } return new GenericUser(array('provider_id' => $this->getProviderId(), 'user_id' => $_profileId, 'published' => Option::get($_profile, 'created_at'), 'display_name' => $_formatted, 'name' => $_name, 'email_address' => Option::get($_profile, 'email'), 'preferred_username' => $_login, 'urls' => array(Option::get($_profile, 'url')), 'thumbnail_url' => Option::get($_profile, 'avatar_url'), 'updated' => Option::get($_profile, 'updated_at'), 'relationships' => Option::get($_profile, 'followers'), 'user_data' => $_profile)); }
/** * @param array|\stdClass $payload * * @throws \InvalidArgumentException * @return array|\stdClass|void */ public static function validatePayload($payload) { if (null === Option::get($payload, 'refresh_token')) { throw new \InvalidArgumentException('The "refresh_token" parameter must be specified to use this grant type.'); } return $payload; }
/** * @param string $storageId * @param string $storagePath * @param array $contents * * @return \DreamFactory\Oasys\Stores\FileSystem */ public function __construct($storageId, $storagePath = null, $contents = array()) { $this->_storageId = $storageId; $this->_storagePath = $storagePath ?: Option::get($contents, 'storage_path', rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR), true); $this->_fileName = Option::get($contents, 'file_name', static::KEY_PREFIX . sha1(static::KEY_PREFIX . $storageId), true); parent::__construct($contents); $this->_load(); }
/** * @param \PDO $pdo The PDO instance on which the error occurred * @param \Exception $exception The exception thrown * @param int|mixed|null $code The HTTP response code to use. Defaults to 500 - Internal Server Error * @param mixed $previous The previous exception * @param array $context Additional information for downstream consumers */ public function __construct($pdo, $exception, $code = HttpResponse::InternalServerError, $previous = null, $context = null) { $this->_driverName = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME); $this->_sqlState = Option::get($_info, 0); $this->_driverCode = Option::get($_info, 1); $this->_driverMessage = Option::get($_info, 2); parent::__construct($exception, $code, $previous, $context); }
/** * @param array|\stdClass $payload * * @throws \InvalidArgumentException * @return array|\stdClass|void */ public static function validatePayload($payload) { if (null === Option::get($payload, 'code')) { throw new \InvalidArgumentException('The "code" parameter must be specified to use this grant type.'); } if (null === Option::get($payload, 'redirect_uri')) { throw new \InvalidArgumentException('The "redirect_uri" parameter must be specified to use this grant type.'); } return $payload; }
/** * @param array|\stdClass $payload * * @throws \InvalidArgumentException * @return array|\stdClass|void */ public static function validatePayload($payload) { if (null === Option::get($payload, 'username')) { throw new \InvalidArgumentException('The "username" parameter must be specified to use this grant type.'); } if (null === Option::get($payload, 'password')) { throw new \InvalidArgumentException('The "password" parameter must be specified to use this grant type.'); } return $payload; }
/** * Returns this user as a GenericUser * * * @throws \DreamFactory\Oasys\Exceptions\OasysException * @throws \InvalidArgumentException * @return UserLike */ public function getUserData() { $_response = $this->fetch('/me'); if (HttpResponse::Ok != ($_code = Option::get($_response, 'code'))) { throw new OasysException('Unexpected response code', $_code, null, $_response); } $_profile = Option::get($_response, 'result'); if (empty($_profile)) { throw new \InvalidArgumentException('No profile available to convert.'); } $_profileId = Option::get($_profile, 'id'); $_name = array('formatted' => Option::get($_profile, 'name'), 'familyName' => Option::get($_profile, 'last_name'), 'givenName' => Option::get($_profile, 'first_name')); return new GenericUser(array('user_id' => $_profileId, 'published' => Option::get($_profile, 'updated_time'), 'updated' => Option::get($_profile, 'updated_time'), 'display_name' => $_name['formatted'], 'name' => $_name, 'preferred_username' => Option::get($_profile, 'username'), 'gender' => Option::get($_profile, 'gender'), 'email_address' => Option::get($_profile, 'email'), 'urls' => array(Option::get($_profile, 'link')), 'relationships' => Option::get($_profile, 'friends'), 'thumbnail_url' => $this->_config->getEndpointUrl() . '/' . $_profileId . '/picture?width=150&height=150', 'user_data' => $_profile)); }
/** * @param array $contents * * @throws \DreamFactory\Oasys\Exceptions\OasysException */ public function __construct($contents = array()) { if (!isset($_SESSION) || PHP_SESSION_DISABLED == session_status()) { throw new OasysException('No session active. Session storage not available.'); } $_data = array(); if (null !== ($_parcel = Option::get($_SESSION, static::KEY_PREFIX . '.data'))) { $_data = Storage::defrost($_parcel); } if (is_array($_data)) { $_data = array_merge($_data, $contents); } parent::__construct($_data); }
/** * @param array $schema * @param bool $returnHtml If true, HTML is returned, otherwise an array of fields * * @return string */ protected static function _buildFormFields($schema, $returnHtml = true) { $_form = null; $_fields = array(); foreach ($schema as $_field => $_settings) { // No private fields are ever rendered if (false !== Option::get($_settings, 'private', false)) { continue; } $_value = Option::get($_settings, 'value', Option::get($_settings, 'default')); $_label = Option::get($_settings, 'label', Inflector::display($_field)); $_labelAttributes = Option::get($_settings, 'label_attributes', array('for' => $_field)); $_attributes = array_merge(array('name' => $_field, 'id' => $_field), Option::get($_settings, 'attributes', array())); if (false !== ($_required = Option::get($_settings, 'required', false))) { $_attributes['class'] = HtmlMarkup::addValue(Option::get($_attributes, 'class'), 'required'); } $_form .= HtmlMarkup::label($_labelAttributes, $_label); $_fields[$_field]['label'] = array('value' => $_label, 'attributes' => $_labelAttributes); switch ($_settings['type']) { case 'text': $_form .= HtmlMarkup::tag('textarea', $_attributes, $_value) . PHP_EOL; $_fields[$_field] = array_merge($_fields[$_field], array('type' => 'textarea', 'contents' => $_value), $_attributes); break; case 'select': $_attributes['size'] = Option::get($_settings, 'size', 1); $_attributes['value'] = $_value; $_fields[$_field] = array_merge($_fields[$_field], array('type' => 'select', 'data' => Option::get($_settings, 'options', array())), $_attributes); $_form .= HtmlMarkup::select($_fields[$_field]['data'], $_attributes) . PHP_EOL; break; default: $_attributes['maxlength'] = Option::get($_settings, 'length'); $_attributes['value'] = $_value; $_attributes['type'] = 'text'; $_fields[$_field] = array_merge($_fields[$_field], array('type' => 'input', 'value' => $_value), $_attributes); $_form .= HtmlMarkup::tag('input', $_attributes, null, true, true) . PHP_EOL; break; } } return $returnHtml ? $_form : $_fields; }
/** * Returns this user as a GenericUser * * @return UserLike * @throws OasysException * @throws \InvalidArgumentException */ public function getUserData() { $_response = parent::getUserData(); if (HttpResponse::Ok != ($_code = Option::get($_response, 'code', Curl::getLastHttpCode()))) { throw new OasysException('Unexpected response code', $_code, null, $_response); } $_profile = Option::get($_response, 'result'); if (empty($_profile)) { throw new \InvalidArgumentException('No profile available to convert.'); } $_profileId = Option::get($_profile, 'id'); $_nameGoogle = Option::get($_profile, 'name'); $_name = array('formatted' => Option::get($_profile, 'displayName'), 'familyName' => Option::get($_nameGoogle, 'familyName'), 'givenName' => Option::get($_nameGoogle, 'givenName')); $_email = null; // Get the account email. Google returns a list of emails. foreach (Option::get($_profile, 'emails') as $_emailIteration) { if (Option::get($_emailIteration, 'type') == 'account') { $_email = Option::get($_emailResult, 'value'); break; // ugly, but works } } return new GenericUser(array('user_id' => $_profileId, 'name' => $_name, 'gender' => Option::get($_profile, 'gender'), 'email_address' => $_email, 'urls' => array(Option::get($_profile, 'url')), 'thumbnail_url' => Option::getDeep($_profile, 'image', 'url'), 'user_data' => $_profile)); }
<?php use DreamFactory\Yii\Utility\Pii; use Kisma\Core\Utility\Option; /** * supplies info for the roll your own list */ if (false !== ($_options = Pii::getParam('dashboard.rackspace', false))) { $_featureEnabled = Option::get($_options, 'enabled', false); if ($_featureEnabled) { $_body = <<<HTML <p>Rackspace has no specific image. Instead, install one of our pre-built packages! For Redhat or CentOS flavors, \t\t\t\tsee our <a href="http://wiki.dreamfactory.com/wiki/Packages/Rpm" target="_blank">installation guide</a>. We also have one for Debian/Ubuntu systems <a \t\thref="http://wiki.dreamfactory.com/wiki/Packages/Deb" target="_blank">here</a>.</p> HTML; } else { $_body = <<<HTML <p><strong>This feature is coming soon! Stay tuned!</strong></p> HTML; } return array('id' => 'rackspace', 'title' => 'Rackspace', 'body' => $_body); } return array();
/** * Merges any configuration schema with model data * * @param string $providerId The API name of the provider * @param array $configData * * @return array|null */ protected function _loadConfigSchema($providerId, $configData = array()) { $_schema = null; switch ($providerId) { case 'provider': /** @var Provider $model */ $_schema = Oasys::getProvider($providerId)->getConfig()->getSchema(); break; } // Merge if (!empty($_schema)) { $_config = !empty($configData) ? $configData : array(); // Load the resource into the schema for a goof foreach ($_schema as $_key => $_value) { if (null !== ($_configValue = Option::get($_config, $_key))) { if (is_array($_configValue)) { $_configValue = implode(', ', $_configValue); } $_value['value'] = $_configValue; } $_schema[static::SCHEMA_PREFIX . $_key] = $_value; unset($_schema[$_key]); } } return $_schema; }
/** * Returns the validated URL that has been called to get here * * @param bool $includeQuery If true, query string is included * @param bool $includePath If true, the uri path is included * * @return string */ public static function currentUrl($includeQuery = true, $includePath = true) { // Are we SSL? Check for load balancer protocol as well... $_port = intval(Option::get($_SERVER, 'HTTP_X_FORWARDED_PORT', Option::get($_SERVER, 'SERVER_PORT', 80))); $_protocol = Option::get($_SERVER, 'HTTP_X_FORWARDED_PROTO', 'http' . (Option::getBool($_SERVER, 'HTTPS') ? 's' : null)) . '://'; $_host = Option::get($_SERVER, 'HTTP_X_FORWARDED_HOST', Option::get($_SERVER, 'HTTP_HOST', gethostname())); $_parts = parse_url($_protocol . $_host . Option::get($_SERVER, 'REQUEST_URI')); if ((empty($_port) || !is_numeric($_port)) && null !== ($_parsePort = Option::get($_parts, 'port'))) { $_port = @intval($_parsePort); } if (null !== ($_query = Option::get($_parts, 'query'))) { $_query = static::urlSeparator($_query) . http_build_query(explode('&', $_query)); } if (false !== strpos($_host, ':') || $_protocol == 'https://' && $_port == 443 || $_protocol == 'http://' && $_port == 80) { $_port = null; } else { $_port = ':' . $_port; } if (false !== strpos($_host, ':')) { $_port = null; } $_currentUrl = $_protocol . $_host . $_port . (true === $includePath ? Option::get($_parts, 'path') : null) . (true === $includeQuery ? $_query : null); if (\Kisma::get('debug.curl.current_url')) { Log::debug('Parsed current URL to be: ' . $_currentUrl, $_parts); } return $_currentUrl; }
/** * Fetch a protected resource * * @param string $resource * @param array $payload * @param string $method * @param array $headers * * @throws \DreamFactory\Oasys\Exceptions\OasysConfigurationException * @throws \Kisma\Core\Exceptions\NotImplementedException * @return array */ public function fetch($resource, $payload = array(), $method = self::Get, array $headers = array()) { $_url = $resource; if (false === stripos($_url, 'http://', 0) && false === stripos($_url, 'https://', 0)) { $_endpoint = $this->_config->getEndpoint(EndpointTypes::SERVICE); $payload = array_merge(Option::get($_endpoint, 'parameters', array()), $payload); // Spiffify $_url = rtrim($_endpoint['endpoint'], '/') . '/' . ltrim($resource, '/'); } if (false !== $this->_client->fetch($_url, $payload, $method, $headers)) { $_response = $this->_client->getLastResponse(); $_info = $this->_client->getLastResponseInfo(); return array('result' => $_response, 'info' => $_info, 'code' => $_info['http_code'], 'content_type' => $_info['content_type']); } }
/** * Create/De-cache a provider and return it * * @param string $providerId * @param array|ProviderConfigLike $config * @param bool $createIfNotFound If false and provider not already created, NULL is returned * * @throws \InvalidArgumentException * @return BaseProvider */ protected static function _createProvider($providerId, $config = null, $createIfNotFound = true) { list($_providerId, $_type, $_mapKey, $_generic) = static::_normalizeProviderId($providerId); $_cacheKey = $_mapKey . ($_generic ?: null); if (null === ($_provider = Option::get(static::$_providerCache, $_cacheKey))) { $_config = empty($config) ? array() : $config; // Get the class mapping... if (null === ($_map = Option::get(static::$_classMap, $_mapKey))) { if (null === ($_map = Option::get(static::$_classMap, $_providerId))) { throw new \InvalidArgumentException('The provider "' . $providerId . '" has no associated mapping. Cannot create.'); } } if (true !== $createIfNotFound && array() == $_config) { return null; } if (!empty($_config) && !$_config instanceof ProviderConfigLike && !is_array($_config) && !is_object($_config)) { throw new \InvalidArgumentException('The "$config" value specified must be null, an object, an array, or an instance of ProviderConfigLike.'); } // Get the base template and merge it into the configuration $_template = BaseProviderConfig::getTemplate($_providerId); // Check the endpoint maps... $_endpoints = Option::get($_config, 'endpoint_map', array()); Option::set($_config, 'endpoint_map', array_merge(Option::get($_template, 'endpoint_map', array()), $_endpoints)); /** @noinspection PhpIncludeInspection */ require $_map['path']; if (empty($_config)) { $_config = array(); } $_className = $_map['namespace'] . '\\' . $_map['class_name']; $_mirror = new \ReflectionClass($_className); // Fill the config with the store values if any if (null !== $_type) { Option::sins($_config, 'type', $_type); } // Load any stored configuration $_config = static::_mergeConfigFromStore($_providerId, $_config); // Instantiate! $_provider = $_mirror->newInstanceArgs(array($_providerId, $_config)); // Cache the current version... Option::set(static::$_providerCache, $_cacheKey, $_provider); } return $_provider; }
/** * Formats the log entry. You can override this method to provide you own formatting. * It will strip out any console escape sequences as well * * @param array $entry Read the code, data in the array * @param bool $newline * * @return string * @deprecated in v0.2.20. To be removed in v0.3.0. Replaced by Monolog formatter */ public static function formatLogEntry(array $entry, $newline = true) { $_level = Option::get($entry, 'level'); $_levelName = static::_getLogLevel($_level); $_timestamp = Option::get($entry, 'timestamp'); $_message = preg_replace('/\\033\\[[\\d;]+m/', null, Option::get($entry, 'message')); $_context = Option::get($entry, 'context'); $_extra = Option::get($entry, 'extra'); $_blob = new \stdClass(); if (static::$_includeProcessInfo) { $_blob->pid = getmypid(); $_blob->uid = getmyuid(); $_blob->hostname = gethostname(); } if (!empty($_context)) { $_blob->context = $_context; } if (!empty($_extra)) { $_context->extra = $_extra; } $_blob = json_encode($_blob); if (false === $_blob || '{}' == $_blob) { $_blob = null; } $_replacements = array(0 => $_levelName, 1 => date('M d', $_timestamp), 2 => date('H:i:s', $_timestamp), 3 => $_message, 4 => $_blob); return str_ireplace(array('%%level%%', '%%date%%', '%%time%%', '%%message%%', '%%extra%%'), $_replacements, static::$_logFormat) . ($newline ? PHP_EOL : null); }
/** * @return string */ public function getLastName() { return Option::get($this->_name, 'family_name'); }
<?php use DreamFactory\Yii\Utility\Pii; use Kisma\Core\Utility\Option; /** * supplies info for the roll your own list */ if (false !== ($_options = Pii::getParam('dashboard.azure', false))) { $_featureEnabled = Option::get($_options, 'enabled', false); $_vhdId = Option::get($_options, 'vhd_id'); $_vhdVersion = Option::get($_options, 'vhd_version'); $_wikiUrl = Option::get($_options, 'wiki_url'); $_launchUrl = str_replace(array('{{vhd_id}}', '{{vhd_version}}'), array($_vhdId, $_vhdVersion), Option::get($_options, 'launch_url')); if ($_featureEnabled) { $_body = <<<HTML <p>Our Windows Azure DSP image is available in <a target="_blank" href="{$_launchUrl}">{$_launchUrl}</a>.</p> <p>A complete step-by-step tutorial is available in the wiki:<br/> <a target="_blank" href="{$_wikiUrl}">{$_wikiUrl}</a></p> HTML; } else { $_body = <<<HTML <p><strong>This feature is coming soon! Stay tuned!</strong></p> HTML; } return array('id' => 'windows-azure', 'title' => 'Windows Azure', 'body' => $_body); } return array();
/** * @param string $resource * @param array $payload * @param string $method * @param array $headers * * @throws HttpException * @return array|bool|mixed */ public function fetch($resource, $payload = array(), $method = self::Get, array $headers = array()) { // Dynamically insert Force API version $_resource = str_ireplace(static::API_VERSION_TAG, $this->_apiVersion ?: static::DEFAULT_API_VERSION, $resource); // Add our default headers if (false === array_search('X-PrettyPrint: 1', $headers)) { $headers = array_merge(array('Content-type: application/json', 'X-PrettyPrint: 1'), $headers); } // Send as JSON $this->_requestFormat = DataFormatTypes::JSON; // Fetch the resource $_response = parent::fetch($_resource, $payload, $method, $headers); // Check the result $_result = Option::get($_response, 'result'); $_code = Option::get($_response, 'code'); // Not a "denied" error... if ($_code < 400) { // Grab the request meta-results $this->_totalSize = Option::get($_result, 'totalSize'); $this->_queryDone = Option::get($_result, 'done', 0); $this->_nextRecordsUrl = Option::get($_result, static::NEXT_RECORDS_URL); } $_error = null; if (HttpResponse::NotFound == $_code) { $_error = 'Resource not found'; } elseif (is_array($_result) && isset($_result[0]->message) && isset($_result[0]->errorCode)) { $_error = $_result[0]->message . ' (' . $_result[0]->errorCode . ')'; } else { return $_result; } $this->_lastError = $_error; $this->_lastErrorCode = $_code; throw new HttpException($_code, $_error); }
<?php use DreamFactory\Yii\Utility\Pii; use Kisma\Core\Utility\Option; /** * supplies info for the roll your own list */ if (false !== ($_options = Pii::getParam('dashboard.amazon_ec2', false))) { $_featureEnabled = Option::get($_options, 'enabled', false); $_ami = Option::get($_options, 'ami'); $_wikiUrl = Option::get($_options, 'wiki_url'); $_launchUrl = str_replace('{{ami}}', $_ami, Option::get($_options, 'launch_url')); if ($_featureEnabled) { $_body = <<<HTML <p>Click the link to launch a DSP using our AMI:<br/><a target="_blank" href="{$_launchUrl}">{$_launchUrl}</a></p> <p>A complete step-by-step tutorial is available in the wiki:<br/> <a target="_blank" href="{$_wikiUrl}">{$_wikiUrl}</a></p> HTML; } else { $_body = <<<HTML <p><strong>This feature is coming soon! Stay tuned!</strong></p> HTML; } return array('id' => 'amazon-ec2', 'title' => 'Amazon EC2', 'body' => $_body); } return array();
/** * Construct a link to authorize the application * * @param array $payload * * @return string */ public function getAuthorizationUrl($payload = array()) { $_map = $this->_config->getEndpoint(EndpointTypes::AUTHORIZE); $_scope = $this->getConfig('scope'); $_referrer = Option::get($this->_requestPayload, 'referrer', Option::server('HTTP_REFERER', Curl::currentUrl()), true); $_redirectUri = $this->getConfig('redirect_uri', $_referrer); $_origin = $this->getConfig('origin_uri', $_redirectUri); $_proxyUrl = $this->getConfig('redirect_proxy_url'); $_state = array('request' => array('method' => Option::server('REQUEST_METHOD'), 'referrer' => $_referrer, 'query_string' => Option::server('QUERY_STRING'), 'remote_addr' => Option::server('REMOTE_ADDR'), 'time' => microtime(true), 'uri' => Option::server('REQUEST_URI'), 'payload' => $this->_requestPayload), 'origin' => $_origin, 'api_key' => sha1($_origin), 'redirect_uri' => $_redirectUri); Log::debug('Request state built: ' . print_r($_state, true)); $_payload = array_merge(array('client_id' => $this->getConfig('client_id'), 'redirect_uri' => $_redirectUri, 'response_type' => 'code', 'scope' => is_array($_scope) ? implode(' ', $_scope) : $_scope, 'state' => Storage::freeze($_state)), Option::clean(Option::get($_map, 'parameters', array()))); if (!empty($_proxyUrl)) { Log::info('Proxying request through: ' . $_proxyUrl); $_payload['redirect_uri'] = $_proxyUrl; } $_qs = http_build_query($_payload); $this->setConfig('authorize_url', $_authorizeUrl = $_map['endpoint'] . Curl::urlSeparator($_map['endpoint']) . $_qs); Log::debug('Authorization URL created: ' . $_authorizeUrl); return $_authorizeUrl; }
/** * @param PackageInterface $package * * @throws \InvalidArgumentException * @return string */ protected function _validatePackage(PackageInterface $package) { $_packageName = $package->getPrettyName(); $_parts = explode('/', $_packageName, 2); $this->_extra = Option::clean($package->getExtra()); $this->_config = Option::get($this->_extra, 'config', array()); $this->_plugIn = static::DSP_PLUGIN_PACKAGE_TYPE == $package->getType(); // Only install DreamFactory packages if not a plug-in if (static::PACKAGE_PREFIX != ($_vendor = @current($_parts)) && !$this->_plugIn) { throw new \InvalidArgumentException('This package is not a DreamFactory package and cannot be installed by this installer.' . PHP_EOL . ' * Name: ' . $_packageName . PHP_EOL . ' * Parts: ' . implode(' / ', $_parts) . PHP_EOL); } // Effectively /docRoot/shared/[vendor]/[namespace]/[package] Log::debug('Package "' . $_packageName . '" installation type: ' . ($this->_plugIn ? 'Plug-in' : 'Package')); $this->_packageName = $_packageName; $this->_installPath = $this->_buildInstallPath($_vendor, @end($_parts)); // Link path for plug-ins $_extra = Option::clean($package->getExtra()); $this->_linkName = Option::get($_extra, 'link_name', $_parts[1]); // Relative to composer.json... i.e. web/[link_name] $this->_linkPath = trim(static::PLUG_IN_LINK_PATH . '/' . $this->_linkName, '/'); Log::info('Platform Installer Debug > ' . $_packageName . ' > Version ' . $package->getVersion()); Log::debug(' * Install path: ' . $this->_installPath); if ($this->_plugIn) { Log::debug(' * Link name: ' . $this->_linkName); Log::debug(' * Link path: ' . $this->_linkPath); } return true; }
/** * Returns the level indicator for the log * * @param int $level The level value * * @return string */ public static function getIndicator($level) { return \Kisma\Core\Utility\Option::get(self::$_indicators, $level, self::__default); }
/** * Constructs and sets all options at once. * * @param array $options * * Options are: * * @option string $dbname The name of the database * @option string $type The connection type, "socket" or "stream" * @option string $host * @option int $port * @option string $user * @option string $password * @option string $ip * @option bool $logging * @option Configuration $config * @option EventManager $manager * @option array $namespaces Array of additional document namespaces * * @return \Doctrine\ODM\CouchDB\DocumentManager */ public static function documentManager($options = array()) { $_key = Option::get($options, 'host', 'localhost') . ':' . Option::get($options, 'port', 5984); if (!isset(self::$_dms[$_key])) { self::$_dms[$_key] = \Doctrine\ODM\CouchDB\DocumentManager::create(Option::get($options, 'client', static::couchDbClient($options)), Option::get($options, 'config'), Option::get($options, 'manager')); } return self::$_dms[$_key]; }
/** * Retrieves a value at the given key location, or the default value if key isn't found. * Setting $burnAfterReading to true will remove the key-value pair from the bag after it * is retrieved. Call with no arguments to get back a KVP array of contents * * @param string $key * @param mixed $defaultValue * @param bool $burnAfterReading * * @return mixed */ public function get($key = null, $defaultValue = null, $burnAfterReading = false) { return Option::get($this->_map, $this->_hashKey($key), $defaultValue, $burnAfterReading); }
<?php use DreamFactory\Yii\Utility\Pii; use Kisma\Core\Utility\Option; /** * supplies info for the roll your own list */ if (false !== ($_options = Pii::getParam('dashboard.vmware', false))) { $_featureEnabled = Option::get($_options, 'enabled', false); $_wikiUrl = Option::get($_options, 'wiki_url'); $_launchUrl = Option::get($_options, 'launch_url'); if ($_featureEnabled) { $_body = <<<HTML <p>Our VMWare appliance is available at <a target="_blank" href="{$_launchUrl}">{$_launchUrl}</a>.</p> <p>More information is available here:<br/> <a target="_blank" href="{$_wikiUrl}">{$_wikiUrl}</a></p> HTML; } else { $_body = <<<HTML <p><strong>This feature is coming soon! Stay tuned!</strong></p> HTML; } return array('id' => 'vmware', 'title' => 'VMWare Appliance', 'body' => $_body); } return array();
/** * @param int|string $type endpoint map type (@see EndpointTypes) * @param bool $urlOnly * * @throws \InvalidArgumentException * @return array */ public function getEndpoint($type = self::SERVICE, $urlOnly = false) { $type = $this->_getEndpointType($type); if (!EndpointTypes::contains($type)) { throw new \InvalidArgumentException('The endpoint type "' . $type . '" is not valid.'); } if (null === ($_endpoint = Option::get($this->_endpointMap, $type))) { if (empty($this->_endpointMap)) { throw new \InvalidArgumentException('The endpoint for "' . $type . '" is not mapped, nor is there a default mapping.'); } $_endpoint = current($this->_endpointMap); } if (false !== $urlOnly) { return Option::get($_endpoint, 'endpoint'); } return $_endpoint; }
/** * @param string $property * @param mixed $defaultValue * @param bool $burnAfterReading * * @return BaseProviderConfig|ProviderConfigLike|array */ public function getConfig($property = null, $defaultValue = null, $burnAfterReading = false) { if (null !== $property) { return Option::get($this->_config, $property, $defaultValue, $burnAfterReading); } return $this->_config; }
/** * Handle inbound redirect from various services * * @throws DreamFactory\Platform\Exceptions\RestException */ public function actionAuthorize() { Log::debug('Inbound $REQUEST: ' . print_r($_REQUEST, true)); $_state = Storage::defrost(Option::request('state')); $_origin = Option::get($_state, 'origin'); $_apiKey = Option::get($_state, 'api_key'); Log::debug('Inbound state: ' . print_r($_state, true)); if (empty($_origin) || empty($_apiKey)) { Log::error('Invalid request state.'); throw new BadRequestException(); } if ($_apiKey != ($_testKey = sha1($_origin))) { Log::error('API Key mismatch: ' . $_apiKey . ' != ' . $_testKey); throw new ForbiddenException(); } $_code = FilterInput::request('code', null, FILTER_SANITIZE_STRING); if (!empty($_code)) { Log::debug('Inbound code received: ' . $_code . ' from ' . $_state['origin']); } else { if (null === Option::get($_REQUEST, 'access_token')) { Log::error('Inbound request code missing.'); throw new RestException(HttpResponse::BadRequest); } else { Log::debug('Token received. Relaying to origin.'); } } $_redirectUri = Option::get($_state, 'redirect_uri', $_state['origin']); $_redirectUrl = $_redirectUri . (false === strpos($_redirectUri, '?') ? '?' : '&') . \http_build_query($_REQUEST); Log::debug('Proxying request to: ' . $_redirectUrl); header('Location: ' . $_redirectUrl); exit; }
<?php use DreamFactory\Yii\Utility\Pii; use Kisma\Core\Utility\Option; /** * supplies info for the roll your own list */ if (false !== ($_options = Pii::getParam('dashboard.bitnami', false))) { $_featureEnabled = Option::get($_options, 'enabled', false); $_url = Option::get($_options, 'url'); $_wikiUrl = Option::get($_options, 'wiki_url'); if ($_featureEnabled) { $_body = <<<HTML <p>Click the link to launch a DSP using a BitNami stack:<br/> <a target="_blank" href="{$_url}">{$_url}</a></p> <p>More information may be found in the README: <br/> <a target="_blank" href="{$_wikiUrl}">{$_wikiUrl}</a></p> HTML; } else { $_body = <<<HTML <p><strong>This feature is coming soon! Stay tuned!</strong></p> HTML; } return array('id' => 'bitnami', 'title' => 'BitNami', 'body' => $_body); } return array();