/** * @param array[] $endpointMap * * @return BaseProviderConfig */ public function setEndpointMap($endpointMap) { foreach (Option::clean($endpointMap) as $_type => $_endpoint) { $this->mapEndpoint($_type, $_endpoint); } return $this; }
/** * @return array */ public function getPhoneNumber() { return @current(Option::clean($this->_phoneNumbers)); }
/** * @param array $options * @param bool $fromCreate * * @throws DreamFactory\Platform\Exceptions\BadRequestException */ public function actionUpdate($options = array(), $fromCreate = false) { $_id = $_schema = $_errors = null; // New provider if (false !== $fromCreate && null !== ($_resourceId = FilterInput::request('resource'))) { // New request $_model = ResourceStore::model($_resourceId); $_displayName = Inflector::display($_resourceId); $_schema = $this->_loadConfigSchema($_resourceId, $_model->hasAttribute('config_text') ? $_model->config_text : array()); } else { // Requests will come in like: /admin/update/<resource>/<id> list($_resourceId, $_id) = $this->_parseRequest(); $_displayName = Inflector::display($_resourceId); // Load it up. /** @var $_model BasePlatformSystemModel */ if (null !== ($_model = ResourceStore::model($_resourceId)->findByPk($_id))) { $_schema = $this->_loadConfigSchema($_resourceId, $_model->hasAttribute('config_text') ? $_model->config_text : array()); if (Pii::postRequest()) { // On a post, update if (null === ($_data = Option::get($_POST, $_displayName))) { throw new BadRequestException('No payload received.'); } /** @var Provider $_model */ if ($_model->hasAttribute('config_text')) { $_len = strlen(static::SCHEMA_PREFIX); $_config = Option::clean($_model->config_text); foreach ($_data as $_key => $_value) { if (static::SCHEMA_PREFIX == substr($_key, 0, $_len)) { $_newKey = str_replace(static::SCHEMA_PREFIX, null, $_key); if (isset($_config[$_newKey])) { $_config[$_newKey] = $_value; } unset($_data[$_key]); } } $_model->config_text = $_config; unset($_data['config_text']); } $_model->setAttributes($_data); $_model->save(); Pii::setState('status_message', 'Resource Updated Successfully'); $this->redirect('/admin/' . $_resourceId . '/update/' . $_id); } } if ($_model->hasAttribute('name')) { $_displayName = $_model->name; } else { if ($_model->hasAttribute('provider_name')) { $_displayName = $_model->provider_name; } else { if ($_model->hasAttribute('api_name')) { $_displayName = $_model->api_name; } } } } $this->render('update', array('model' => $_model, 'schema' => $_schema, 'errors' => $_errors, 'resourceName' => $_resourceId, 'displayName' => $_displayName, 'update' => null !== $_id)); }
/** * 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; }
/** * @param array|\stdClass $data * * @return bool|void */ protected function _processReceivedToken($data) { $_data = $data; if (!is_array($data) && !$data instanceof \stdClass && !$data instanceof \Traversable) { $_data = Option::clean($data); if (!empty($_data)) { $_data = current($_data); } } foreach ($_data as $_key => $_value) { switch ($_key) { case 'instance_url': $this->_instanceName = trim(str_ireplace(array('https://', 'http://', '/'), null, $_value)); $_endpoint = $this->getConfig()->getEndpoint(EndpointTypes::SERVICE); $_endpoint['endpoint'] = str_ireplace('{{instance_name}}', $this->_instanceName, static::SERVICE_ENDPOINT_PATTERN); $this->getConfig()->mapEndpoint(EndpointTypes::SERVICE, $_endpoint); break; case 'id': $this->_identityUrl = $_value; break; } } return parent::_processReceivedToken($data); }
* @var string $resourceName The name of this resource (i.e. App, AppGroup, etc.) Essentially the model name * @var string $displayName * @var string $statusMessage */ use DreamFactory\Common\Enums\PageLocation; use DreamFactory\Platform\Yii\Models\BasePlatformSystemModel; use DreamFactory\Yii\Utility\BootstrapForm; use DreamFactory\Yii\Utility\Pii; use Kisma\Core\Utility\Bootstrap; use Kisma\Core\Utility\Option; Pii::cssFile('//cdnjs.cloudflare.com/ajax/libs/x-editable/1.4.5/bootstrap-editable/css/bootstrap-editable.css'); Pii::scriptFile('//cdnjs.cloudflare.com/ajax/libs/x-editable/1.4.5/bootstrap-editable/js/bootstrap-editable.min.js', PageLocation::End); $_css .= '<link href="" rel="stylesheet" />'; echo '<script src=""></script>'; //@TODO error handling from resource request $_errors = isset($errors) ? Option::clean($errors) : array(); $_update = !$model->isNewRecord; $_prefix = @end(@explode('\\', $this->getModelClass())); $_resourcePath = $resourceName; if ($_update) { $_resourcePath .= '/' . $model->id; } if (!empty($_errors)) { $_headline = isset($alertMessage) ? $alertMessage : 'Sorry pal...'; $_messages = null; foreach ($_errors as $_error) { foreach ($_error as $_message) { $_messages .= '<p>' . $_message . '</p>'; } } echo <<<HTML
/** * Takes a KVP traversable and converts to a ' key="value" ' string suitable for framing. * * @param array|object $array * @param bool $uppercaseKeys If TRUE, the "key" portion will be uppercased * @param int $trueConvert The value to substitute for boolean true * @param int $falseConvert The value to substitute for boolean false * * @return string */ public static function kvpToString($array, $uppercaseKeys = false, $trueConvert = 1, $falseConvert = 0) { $_result = array(); foreach (Option::clean($array) as $_key => $_value) { if (null !== $_value) { if (false === $_value) { $_value = $falseConvert; } else { if (true === $_value) { $_value = $trueConvert; } else { if (is_array($_value)) { $_value = trim(implode(' ', $_value)); } } } $_result[] = (false !== $uppercaseKeys ? strtoupper($_key) : strtolower($_key)) . '="' . $_value . '"'; } } return trim(implode(' ', $_result)); }