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"); }
/** * @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; }
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; }
public function __construct(\ReflectionParameter $parameter) { if (!$parameter->isCallable()) { throw new \InvalidArgumentException('Provided parameter should have a callable type hint'); } parent::__construct($parameter); }
/** * 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(); } }; }
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(); }
/** * 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; }
/** * 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')); }
/** * @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)); } }
/** * 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; }
/** * constructor * @param string $name * @param mixed $value * @param string $operation * @return void */ function __construct($name, $value, $operation) { $operationList = array('in' => 1, 'notin' => 1, 'not_in' => 1, 'between' => 1); if (isset($value) && isset($operationList[$operation]) && !is_array($value) && $value != '') { $value = str_replace(' ', '', $value); $value = str_replace('\'', '', $value); $value = explode(',', $value); } parent::__construct($name, $value); $this->operation = $operation; }
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; }
/** * 添加一个参数 * @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; }
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; }
/** * @load * @param ReflectionMethod $reflection */ private function _createFromReflection($reflection) { $this->_name = $reflection->getName(); $this->_public = $reflection->isPublic(); $this->_inherited = !($reflection->getDeclaringClass()->getName() == $this->_controller->className()); foreach ($reflection->getParameters() as $paramReflection) { //Argument::create($this, $paramReflection); $this->addArgument(Argument::create($this, $paramReflection)); } //{ Add Views if ($this->isAction()) { $viewPath = \Path::instance()->evaluate(':' . $this->controller()->project()->name() . '.apps.view.+' . $this->controller()->name() . '.-' . $this->name()); if (file_exists($viewPath)) { $this->setViewDirectoryCreated(); $dh = opendir($viewPath); $viewsFound = array(); while (false !== ($file = readdir($dh))) { if ($file != "." && $file != ".." && strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'php') { $viewFilePath = rtrim($viewPath, '/') . "/{$file}"; if ($file == 'layout.php') { $this->setHasLayout(); } else { if ($file == 'params.php') { $this->setHasParams(); } else { $viewsFound[$file] = $viewFilePath; $this->addView(ControllerView::create($this, pathinfo($file, PATHINFO_FILENAME))); } } } } closedir($dh); if (array_key_exists('view.php', $viewsFound)) { $this->setHasDefaultView(); } } } //} }
/** * 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']); } }; }
public function testSetValidationUncallable() { $this->setExpectedException('InvalidArgumentException'); $argument = new Argument(); $argument->setValidation(''); }
/** * Sets subject * * @param string $subject The title of this message * * @return Eden\Mail\Smtp */ public function setSubject($subject) { Argument::i()->test(1, 'string'); $this->subject = $subject; return $this; }
/** * Given a SELECT statement that uses click count * returns the corresponding update sql string * for databases that don't have click count support built in * (aka all besides CUBRID) * * Function does not check if click count columns exist! * You must call $query->usesClickCount() before using this function * * @param $queryObject */ function getClickCountQuery($queryObject) { $new_update_columns = array(); $click_count_columns = $queryObject->getClickCountColumns(); foreach ($click_count_columns as $click_count_column) { $click_count_column_name = $click_count_column->column_name; $increase_by_1 = new Argument($click_count_column_name, null); $increase_by_1->setColumnOperation('+'); $increase_by_1->ensureDefaultValue(1); $update_expression = new UpdateExpression($click_count_column_name, $increase_by_1); $new_update_columns[] = $update_expression; } $queryObject->columns = $new_update_columns; return $queryObject; }
/** * Prep the prefix string for comparison * * @param Argument $argument * * @return string */ protected function prefixCompareString(Argument $argument) { return strtolower($argument->longPrefix() ?: $argument->prefix() ?: ''); }
/** * Summarizes a text * * @param int number of words * * @return Eden\Type\Type\StringType */ public function summarize($words) { //argument 1 must be an integer Argument::i()->test(1, 'int'); $this->data = explode(' ', strip_tags($this->data), $words); array_pop($this->data); $this->data = implode(' ', $this->data); return $this; }
/** * The opposite of registerPartial * * @param *string $name the partial name */ public static function unregisterPartial($name) { //Argument 1 must be a string Argument::i()->test(1, 'string'); if (isset(self::$partials[$name])) { unset(self::$partials[$name]); } }
/** * Run the database seeds. * * @return void */ public function run() { Eloquent::unguard(); $algorithmsXmls = File::allFiles(public_path() . '/algorithms'); foreach ($algorithmsXmls as $algorithmsXml) { $dom = new DomDocument(); $dom->load($algorithmsXml); $root = $dom->documentElement; $modality = Modality::whereName($root->getAttribute('modality'))->first(); if (empty($modality)) { throw new Exception("Could not find modality! ({$algorithmsXml})"); } $protocolName = $root->getAttribute('protocol'); $protocol = Protocol::whereName($protocolName)->whereModalityId($modality->Id)->first(); if (empty($protocol)) { \Log::warning("Could not find protocol! ({$algorithmsXml})"); continue; } $arguments = []; $parameters = []; $description = ""; foreach ($root->childNodes as $node) { if (get_class($node) == 'DOMText') { continue; } switch ($node->nodeName) { case 'arguments': foreach ($node->childNodes as $argument) { if (get_class($argument) == 'DOMText') { continue; } $arguments[] = ['Name' => $argument->getAttribute('name')]; } break; case 'parameters': foreach ($node->childNodes as $parameter) { if (get_class($parameter) == 'DOMText') { continue; } $parameters[] = ['Name' => $parameter->getAttribute('name'), 'Type' => $parameter->getAttribute('type'), 'Value' => $parameter->hasAttribute('value') ? $parameter->getAttribute('value') : null]; } break; case 'description': $description = $node->textContent; break; default: throw new Exception("Unrecognized entry in algorithm XML - {$node->nodeName}! ({$algorithmsXml})"); } } $algorithm = new Algorithm(); $algorithm->content = $description; $resultName = $root->getAttribute('result'); $resultType = $root->getAttribute('type'); $result = Parameter::whereName($resultName)->first(); if (empty($result)) { $result = Parameter::create(['Name' => $resultName, 'Type' => $resultType]); } $algorithm->result()->associate($result); $algorithm->protocol()->associate($protocol); $algorithm->save(); foreach ($arguments as $argument) { $algorithm->arguments()->attach(Argument::create($argument)); } foreach ($parameters as $parameter) { $algorithm->attribute($parameter); } } }
/** * Creates, adds and returns a new controller argument to this composite object. * If an argument with the same name exists already, it will be replaced by the * new argument object. * * @param string $name Name of the argument * @param string $dataType Name of one of the built-in data types * @param boolean $isRequired TRUE if this argument should be marked as required * @param mixed $defaultValue Default value of the argument. Only makes sense if $isRequired==FALSE * @return \TYPO3\Flow\Mvc\Controller\Argument The new argument * @api */ public function addNewArgument($name, $dataType = 'string', $isRequired = true, $defaultValue = null) { $argument = new Argument($name, $dataType); $argument->setRequired($isRequired); $argument->setDefaultValue($defaultValue); $this->addArgument($argument); return $argument; }
/** * 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; }
function CallFromArray($argumentsArray) { if ($this->rules == null) { return $this->delegate->CallFromArray($argumentsArray); } else { foreach ($this->rules as $arg => $value) { $this->array_insert_before($argumentsArray, Argument::GetArgumentNumber($arg), $value); } return $this->delegate->CallFromArray($argumentsArray); } }
/** * Creates a file and puts specified content into that file * * @param *string $content The raw content to save * * @return Eden\File\Index */ public function setContent($content) { //argument 1 must be string Argument::i()->test(1, 'string'); try { $this->absolute(); } catch (\Eden\Path\Exception $e) { $this->touch(); } file_put_contents($this->data, $content); return $this; }
/** * 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; }
/** * IMAP requires setting an active mailbox * before getting a list of mails * * @param string $mailbox Name of mailbox * * @return false|Eden\Mail\Imap */ public function setActiveMailbox($mailbox) { Argument::i()->test(1, 'string'); if (!$this->socket) { $this->connect(); } $response = $this->call('SELECT', $this->escape($mailbox)); $result = array_pop($response); foreach ($response as $line) { if (strpos($line, 'EXISTS') !== false) { list($star, $this->total, $type) = explode(' ', $line, 3); } else { if (strpos($line, 'UIDNEXT') !== false) { list($star, $ok, $next, $this->next, $type) = explode(' ', $line, 5); $this->next = substr($this->next, 0, -1); } } if ($this->total && $this->next) { break; } } if (strpos($result, 'OK') !== false) { $this->mailbox = $mailbox; return $this; } return false; }
/** * Returns a list of files given the path and optionally the pattern * * @param string|null regular expression * @param bool * * @return array */ public function getFiles($regex = null, $recursive = false) { //argument test Argument::i()->test(1, 'string', 'null')->test(2, 'bool'); $this->absolute(); $files = array(); if ($handle = opendir($this->data)) { //for each file while (false !== ($file = readdir($handle))) { // If this is infact a file if (filetype($this->data . '/' . $file) == 'file' && (!$regex || preg_match($regex, $file))) { //add it $files[] = File::i($this->data . '/' . $file); // recursive and this is infact a directory } else { if ($recursive && $file != '.' && $file != '..' && filetype($this->data . '/' . $file) == 'dir') { $subfiles = self::i($this->data . '/' . $file); $files = array_merge($files, $subfiles->getFiles($regex, $recursive)); } } } closedir($handle); } return $files; }