本文整理汇总了PHP中Argument::i方法的典型用法代码示例。如果您正苦于以下问题:PHP Argument::i方法的具体用法?PHP Argument::i怎么用?PHP Argument::i使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Argument
的用法示例。
在下文中一共展示了Argument::i方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
/**
* Main plugin method
*
* @param array $users a list of user/pass
* @param string $realm the title of the auth popup
*
* @return function
*/
public function import(array $users = array(), $realm = 'Restricted area')
{
//realm must be a string
Argument::i()->test(2, 'string');
$this->realm = $realm;
$self = $this;
return function (Registry $request, Registry $response) use($users, $self) {
//get digest
$digest = $request->get('server', 'PHP_AUTH_DIGEST');
//if no digest
if (empty($digest)) {
//this throws anyways
return $self->dialog();
}
// analyze the PHP_AUTH_DIGEST variable
$data = $self->digest($digest);
//if no username
if (!isset($users[$data['username']])) {
//this throws anyways
return $self->dialog();
}
// generate the valid response
$signature = $self->getSignature($users, $data);
//if it doesnt match
if ($data['response'] !== $signature) {
//this throws anyways
return $self->dialog();
}
};
}
示例2: find
/**
* This explains the importance of parent/child
* Based on the given path we need to return the
* correct results
*
* @param *string $path Dot notated path
* @param int $i Current context
*
* @return mixed
*/
public function find($path, $i = 0)
{
Argument::i()->test(1, 'string')->test(2, 'int');
if ($i >= count($this->tree)) {
return null;
}
$current = $this->tree[$i];
//if they are asking for the parent
if (strpos($path, '../') === 0) {
return $this->find(substr($path, 3), $i + 1);
}
if (strpos($path, './') === 0) {
return $this->find(substr($path, 2), $i);
}
//separate by .
$path = explode('.', $path);
$last = count($path) - 1;
foreach ($path as $i => $node) {
//is it the last ?
if ($i === $last) {
//does it exist?
if (isset($current[$node])) {
return $current[$node];
}
//is it length ?
if ($node === 'length') {
//is it a string?
if (is_string($current)) {
return strlen($current);
}
//is it an array?
if (is_array($current) || $current instanceof \Countable) {
return count($current);
}
//we cant count it, so it's 0
return 0;
}
}
//we are not at the last node...
//does the node exist and is it an array ?
if (isset($current[$node]) && is_array($current[$node])) {
//great we can continue
$current = $current[$node];
continue;
}
//if it exists and we are just getting the length
if (isset($current[$node]) && $path[$i + 1] === 'length' && $i + 1 === $last) {
//let it continue
continue;
}
//if we are here, then there maybe a node in current,
//but there's still more nodes to process
//either way it cannot be what we are searching for
break;
}
return null;
}
示例3: import
/**
* Main route method
*
* @return function
*/
public function import($token, $secret, $escape = '1234567890')
{
Argument::i()->test(1, 'string')->test(2, 'string')->test(3, 'string');
//remember this scope
$self = $this;
eve()->addMethod('addCaptcha', function (Registry $request, Registry $response, array $meta) use($token, $self) {
//we already checked the captcha it's good
//we just need to check if it's set
if (isset($meta['check_captcha']) && $meta['check_captcha'] && !$request->isKey('get', 'g-recaptcha-response') && !$request->isKey('post', 'g-recaptcha-response')) {
//let the action handle the rest
$request->set('valid_captcha', false);
}
//set captcha
if (isset($route['make_captcha']) && $meta['make_captcha']) {
$request->set('captcha', $token);
}
});
//You can add validators here
return function (Registry $request, Registry $response) use($secret, $escape, $self) {
$request->set('valid_captcha', true);
//CAPTCHA - whether or not we are expecting it lets do a check
$captcha = false;
if ($request->isKey('get', 'g-recaptcha-response')) {
$captcha = $request->get('get', 'g-recaptcha-response');
} else {
if ($request->isKey('post', 'g-recaptcha-response')) {
$captcha = $request->get('post', 'g-recaptcha-response');
}
}
if ($captcha !== false && $captcha !== $escape) {
$result = eden('curl')->setUrl('https://www.google.com/recaptcha/api/siteverify')->verifyHost(false)->verifyPeer(false)->setPostFields(http_build_query(array('secret' => $secret, 'response' => $captcha)))->getJsonResponse();
//let the action handle the rest
$request->set('valid_captcha', $result['success']);
}
};
}
示例4: translate
/**
* Translate string
*
* @param *string $string The phrase to translate
* @param array|string[, string..] $args The sprintf arguments
*
* @return string
*/
public function translate($string, $args = array())
{
Argument::i()->test(1, 'string');
if (!is_array($args)) {
$args = func_get_args();
$string = array_shift($args);
}
if (count($args)) {
foreach ($args as $i => $arg) {
$args[$i] = $this->language()->get($arg);
}
return vsprintf($this->language()->get($string), $args);
}
return $this->language()->get($string);
}
示例5: send
/**
* Sends off this request to cURL
*
* @param string
* @param string
* @param array
* @return mixed
*/
public function send($method, $path, array $meta = array())
{
Argument::i()->test(1, 'string')->test(2, 'string');
//get the meta data for this url call
$meta = $this->getMetaData($method, $path, $meta);
//if in meta mode
if ($this->metaOnly) {
//return the meta
return $meta;
}
//extract the meta data
$url = $meta['url'];
$data = $meta['post'];
$agent = $meta['agent'];
$encode = $meta['encode'];
$headers = $meta['headers'];
// send it into curl
$request = $this('curl')->setUrl($url)->setConnectTimeout(10)->setFollowLocation(true)->setTimeout(60)->verifyPeer(false)->when($agent, function () use($agent) {
$this->setUserAgent($agent);
// set USER_AGENT
})->when(!empty($headers), function () use($headers) {
$this->setHeaders($headers);
// set headers
})->when($method == 'PUT' || $method == 'DELETE', function () use($method) {
$this->setCustomRequest($method);
})->when($method == 'POST' || $method == 'PUT', function () use($data) {
if (empty($data)) {
return;
}
//set the post data
$this->setPostFields($data);
});
//how should we return the data ?
switch ($encode) {
case self::ENCODE_QUERY:
$response = $request->getQueryResponse();
// get the query response
break;
case self::ENCODE_JSON:
$response = $request->getJsonResponse();
// get the json response
break;
case self::ENCODE_XML:
$response = $request->getSimpleXmlResponse();
// get the xml response
break;
case self::ENCODE_RAW:
default:
$response = $request->getResponse();
// get the raw response
break;
}
return $response;
}
示例6: replace
/**
* Replaces the last path with this one
*
* @param *string
*
* @return Eden\System\Path
*/
public function replace($path)
{
//argument 1 must be a string
Argument::i()->test(1, 'string');
//get the path array
$pathArray = $this->getArray();
//pop out the last
array_pop($pathArray);
//push in the new
$pathArray[] = $path;
//assign back to path
$this->data = implode('/', $pathArray);
return $this;
}
示例7: setPrefix
/**
* Sets the file name prefix
*
* @param *string $prefix
*
* @return Eden\Handlebars\Index
*/
public function setPrefix($prefix)
{
//Argument 1 must be a string
Argument::i()->test(1, 'string');
$this->prefix = $prefix;
return $this;
}
示例8: next
/**
* Hijacks the class and reports the results of the next
* method call
*
* @param *object $scope the class instance
* @param string|null $name the name of the property to inspect
*
* @return Eden\Core\Inspect
*/
public function next($scope, $name = null)
{
Argument::i()->test(1, 'object')->test(2, 'string', 'null');
//argument 2 must be a string or null
$this->scope = $scope;
$this->name = $name;
return $this;
}
示例9: trigger
/**
* Notify all observers of that a specific
* event has happened
*
* @param string|null $event the event to trigger
* @param mixed[, mixed..] $arg the arguments to pass to the handler
*
* @return Eden\Core\Event
*/
public function trigger($event = null)
{
//argument 1 must be string
Argument::i()->test(1, 'string', 'null');
if (is_null($event)) {
$trace = debug_backtrace();
$event = $trace[1]['function'];
if (isset($trace[1]['class']) && trim($trace[1]['class'])) {
$event = str_replace('\\', '-', $trace[1]['class']) . '-' . $event;
}
}
//get the arguments
$args = func_get_args();
//shift out the event
array_shift($args);
//for each observer
foreach ($this->observers as $observer) {
//if this is the same event, call the method, if the method returns false
if ($event == $observer[0] && call_user_func_array($observer[2], $args) === false) {
//break out of the loop
break;
}
}
return $this;
}
示例10: path
/**
* Returns the path class
*
* @param string
*
* @return Eden\System\Path
*/
public function path($path)
{
//argument 1 must be a string
Argument::i()->test(1, 'string');
return Path::i($path);
}
示例11: setId
/**
* Sets the session ID
*
* @param *int $id The prescribed session ID to use
*
* @return int
*/
public function setId($sid)
{
//argument 1 must be an integer
Argument::i()->test(1, 'int');
if (!self::$session) {
Exception::i()->setMessage(self::ERROR_NOT_STARTED)->trigger();
}
return session_id((int) $sid);
}
示例12: argument
/**
* Returns the argument validation class
*
* @return Eden\Core\Argument
*/
public function argument()
{
return Argument::i();
}
示例13: validate
/**
* Loads a validate class
*
* @param *string $key The validate factory key name
*
* @return Eve\Framework\Validate\Base
*/
public function validate($key)
{
Argument::i()->test(1, 'string');
$key = str_replace(array('-', '_', '/'), ' ', $key);
$key = ucwords($key);
$key = str_replace(' ', '\\', $key);
$class = $this->rootNameSpace . '\\Validate\\' . $key . '\\Index';
if (!class_exists($class)) {
throw new Exception(sprintf(self::NO_VALIDATE, $key));
}
//remove starting \\
$class = substr($class, 1);
return $this->{$class}();
}
示例14: setSecureData
/**
* Sets a set of secure cookies.
*
* @param *array $data The list of cookie data
* @param int $expires Expiration
* @param string $path Path to make the cookie available
* @param string|null $domain The domain
*
* @return Eden\Cookie\Index
*/
public function setSecureData(array $data, $expires = 0, $path = null, $domain = null)
{
//argment test
Argument::i()->test(2, 'int')->test(3, 'string', 'null')->test(4, 'string', 'null');
$this->setData($data, $expires, $path, $domain, true, false);
return $this;
}
示例15: getString
/**
* Returns the string class
*
* @param string
*
* @return Eden\Type\Type\StringType
*/
public function getString($string)
{
//argument 1 must be a string
Argument::i()->test(1, 'string');
return StringType::i($string);
}