/** * Parses a template file and declares view variables in this scope for the * template to have access to them. Loads localized templates based on the current * active locale. * @param string The name of the template to load * @param array an associative array of values to assign in the template * @param string The file extension of the template to be loaded * @return string The parsed html. */ public static function parse($path, $variables = array(), $extension = '.php', $allowDebug = true) { $tpl = new self(); $tpl->injectVariables($variables); $tpl->setViewName($path); $tpl->setConfig("file_extention", $extension); if (!(bool) $tpl->getConfig("allow_debug")) { $tpl->setConfig("allow_debug", false); } else { $tpl->setConfig("allow_debug", $allowDebug); } return $tpl->compile(); }
public static function load(Config $cfg, DB $db, $id) { $stmt = $db->prepare(' SELECT `id`, `initiated_at`, `customer_address`, `currency_amount`, `bitcoin_price`, `bitcoin_amount`, `txid`, `ntxid`, `status`, `cur_code`, `finalized_at`, `message`, `notice`, `email_to_notify` FROM `purchases` WHERE `id`=:id '); $stmt->execute(array(':id' => $id)); $row = $stmt->fetchAll(PDO::FETCH_ASSOC)[0]; $purchase = new self(); $purchase->setConfig($cfg)->setInitiatedAt(new DateTime($row['initiated_at']))->setCustomerAddress(new BitcoinAddress($row['customer_address']))->setCurrencyAmount(new Amount($row['currency_amount']))->setBitcoinPrice(new Amount($row['bitcoin_price']))->setBitcoinAmount(new Amount($row['bitcoin_amount']))->setCurrency($row['cur_code'])->setFinalizedAt(new DateTime($row['finalized_at']))->setTXID($row['txid'])->setNTXID($row['txid'])->setStatus($row['status'])->setMessage($row['message'])->setNotice($row['notice'])->setEmailToNotify($row['email_to_notify'])->setId($id); return $purchase; }
/** * @param string $base * @param string $label * @param array $properties * @throws PlinthException */ public static function loadFromArray($base, $label, $properties) { if (!isset($properties['path'])) { throw new PlinthException('Please define the path for you component.'); } if (!isset($properties['config']) && !isset($properties['routing'])) { throw new PlinthException('Please define at least a config or routing.'); } $self = new self($base, $label, $properties['path']); if (isset($properties['config'])) { if (!file_exists(__APP_CONFIG_PATH . $properties['config'])) { throw new PlinthException('The config you defined does not exist.'); } $self->setConfig($properties['config']); } if (isset($properties['routing'])) { if (!file_exists(__APP_CONFIG_PATH . $properties['routing'])) { throw new PlinthException('The routing you defined does not exist.'); } $self->setRouting($properties['routing']); } if (isset($properties['configMergeDefault']) && $properties['configMergeDefault']) { $self->enableDefaultConfigMerge(); } if (isset($properties['routingMergeDefault']) && $properties['routingMergeDefault']) { $self->enableDefaultRoutingMerge(); } return $self; }
/** * @param $missingConfigurationKey * @param array $config * * @return InvalidRepositoryConfig */ public static function create($missingConfigurationKey, array $config) { $e = new self('This configuration property must be provided: ' . $missingConfigurationKey); $e->setMissingConfigurationKey($missingConfigurationKey); $e->setConfig($config); return $e; }
/** * @param string $oldText * @param string $newText * @param HtmlDiffConfig|null $config * * @return self */ public static function create($oldText, $newText, HtmlDiffConfig $config = null) { $diff = new self($oldText, $newText); if (null !== $config) { $diff->setConfig($config); } return $diff; }
/** * @param string $json * * @return BuildScript */ public static function fromJson($json) { $data = json_decode($json, true); $obj = new self(); $obj->setBuildScript($data['build']); $obj->setRunScript($data['run']); $obj->setConfig($data['config']); return $obj; }
/** * @param string $query * @param int $offset * @param int $perPage * @param array $config * @return Pimcore_Google_Cse */ public function search($query, $offset = 0, $perPage = 10, $config = array()) { $list = new self(); $list->setConfig($config); $list->setOffset($offset); $list->setPerPage($perPage); $list->setQuery($query); return $list; }
/** * Factory method to create a new OpenstackClient * * @static * * @param array|Collection $config Configuration data. Array keys: * auth_url - Authentication service URL * username - API username * password - API password * tenantName - API tenantName * * @return \Guzzle\Common\FromConfigInterface|OpenstackClient|\Guzzle\Service\Client */ public static function factory($config = array()) { $default = array('compute_type' => 'compute', 'identity_type' => 'identity', 'storage_type' => 'storage', 'region' => 'RegionOne'); $required = array('auth_url'); $config = Inspector::prepareConfig($config, $default, $required); $client = new self($config->get('auth_url'), $config->get('username'), $config->get('password'), $config->get('tenantName')); $client->setConfig($config); return $client; }
/** * Factory method to create a new OpenstackClient * * @static * * @param array|Collection $config Configuration data. Array keys: * auth_url - Authentication service URL * username - API username * password - API password * tenantName - API tenantName * * @return \Guzzle\Common\FromConfigInterface|OpenstackClient|\Guzzle\Service\Client */ public static function factory($config = array(), EventDispatcherInterface $eventDispatcher = null) { $default = array('compute_type' => 'compute', 'identity_type' => 'identity', 'storage_type' => 'storage', 'region' => 'RegionOne'); $required = array('auth_url'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('auth_url'), $config->get('username'), $config->get('password'), $config->get('tenantName'), $eventDispatcher); $client->setConfig($config); $client->region = $config->get('region'); return $client; }
/** * Factory method to create a new ComputeClient * * @static * * * @param array|Collection $config Configuration data. Array keys: * base_url - Base URL of web service * token - Authentication token * tenant_id Tenant id * * @return \Guzzle\Common\FromConfigInterface|ComputeClient|\Guzzle\Service\Client */ public static function factory($config = array()) { $default = array(); $required = array('base_url', 'token', 'tenant_id'); $config = Inspector::prepareConfig($config, $default, $required); $client = new self($config->get('base_url'), $config->get('token'), $config->get('tenant_id')); $client->setConfig($config); $client->getEventDispatcher()->addSubscriber(new AuthenticationObserver()); return $client; }
/** * Create an instance of the client * * @param array $config * * @return \GuzzleAmazonWebservices\ProductAdvertising */ public static function factory($config = array()) { $defaults = array('base_url' => '{{scheme}}://{{locale}}/onca/xml', 'scheme' => 'http', 'locale' => self::LOCALE_US, 'version' => self::VERSION); $required = array('access_key', 'secret_key', 'associate_tag'); $config = Inspector::prepareConfig($config, $defaults, $required); $signature = new SignatureV2($config->get('access_key'), $config->get('secret_key')); $client = new self($config->get('base_url'), $config->get('access_key'), $config->get('secret_key'), $config->get('associate_tag'), $config->get('version')); $client->setConfig($config); $client->addSubscriber(new SignaturePlugin($signature, $config->get('version'))); return $client; }
public static function factory($config = array()) { $default = array('base_url' => '{scheme}://mtgox.com/', 'scheme' => 'https'); $required = array('base_url', 'api_key', 'api_secret'); $config = Inspector::prepareConfig($config, $default, $required); $client = new self($config->get('base_url'), $config->get('api_key'), $config->get('api_secret')); $client->setConfig($config); // Uncomment the following two lines to use an XML service description $client->setDescription(ServiceDescription::factory(__DIR__ . '/' . 'client.xml')); return $client; }
public static function factory($config = array()) { $default = array('base_url' => '{scheme}://blockchain.info/merchant/{guid}', 'scheme' => 'https'); $required = array('base_url', 'guid', 'password'); $config = Inspector::prepareConfig($config, $default, $required); $client = new self($config->get('base_url'), $config->get('guid'), $config->get('password')); $client->setConfig($config); // Uncomment the following two lines to use an XML service description $client->setDescription(ServiceDescription::factory(__DIR__ . '/' . 'client.xml')); return $client; }
/** * Get client instance * * @param array $config * * @return ProductAdvertisingClient */ public static function factory($config) { $defaults = array('base_url' => 'http://webservices.amazon.com/onca/xml?Service=AWSECommerceService', 'version' => self::VERSION); $required = array('access_key', 'secret_key'); $config = Inspector::prepareConfig($config, $defaults, $required); $signature = new SignatureV2($config->get('access_key'), $config->get('secret_key')); $client = new self($config->get('base_url'), $config->get('access_key'), $config->get('secret_key'), $config->get('version'), $signature); $client->setConfig($config); // Sign the request last $client->getEventManager()->attach(new QueryStringAuthPlugin($signature, $config->get('version')), -9999); return $client; }
/** * Factory method to create a new MediawikiApiClient * * @param array|Collection $config Configuration data. Array keys: * base_url - Base URL of web service * * @throws InvalidArgumentException * @return MediawikiApiClient */ public static function factory($config = array()) { $required = array('base_url'); $config = Collection::fromConfig($config, array(), $required); $client = new self($config->get('base_url')); $cookiePlugin = new CookiePlugin(new ArrayCookieJar()); $client->addSubscriber($cookiePlugin); $client->setConfig($config); $client->setUserAgent('addwiki-guzzle-mediawiki-client'); $client->setDescription(ServiceDescription::factory(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'mediawiki.json')); return $client; }
/** * Factory method to create a new SmsBoxClient * * @param array|Collection $config Configuration data. Array keys: * * base_url - Base URL of the smsBox service endpoint * username - API username * password - API password * * @return SmsBoxClient */ static function factory($config = array()) { $default = array('test' => false); $required = array('base_url', 'username', 'password'); $config = Inspector::prepareConfig($config, $default, $required); $client = new self($config->get('base_url'), $config->get('username'), $config->get('password'), $config->get('test')); $client->setConfig($config); // Add the XML service description to the client $description = ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'guzzle_smsbox.xml'); $client->setDescription($description); return $client; }
/** * @param $query * @param int $offset * @param int $perPage * @param array $config * @param null $facet * @return Cse */ public static function search($query, $offset = 0, $perPage = 10, array $config = array(), $facet = null) { $list = new self(); $list->setConfig($config); $list->setOffset($offset); $list->setPerPage($perPage); $list->setQuery($query); if (!empty($facet)) { $list->setQuery($list->getQuery() . " more:" . $facet); } return $list; }
/** * Factory method to create a new SimpleDB client * * @param array|Collection $config Configuration data. Array keys: * base_url - Base URL of web service. Default: {{scheme}}://{{region}}/ * scheme - Set to http or https. Defaults to http * version - API version. Defaults to 2009-04-15 * region - AWS region. Defaults to sdb.amazonaws.com * * access_key - AWS access key ID * * secret_key - AWS secret access key * * @return CentinelClient */ public static function factory($config) { // Passed config, default config, and required configs $config = Inspector::prepareConfig($config, array('base_url' => '{{scheme}}://{{region}}/', 'version' => '2009-04-15', 'region' => self::REGION_DEFAULT, 'scheme' => 'http'), array('access_key', 'secret_key', 'region', 'version', 'scheme')); // Filter our the Timestamp and Signature query string values from cache $config->set('cache.key_filter', 'query=Timestamp, Signature'); $signature = new SignatureV2($config->get('access_key'), $config->get('secret_key')); $client = new self($config->get('base_url'), $config->get('access_key'), $config->get('secret_key'), $config->get('version'), $signature); $client->setConfig($config); // Sign the request last $client->getEventManager()->attach(new QueryStringAuthPlugin($signature, $config->get('version')), -9999); // Retry 500 and 503 failures using exponential backoff $client->getEventManager()->attach(new ExponentialBackoffPlugin()); return $client; }
/** * Factory method to create a new HealthGraphClient * * @param array|Collection $config Configuration data. Array keys: * base_url - Base URL of web service * * @return HealthGraphClient * * @TODO update factory method and docblock for parameters */ public static function factory($config = array()) { $default = array('base_url' => 'https://api.runkeeper.com', 'logger' => FALSE); $required = array('base_url'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url')); $client->setConfig($config); $client->setDescription(ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'client.json')); // Set the iterator resource factory based on the provided iterators config $clientClass = get_class(); $prefix = substr($clientClass, 0, strrpos($clientClass, '\\')); $client->setResourceIteratorFactory(new HealthGraphIteratorFactory(array("{$prefix}\\Common\\Iterator"))); if ($config->get('logger')) { $adapter = new \Guzzle\Log\PsrLogAdapter($config->get('logger')); $logPlugin = new \Guzzle\Plugin\Log\LogPlugin($adapter, \Guzzle\Log\MessageFormatter::DEBUG_FORMAT); $client->addSubscriber($logPlugin); } return $client; }
/** * Factory method to create a new MWS client * * @param array|Collection $config Configuration data. Array keys: * base_url - Base URL of web service. Default: https://mws.amazonservices.com/ * version - API version. Defaults to 2009-02-01 * * access_key - AWS access key ID * * secret_key - AWS secret access key * * merchant_id - AWS merchant ID * * marketplace_id - AWS marketplace ID * application_name - Application name * application_version - Application version * * @return MwsClient */ public static function factory($config) { $defaults = array('base_url' => 'https://mws.amazonservices.fr/', 'version' => self::VERSION); $required = array('access_key', 'secret_key', 'merchant_id', 'marketplace_id', 'application_name', 'application_version'); $config = Inspector::prepareConfig($config, $defaults, $required); // Filter our the Timestamp and Signature query string values from cache $config->set('cache.key_filter', 'query=Timestamp, Signature'); $signature = new SignatureV2($config->get('access_key'), $config->get('secret_key')); $client = new self($config->get('base_url'), $config->get('access_key'), $config->get('secret_key'), $config->get('version'), $signature); $client->setConfig($config); // Sign the request last $client->getEventManager()->attach(new QueryStringAuthPlugin($signature, $config->get('version')), -9999); // Retry 500 and 503 failures, up to 3 times $client->getEventManager()->attach(new ExponentialBackoffPlugin(3, null, function ($try) { // @codeCoverageIgnoreStart return 60; // @codeCoverageIgnoreEnd })); // Throttle requests, no more than one per second $client->getEventManager()->attach(new ThrottlePlugin(1000)); return $client; }
/** * Factory method to create a new S3 client * * @param array|Collection $config Configuration data. Array keys: * base_url - Base URL of web service. Default: {{scheme}}://{{region}}/ * scheme - Set to http or https. Defaults to http * region - AWS region. Defaults to s3.amazonaws.com * access_key - AWS access key ID. Set to sign requests. * secret_key - AWS secret access key. Set to sign requests. * * @return S3Client */ public static function factory($config) { $defaults = array('base_url' => '{{scheme}}://{{region}}/', 'region' => self::REGION_DEFAULT, 'scheme' => 'http'); $required = array('region', 'scheme'); $config = Inspector::prepareConfig($config, $defaults, $required); // Filter our the Timestamp and Signature query string values from cache $config->set('cache.key_filter', 'header=Date, Authorization; query=Timestamp, Signature'); // If an access key and secret access key were provided, then the client // requests will be authenticated if ($config->get('access_key') && $config->get('secret_key')) { $signature = new S3Signature($config->get('access_key'), $config->get('secret_key')); } $client = new self($config->get('base_url'), $config->get('access_key'), $config->get('secret_key'), null, $signature); $client->setConfig($config); // If signing requests, add the request signing plugin if ($signature) { $client->getEventManager()->attach(new SignS3RequestPlugin($signature), -99999); } // Retry 500 and 503 failures using exponential backoff $client->getEventManager()->attach(new ExponentialBackoffPlugin()); // If Amazon DevPay tokens were provided, then add a DevPay filter if ($config->get('devpay_user_token') && $config->get('devpay_product_token')) { // Add the devpay plugin pretty soon in the event emissions $client->getEventManager()->attach(new DevPayPlugin($config->get('devpay_user_token'), $config->get('devpay_product_token')), 9999); } return $client; }
/** * 将xml转为array * @param string $xml * @throws WxPayException */ public static function Init($xml, $config) { $obj = new self(); $obj->setConfig($config); $obj->FromXml($xml); $obj->CheckSign(); return $obj->GetValues(); }
/** * @param Model\Asset\Video $asset * @param $config * @param array $onlyFormats * @return Processor * @throws \Exception */ public static function process(Model\Asset\Video $asset, $config, $onlyFormats = []) { if (!\Pimcore\Video::isAvailable()) { throw new \Exception("No ffmpeg executable found, please configure the correct path in the system settings"); } $instance = new self(); $formats = empty($onlyFormats) ? ["mp4"] : $onlyFormats; $instance->setProcessId(uniqid()); $instance->setAssetId($asset->getId()); $instance->setConfig($config); // check for running or already created thumbnails $customSetting = $asset->getCustomSetting("thumbnails"); $existingFormats = []; if (is_array($customSetting) && array_key_exists($config->getName(), $customSetting)) { if ($customSetting[$config->getName()]["status"] == "inprogress") { if (TmpStore::get($instance->getJobStoreId($customSetting[$config->getName()]["processId"]))) { return; } } elseif ($customSetting[$config->getName()]["status"] == "finished") { // check if the files are there $formatsToConvert = []; foreach ($formats as $f) { if (!is_file($asset->getVideoThumbnailSavePath() . $customSetting[$config->getName()]["formats"][$f])) { $formatsToConvert[] = $f; } else { $existingFormats[$f] = $customSetting[$config->getName()]["formats"][$f]; $existingFormats[$f] = $customSetting[$config->getName()]["formats"][$f]; } } if (!empty($formatsToConvert)) { $formats = $formatsToConvert; } else { return; } } elseif ($customSetting[$config->getName()]["status"] == "error") { throw new \Exception("Unable to convert video, see logs for details."); } } foreach ($formats as $format) { $thumbDir = $asset->getVideoThumbnailSavePath() . "/thumb__" . $config->getName(); $filename = preg_replace("/\\." . preg_quote(File::getFileExtension($asset->getFilename())) . "/", "", $asset->getFilename()) . "." . $format; $fsPath = $thumbDir . "/" . $filename; $tmpPath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $filename; if (!is_dir(dirname($fsPath))) { File::mkdir(dirname($fsPath)); } if (is_file($fsPath)) { @unlink($fsPath); } $converter = \Pimcore\Video::getInstance(); $converter->load($asset->getFileSystemPath()); $converter->setAudioBitrate($config->getAudioBitrate()); $converter->setVideoBitrate($config->getVideoBitrate()); $converter->setFormat($format); $converter->setDestinationFile($tmpPath); $converter->setStorageFile($fsPath); $transformations = $config->getItems(); if (is_array($transformations) && count($transformations) > 0) { foreach ($transformations as $transformation) { if (!empty($transformation)) { $arguments = []; $mapping = self::$argumentMapping[$transformation["method"]]; if (is_array($transformation["arguments"])) { foreach ($transformation["arguments"] as $key => $value) { $position = array_search($key, $mapping); if ($position !== false) { $arguments[$position] = $value; } } } ksort($arguments); if (count($mapping) == count($arguments)) { call_user_func_array([$converter, $transformation["method"]], $arguments); } else { $message = "Video Transform failed: cannot call method `" . $transformation["method"] . "´ with arguments `" . implode(",", $arguments) . "´ because there are too few arguments"; Logger::error($message); } } } } $instance->queue[] = $converter; } $customSetting = $asset->getCustomSetting("thumbnails"); $customSetting = is_array($customSetting) ? $customSetting : []; $customSetting[$config->getName()] = ["status" => "inprogress", "formats" => $existingFormats, "processId" => $instance->getProcessId()]; $asset->setCustomSetting("thumbnails", $customSetting); $asset->save(); $instance->convert(); return $instance; }
/** * @param array $config * * @throws Exception * @return Gateway */ public static function newInstance($config) { if (!function_exists('curl_init')) { throw new Exception('Curl required'); } $gateway = new self(); $gateway->setConfig($config); return $gateway; }
/** * @static * @param Asset_Video $asset * @param Asset_Video_Thumbnail_Config $config */ public static function process(Asset_Video $asset, $config) { if (!Pimcore_Video::isAvailable()) { throw new Exception("No ffmpeg executable found, please configure the correct path in the system settings"); } $instance = new self(); $formats = array("mp4", "webm", "f4v"); $instance->setProcessId(uniqid()); $instance->setAssetId($asset->getId()); $instance->setConfig($config); // check for running or already created thumbnails $customSetting = $asset->getCustomSetting("thumbnails"); $existingFormats = array(); if (is_array($customSetting) && array_key_exists($config->getName(), $customSetting)) { if ($customSetting[$config->getName()]["status"] == "inprogress") { if (is_file($instance->getJobFile($customSetting[$config->getName()]["processId"]))) { return; } } else { if ($customSetting[$config->getName()]["status"] == "finished") { // check if the files are there $formatsToConvert = array(); foreach ($formats as $f) { if (!is_file(PIMCORE_DOCUMENT_ROOT . $customSetting[$config->getName()]["formats"][$f])) { $formatsToConvert[] = $f; } else { $existingFormats[$f] = $customSetting[$config->getName()]["formats"][$f]; } } if (!empty($formatsToConvert)) { $formats = $formatsToConvert; } else { return; } } } } foreach ($formats as $format) { $filename = "video_" . $asset->getId() . "__" . $config->getName() . "." . $format; $fsPath = PIMCORE_TEMPORARY_DIRECTORY . "/" . $filename; if (is_file($fsPath)) { @unlink($fsPath); } $converter = Pimcore_Video::getInstance(); $converter->load($asset->getFileSystemPath()); $converter->setAudioBitrate($config->getAudioBitrate()); $converter->setVideoBitrate($config->getVideoBitrate()); $converter->setFormat($format); $converter->setDestinationFile($fsPath); $transformations = $config->getItems(); if (is_array($transformations) && count($transformations) > 0) { foreach ($transformations as $transformation) { if (!empty($transformation)) { $arguments = array(); $mapping = self::$argumentMapping[$transformation["method"]]; if (is_array($transformation["arguments"])) { foreach ($transformation["arguments"] as $key => $value) { $position = array_search($key, $mapping); if ($position !== false) { $arguments[$position] = $value; } } } ksort($arguments); if (count($mapping) == count($arguments)) { call_user_func_array(array($converter, $transformation["method"]), $arguments); } else { $message = "Video Transform failed: cannot call method `" . $transformation["method"] . "´ with arguments `" . implode(",", $arguments) . "´ because there are too few arguments"; Logger::error($message); } } } } $instance->queue[] = $converter; } $customSetting = $asset->getCustomSetting("thumbnails"); $customSetting = is_array($customSetting) ? $customSetting : array(); $customSetting[$config->getName()] = array("status" => "inprogress", "formats" => $existingFormats, "processId" => $instance->getProcessId()); $asset->setCustomSetting("thumbnails", $customSetting); $asset->save(); $instance->convert(); return $instance; }