/** * Constructor * * @param array|Collection $parameters Collection of parameters * to set on the command * @param ApiCommand $apiCommand Command definition from description */ public function __construct($parameters = null, ApiCommand $apiCommand = null) { parent::__construct($parameters); if ($apiCommand) { $this->apiCommand = $apiCommand; } else { // If this is a concrete command, then build an ApiCommand object $className = get_class($this); // Determine the name of the command based on the relation to the // client that executes the command $this->apiCommand = new ApiCommand(array('name' => str_replace('\\_', '.', Inflector::snake(substr($className, strpos($className, 'Command') + 8))), 'class' => $className, 'params' => $this->getInspector()->getApiParamsForClass($className))); } // Set default values on the command $this->getInspector()->validateConfig($this->apiCommand->getParams(), $this, false, false); $headers = $this->get('headers'); if (!$headers instanceof Collection) { $this->set('headers', new Collection((array) $headers)); } // You can set a command.on_complete option in your parameters as a // convenience method for setting an onComplete function $onComplete = $this->get('command.on_complete'); if ($onComplete) { $this->remove('command.on_complete'); $this->setOnComplete($onComplete); } $this->init(); }
/** * @param array|Collection $parameters Collection of parameters to set on the command * @param OperationInterface $operation Command definition from description */ public function __construct($parameters = array(), OperationInterface $operation = null) { parent::__construct($parameters); $this->operation = $operation ?: $this->createOperation(); foreach ($this->operation->getParams() as $name => $arg) { $currentValue = $this[$name]; $configValue = $arg->getValue($currentValue); // If default or static values are set, then this should always be updated on the config object if ($currentValue !== $configValue) { $this[$name] = $configValue; } } $headers = $this[self::HEADERS_OPTION]; if (!$headers instanceof Collection) { $this[self::HEADERS_OPTION] = new Collection((array) $headers); } // You can set a command.on_complete option in your parameters to set an onComplete callback if ($onComplete = $this['command.on_complete']) { unset($this['command.on_complete']); $this->setOnComplete($onComplete); } // Set the hidden additional parameters if (!$this[self::HIDDEN_PARAMS]) { $this[self::HIDDEN_PARAMS] = array(self::HEADERS_OPTION, self::RESPONSE_PROCESSING, self::HIDDEN_PARAMS, self::REQUEST_OPTIONS); } $this->init(); }
/** * Constructor * * @param array|Collection $parameters Collection of parameters to set on the command * @param OperationInterface $operation Command definition from description */ public function __construct($parameters = null, OperationInterface $operation = null) { parent::__construct($parameters); $this->operation = $operation ?: $this->createOperation(); foreach ($this->operation->getParams() as $name => $arg) { $currentValue = $this->get($name); $configValue = $arg->getValue($currentValue); // If default or static values are set, then this should always be updated on the config object if ($currentValue !== $configValue) { $this->set($name, $configValue); } } $headers = $this->get(self::HEADERS_OPTION); if (!$headers instanceof Collection) { $this->set(self::HEADERS_OPTION, new Collection((array) $headers)); } // You can set a command.on_complete option in your parameters to set an onComplete callback if ($onComplete = $this->get('command.on_complete')) { $this->remove('command.on_complete'); $this->setOnComplete($onComplete); } // If no response processing value was specified, then attempt to use the highest level of processing if (!$this->get(self::RESPONSE_PROCESSING)) { $this->set(self::RESPONSE_PROCESSING, self::TYPE_MODEL); } $this->init(); }
/** * Construct collection from models indexed by name * @param array $models Associative array of data to set * @throws \Exception if circular references cannot be resolved. */ public function __construct(array $models = array()) { parent::__construct(); // build dependency graph and add missing id properties $graph = array(); foreach ($models as $id => $model) { if (!isset($model['id'])) { $models[$id]['id'] = $id; } $graph[$id] = self::collectRefs($model); // allow self-dependency unset($graph[$id][$id]); } // Add items with no dependencies until no items have dependencies left while ($models) { $n = 0; foreach (array_keys($models) as $id) { if (empty($graph[$id])) { $n++; // add item with no dependencies to collection $this->set($id, $models[$id]); unset($models[$id]); // remove added item from dependency list of others foreach ($graph as $ref => $references) { unset($graph[$ref][$id]); } } } if (!$n) { throw new \Exception('circular references in model depenencies'); } } }
/** * Phlack Constructor. * * @param mixed $client * * @throws UnexpectedTypeException */ public function __construct($client) { if (is_string($client) || is_array($client)) { $client = new PhlackClient($client); } elseif (!$client instanceof PhlackClient) { throw new UnexpectedTypeException($client, ['string', 'array', 'Crummy\\Phlack\\Bridge\\Guzzle\\PhlackClient']); } parent::__construct(['client' => $client, 'builders' => [], 'commands' => ['send' => 'Send']]); }
/** * Constructor * * @param array|Collection $parameters (optional) Collection of parameters * to set on the command * @param ApiCommand $apiCommand (optional) Command definition from description */ public function __construct($parameters = null, ApiCommand $apiCommand = null) { parent::__construct($parameters); // Add arguments and defaults to the command if ($apiCommand) { $this->apiCommand = $apiCommand; Inspector::getInstance()->validateConfig($apiCommand->getParams(), $this, false, false); } else { Inspector::getInstance()->validateClass(get_class($this), $this, false, false); } if (!$this->get('headers') instanceof Collection) { $this->set('headers', new Collection((array) $this->get('headers'))); } $this->init(); }
/** * Constructor * * @param array|Collection $parameters Collection of parameters to set on the command * @param ApiCommandInterface $apiCommand Command definition from description */ public function __construct($parameters = null, ApiCommandInterface $apiCommand = null) { parent::__construct($parameters); $this->apiCommand = $apiCommand ?: ApiCommand::fromCommand(get_class($this)); $this->initConfig(); $headers = $this->get(self::HEADERS_OPTION); if (!$headers instanceof Collection) { $this->set(self::HEADERS_OPTION, new Collection((array) $headers)); } // You can set a command.on_complete option in your parameters as a // convenience method for setting an onComplete function $onComplete = $this->get('command.on_complete'); if ($onComplete) { $this->remove('command.on_complete'); $this->setOnComplete($onComplete); } $this->init(); }
public function __construct($parameters = array(), OperationInterface $operation = null) { parent::__construct($parameters); $this->operation = $operation ?: $this->createOperation(); foreach ($this->operation->getParams() as $name => $arg) { $currentValue = $this[$name]; $configValue = $arg->getValue($currentValue); if ($currentValue !== $configValue) { $this[$name] = $configValue; } } $headers = $this[self::HEADERS_OPTION]; if (!$headers instanceof Collection) { $this[self::HEADERS_OPTION] = new Collection((array) $headers); } if ($onComplete = $this['command.on_complete']) { unset($this['command.on_complete']); $this->setOnComplete($onComplete); } if (!$this[self::HIDDEN_PARAMS]) { $this[self::HIDDEN_PARAMS] = array(self::HEADERS_OPTION, self::RESPONSE_PROCESSING, self::HIDDEN_PARAMS, self::REQUEST_OPTIONS); } $this->init(); }
/** * Constructs the PostObject * * The options array accepts the following keys: * * - acl: The access control setting to apply to the uploaded file. Accepts any of the * CannedAcl constants * - Cache-Control: The Cache-Control HTTP header value to apply to the uploaded file * - Content-Disposition: The Content-Disposition HTTP header value to apply to the uploaded file * - Content-Encoding: The Content-Encoding HTTP header value to apply to the uploaded file * - Content-Type: The Content-Type HTTP header value to apply to the uploaded file. The default * value is `application/octet-stream` * - Expires: The Expires HTTP header value to apply to the uploaded file * - key: The location where the file should be uploaded to. The default value is * `^${filename}` which will use the name of the uploaded file * - policy: A raw policy in JSON format. By default, the PostObject creates one for you * - success_action_redirect: The URI for Amazon S3 to redirect to upon successful upload * - success_action_status: The status code for Amazon S3 to return upon successful upload * - ttd: The expiration time for the generated upload form data * - x-amz-server-side-encryption: The server-side encryption mechanism to use * - x-amz-storage-class: The storage setting to apply to the object * - x-amz-meta-*: Any custom meta tag that should be set to the object * * For the Cache-Control, Content-Disposition, Content-Encoding, * Content-Type, Expires, and key options, to use a "starts-with" comparison * instead of an equals comparison, prefix the value with a ^ (carat) * character * * @param S3Client $client * @param $bucket * @param array $options */ public function __construct(S3Client $client, $bucket, array $options = array()) { $this->setClient($client); $this->setBucket($bucket); parent::__construct($options); }
/** * @param array $data */ public function __construct($data = []) { $resolver = new OptionsResolver(); $this->setDefaultOptions($resolver); parent::__construct($resolver->resolve($data)); }