本文整理汇总了PHP中Argument类的典型用法代码示例。如果您正苦于以下问题:PHP Argument类的具体用法?PHP Argument怎么用?PHP Argument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Argument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: notifyNewArgument
public function notifyNewArgument(Question $q, Argument $a)
{
global $sDB, $sTimer, $sTemplate;
$sTimer->start("notifyNewArgument");
$res = $sDB->exec("SELECT `notifications`.`userId`, `notifications`.`flags`, `users`.`email`, `users`.`userName` FROM `notifications`\n LEFT JOIN `users` ON `users`.`userId` = `notifications`.`userId`\n WHERE `questionId` = '" . i($q->questionId()) . "';");
while ($row = mysql_fetch_object($res)) {
// no notifications for our own arguments.
/*if($a->userId() == $row->userId)
{
continue;
}*/
$uId = new BaseConvert($row->userId);
$qId = new BaseConvert($q->questionId());
$profileUrl = $sTemplate->getShortUrlBase() . "u" . $uId->val();
$unfollowUrl = $sTemplate->getShortUrlBase() . "f" . $qId->val();
$url = $a->shortUrl();
if (!SHORTURL_BASE) {
$profileUrl = $sTemplate->getRoot() . "user/" . $row->userId . "/";
$unfollowUrl = $sTemplate->getRoot() . "unfollow.php?qId=" . $q->questionId();
$url = $a->fullurl();
}
$subject = $sTemplate->getString("NOTIFICATION_NEW_ARGUMENT_SUBJECT");
$message = $sTemplate->getString("NOTIFICATION_NEW_ARGUMENT_BODY", array("[USERNAME]", "[AUTHOR]", "[URL]", "[QUESTION]", "[ARGUMENT]", "[UNFOLLOW_URL]", "[PROFILE_URL]"), array($row->userName, $a->author(), $url, $q->title(), $a->headline(), $unfollowUrl, $profileUrl));
$this->sendMail($row->email, "", $subject, $message);
}
$sTimer->stop("notifyNewArgument");
}
示例2: add
/**
* @param Argument $argument
*
* @return ArgumentCollection
*/
public function add(Argument $argument)
{
$this->arguments[] = $argument;
if (!array_key_exists($argument->getType(), $this->maps)) {
$this->maps[$argument->getType()] = [];
}
$this->maps[$argument->getType()][] = $argument;
return $this;
}
示例3: addArgument
public function addArgument($name, $description = null, $constraints = [], $default = null)
{
$argument = new Argument();
$argument->setName($name);
$argument->setDescription($description);
$argument->setContraints($constraints);
$this->arguments[] = $argument;
return $this;
}
示例4: __construct
public function __construct(\ReflectionParameter $parameter)
{
if (!$parameter->isCallable()) {
throw new \InvalidArgumentException('Provided parameter should have a callable type hint');
}
parent::__construct($parameter);
}
示例5: 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();
}
};
}
示例6: __construct
public function __construct(\ReflectionParameter $parameter)
{
if ($parameter->getClass() === null) {
throw new \InvalidArgumentException('Provided parameter should have a class type hint');
}
parent::__construct($parameter);
$this->class_name = $parameter->getClass()->getName();
$this->short_name = $parameter->getClass()->getShortName();
}
示例7: 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;
}
示例8: create
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
$arguments = Input::get('Arguments');
$arguments = Argument::find($arguments);
if (empty($arguments)) {
$arguments = array();
}
return View::make('algorithms.create', compact('arguments'));
}
示例9: _createFromReflection
/**
* @load
* @param ReflectionMethod $reflection
*/
protected function _createFromReflection($reflection)
{
$this->_name = $reflection->getName();
$this->_public = $reflection->isPublic();
foreach ($reflection->getParameters() as $paramReflection) {
//Argument::create($this, $paramReflection);
$this->addArgument(Argument::create($this, $paramReflection));
}
}
示例10: convertArgument
/**
* Convert argument to argument object.
*
* @param string|Argument $argument
*
* @throws \InvalidArgumentException
*
* @return Argument
*/
protected function convertArgument($argument)
{
if (is_string($argument)) {
$argument = Argument::fromString($argument);
}
if (!$argument instanceof Argument) {
throw new \InvalidArgumentException('Invalid argument');
}
return $argument;
}
示例11: accepts
public function accepts(Argument $argument)
{
if (!$argument instanceof ExactArgument) {
return false;
}
$value = $argument->value();
if (is_array($value)) {
return in_array($this->needle, $value);
} else {
if (is_string($value)) {
return strpos($value, $this->needle) !== false;
} else {
if (is_object($value)) {
foreach ($value as $item) {
if ($item == $this->needle) {
return true;
}
}
}
}
}
return false;
}
示例12: addArgument
/**
* 添加一个参数
* @param Argument $argument 参数
* @throws \LogicException
*/
public function addArgument(Argument $argument)
{
if (isset($this->arguments[$argument->getName()])) {
throw new \LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName()));
}
if ($this->hasAnArrayArgument) {
throw new \LogicException('Cannot add an argument after an array argument.');
}
if ($argument->isRequired() && $this->hasOptional) {
throw new \LogicException('Cannot add a required argument after an optional one.');
}
if ($argument->isArray()) {
$this->hasAnArrayArgument = true;
}
if ($argument->isRequired()) {
++$this->requiredCount;
} else {
$this->hasOptional = true;
}
$this->arguments[$argument->getName()] = $argument;
}
示例13: create_from_reflection_parameter
public static function create_from_reflection_parameter(\ReflectionParameter $rp)
{
$arg = new Argument($rp->getName());
if ($rp->allowsNull()) {
$arg->set_null_allowed(true);
}
if ($rp->isDefaultValueAvailable()) {
$arg->set_default($rp->getDefaultValue());
}
if ($rp->isArray()) {
$arg->set_array(true);
} elseif ($type = $rp->getClass()) {
$arg->set_type($type->getName());
}
if ($rp->isPassedByReference()) {
$arg->set_reference(true);
}
return $arg;
}
示例14: 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']);
}
};
}
示例15: testSetValidationUncallable
public function testSetValidationUncallable()
{
$this->setExpectedException('InvalidArgumentException');
$argument = new Argument();
$argument->setValidation('');
}