本文整理汇总了PHP中Annotation类的典型用法代码示例。如果您正苦于以下问题:PHP Annotation类的具体用法?PHP Annotation怎么用?PHP Annotation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Annotation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
function index()
{
$url = $this->url;
$webpage = $this->webpage->create($url);
$tutor = $webpage->get_tutor();
$annotation = new Annotation(1017);
$user = $annotation->get_user();
$unread_count = $user->get_unread_notification_count();
$this->unit->run($unread_count, 'is_int', '先看一下user的未讀通知有幾封');
$tutor->setup_recommend($annotation);
$recommend = $annotation->get_recommend();
$this->unit->run($recommend->get_id(), 'is_int', '有取得建議');
$recommend_annotation = $recommend->get_recommend_by();
$this->unit->run($recommend_annotation, NULL, '沒有推薦標註');
$tips = $recommend->get_tips_text_array();
$this->unit->run_false(count($tips), 0, '有建議');
//------------------------------------------------
$recommend_annotation = new Annotation(783);
$recommend_annotation->set_score(0, 3);
$recommend_annotation->update();
$scope = new Annotation_scope(129);
$recommend_scope = new Annotation_scope_collection();
$recommend_scope->add_scope($scope);
$annotation->set_recommend_scopes($recommend_scope);
$tutor->setup_recommend($annotation);
$recommend->reload();
$recommend_annotation = $recommend->get_recommend_by();
$this->unit->run($recommend_annotation->get_id(), 783, '有找到推薦標註');
$this->unit->run($user->get_unread_notification_count(TRUE), $unread_count + 2, '因為新增了兩次推薦,所以應該有兩封通知?');
// $this->unit->run($test_result
// , $expected_result
// , $test_name);
//context_complete();
unit_test_report($this, __METHOD__);
}
示例2: throwsReflectionExceptionForMethodCallsWithoutGetOrIsOnSpecialValue
/**
* @test
*/
public function throwsReflectionExceptionForMethodCallsWithoutGetOrIsOnSpecialValue()
{
expect(function () {
$annotation = new Annotation('Example', 'someFunction()', ['__value' => 'true']);
$annotation->invalid();
})->throws(\ReflectionException::class)->withMessage('The value with name "invalid" for annotation @Example at someFunction() does not exist');
}
示例3: generate
/**
* Generates the actual interfaces
*/
public function generate()
{
$interfacesData = json_decode($this->json, true);
foreach ($interfacesData as $interface) {
$filename = $interface['name'] . '.java';
$interfaceObject = new JAVAInterfaceObject();
$interfaceObject->setName($interface['name']);
foreach ($interface['methods'] as $method) {
$methodObject = new JAVAMethod();
$methodObject->setName($method['name']);
$methodObject->setReturnValue($method['returnType']);
$methodObject->setScope($method['scope']);
$methodObject->setComment($method['comment']);
foreach ($method['parameters'] as $parameter) {
$parameterObject = new Parameter();
$parameterObject->setName($parameter['name']);
$parameterObject->setType($parameter['type']);
$methodObject->addParameter($parameterObject);
}
foreach ($method['annotations'] as $annotation) {
$annotationObject = new Annotation();
$annotationObject->setName($annotation['name']);
$annotationObject->setValue($annotation['value']);
$annotationObject->setInterpreter('@');
$methodObject->addAnnotation($annotationObject);
}
$interfaceObject->addMethod($methodObject);
}
file_put_contents($this->folder . DIRECTORY_SEPARATOR . $filename, $interfaceObject->toString());
}
}
示例4: parse
public function parse($text)
{
$ret = new Collection();
if (preg_match_all('/@([^@\\n\\r\\t]*)/', $text, $globalMatches) > 0) {
foreach ($globalMatches[1] as $annotationText) {
preg_match('/([a-zA-Z0-9]+)/', $annotationText, $localMatches);
if (in_array($localMatches[1], self::$ignoredAnnotations)) {
continue;
}
$annotation = new Annotation($localMatches[1]);
$optsStart = strpos($annotationText, '(');
if ($optsStart !== false) {
$optsEnd = strrpos($annotationText, ')');
$optsLength = $optsEnd - $optsStart - 1;
$opts = trim(substr($annotationText, $optsStart + 1, $optsLength));
foreach ($this->_parseOptions($opts) as $key => $values) {
foreach ($values as $value) {
$annotation->addOption($key, $value);
}
}
}
$ret->add($annotation);
}
}
return $ret;
}
示例5: get_feature
protected function get_feature(Annotation $annotation)
{
//if ($annotation->get_id() == 2363)
// test_msg('Language_variable_consensus', array($annotation->get_id(), $annotation->get_consensus_count()));
$feature = $annotation->get_consensus_count();
return $feature;
}
示例6: annotationDeleted
/**
* @param Annotation $annotation
*/
protected function annotationDeleted(Annotation $annotation)
{
$children = $annotation->getChildren();
foreach ($children as $child) {
$child->setStatus($annotation->getStatus());
$child->save();
}
}
示例7: annotations_from_hits
function annotations_from_hits($uri, $page, $hits)
{
$EXTEND_BY = 3;
$annotations = array();
foreach ($hits as $hit) {
print_r($hit);
// what word does hit start in?
$starting_word = $page->characters[$hit->start];
// offset with respect to the starting word
$starting_position = $hit->start - $page->word_start[$starting_word] - 1;
// what word does hit end in?
$ending_word = $page->characters[$hit->end];
// offset with respect to the ending word
$ending_position = $hit->end - $page->word_start[$ending_word];
echo $starting_word . ' ' . $starting_position . "\n";
echo $ending_word . ' ' . $ending_position . "\n";
$prefix_words = array();
if ($starting_word > 0) {
$prefix_pos = max(0, $starting_word - $EXTEND_BY);
$prefix_count = $starting_word - $prefix_pos;
$prefix_words = array_slice($page->words, $prefix_pos, $prefix_count);
$prefix = substr($page->words[$starting_word], 0, $starting_position);
if ($prefix != '') {
$prefix_words[] = $prefix;
}
}
$num_words = count($page->words);
$suffix_words = array();
if ($ending_word < $num_words - 1) {
$suffix_pos = min($ending_word + $EXTEND_BY, $num_words);
$suffix_count = $suffix_pos - $ending_word;
$suffix_words = array_slice($page->words, $ending_word + 1, $suffix_count);
$suffix = substr($page->words[$ending_word], $ending_position);
if ($suffix != '') {
array_unshift($suffix_words, $suffix);
}
}
$a = new Annotation($uri);
$a->add_permissions("acct:rdmpage@hypothes.is");
$a->add_text_quote(str_replace(" ", "\n", $hit->mid), join("\n", $prefix_words), join("\n", $suffix_words));
// Not sure that we need this, and doesn't seme to be working
/*
$a->add_range(
"//div[@id='" . ($starting_word + 1) . "']",
$starting_position,
"//div[@id='" . ($ending_word + 1) . "']",
$ending_position
);
*/
$a->add_tag($hit->type);
if (isset($hit->text)) {
$a->set_text($hit->text);
}
$annotations[] = $a;
}
return $annotations;
}
示例8: process
public static function process(Annotation $a)
{
$classes = $a->getValues();
foreach ($classes as $class) {
$classFile = "../{$class}.class.php";
if (file_exists($classFile)) {
include_once $classFile;
} else {
throw new Exception("{$classFile} DO NOT EXIST");
}
}
}
示例9: punish_comments
function punish_comments($hours = 6)
{
global $globals, $db;
$log = new Annotation('punish-comment');
if ($log->read() && $log->time > time() - 3600 * $hours) {
echo "Comments already verified at: " . get_date_time($log->time) . "\n";
return false;
}
if ($globals['min_karma_for_comments'] > 0) {
$min_karma = $globals['min_karma_for_comments'];
} else {
$min_karma = 4.5;
}
$votes_from = time() - $hours * 3600;
// 'date_sub(now(), interval 6 hour)';
$comments_from = time() - 2 * $hours * 3600;
//'date_sub(now(), interval 12 hour)';
echo "Starting karma_comments...\n";
$users = "SELECT SQL_NO_CACHE distinct comment_user_id as user_id from comments, users where comment_date > from_unixtime({$comments_from}) and comment_karma < -50 and comment_user_id = user_id and user_level != 'disabled' and user_karma >= {$min_karma}";
$result = $db->get_results($users);
$log->store();
if (!$result) {
return;
}
foreach ($result as $dbuser) {
$user = new User();
$user->id = $dbuser->user_id;
$user->read();
printf("%07d %s\n", $user->id, $user->username);
$punish = 0;
$comment_votes_count = (int) $db->get_var("SELECT SQL_NO_CACHE count(*) from votes, comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from}) and vote_type='comments' and vote_link_id = comment_id and vote_date > from_unixtime({$votes_from}) and vote_user_id != {$user->id}");
if ($comment_votes_count > 5) {
$votes_karma = (int) $db->get_var("SELECT SQL_NO_CACHE sum(vote_value) from votes, comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from}) and vote_type='comments' and vote_link_id = comment_id and vote_date > from_unixtime({$votes_from}) and vote_user_id != {$user->id}");
if ($votes_karma < 50) {
$distinct_votes_count = (int) $db->get_var("SELECT SQL_NO_CACHE count(distinct comment_id) from votes, comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from}) and vote_type='comments' and vote_link_id = comment_id and vote_date > from_unixtime({$votes_from}) and vote_user_id != {$user->id}");
$comments_count = (int) $db->get_var("SELECT SQL_NO_CACHE count(*) from comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from})");
$comment_coeff = min($comments_count / 10, 1) * min($distinct_votes_count / ($comments_count * 0.75), 1);
$punish = max(-2, round($votes_karma * $comment_coeff * 1 / 1000, 2));
}
}
if ($punish < -0.1) {
echo "comments: {$comments_count} votes distinct: {$distinct_votes_count} karma: {$votes_karma} coef: {$comment_coeff} -> {$punish}\n";
$user->karma += $punish;
//$user->store();
$annotation = new Annotation("karma-{$user->id}");
//$annotation->append(_('Penalización por comentarios').": $punish, nuevo karma: $user->karma\n");
echo _('Penalización por comentarios') . ": {$punish}, nuevo karma: {$user->karma}\n";
$log->append(_('Penalización') . " {$user->username}: {$punish}, nuevo karma: {$user->karma}\n");
}
$db->barrier();
}
}
示例10: do_load
function do_load() {
global $db, $current_user;
$annotation = new Annotation('ec2-autoscaler');
if (!$annotation->read()) {
return _('no hay estadísticas disponibles');
}
$group = unserialize($annotation->text);
$str = "web instances: $group->instances, ";
$str .= "cpu average load: ".round($group->load, 2) . "%, ";
$str .= "cpu max average ($group->measures periods): ".round($group->load_max, 2)."%, ";
$str .= "stored at: ". get_date_time($annotation->time);
return $str;
}
示例11: do_load
function do_load()
{
global $db, $current_user;
$annotation = new Annotation('ec2_watch');
if (!$annotation->read()) {
return _('no hay estadísticas disponibles');
}
$group = json_decode($annotation->text);
$str = "web instances: {$group->instances}, ";
$str .= "cpu average load: " . round($group->avg_load, 2) . "%, ";
$str .= "last action: {$group->action} ";
$str .= "last change: " . get_date_time($group->changed_ts) . " ";
$str .= "stored at: " . get_date_time($annotation->time);
return $str;
}
示例12: getKeyValuePropertiesByEntity
/**
* This functions builds an array (key\value) with entity data, to later insert on the db
*
* @param Entity $entity
*
* @return array
*/
private function getKeyValuePropertiesByEntity(Entity $entity)
{
$properties = array_keys($entity->getProperties());
$keyValueProperties = array();
foreach ($properties as $property) {
$method = $this->getterMethodToGetPropertyValue($property);
$propertyValue = $entity->{$method}();
if (is_null($propertyValue)) {
continue;
}
$annotations = $this->annotation->getAnnotationsByProperty($property, $entity);
$propertyKey = $this->getValueOfAnnotation($annotations, self::PROPERTY_ANNOTATION);
$keyValueProperties[$propertyKey] = $propertyValue;
}
return $keyValueProperties;
}
示例13: discover
/**
* Discovers all the annotations of a given class file
*
* @param string $class a class file
* @return array
*/
public static function discover($class)
{
try {
if (!file_exists($class)) {
throw new Exception($class . " does not exist");
}
$text = file($class, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$annotations = array();
$currentAnnotations = array();
foreach ($text as $key => $line) {
if (strpos($line, "* @annotation") !== false) {
$currentAnnotations[] = trim(str_replace("* @annotation", "", $line));
} else {
$functionName = "";
if (count($currentAnnotations) > 0 && Annotation::discoverFunctionName($line, $functionName)) {
$annotations[$functionName] = $currentAnnotations;
$currentAnnotations = array();
}
unset($text[$key]);
}
}
return $annotations;
} catch (Exception $e) {
Functions::dump($e->getMessage());
return NULL;
}
}
示例14: calculate_type
public static function calculate_type($reflection)
{
$annotations = Annotation::parse($reflection);
if (isset($annotations['type'])) {
return $annotations['type'];
} else {
$defaults = $reflection->getDeclaringClass()->getDefaultProperties();
$default_value = $defaults[$reflection->getName()];
if (is_null($default_value)) {
return 'null';
}
if (is_string($default_value)) {
return 'string';
} else {
if (is_integer($default_value)) {
return 'integer';
} else {
if (is_float($default_value)) {
return 'float';
} else {
if (is_bool($default_value)) {
return 'boolean';
} else {
if (is_array($default_value)) {
return 'array';
}
}
}
}
}
}
}
示例15: getTable
/**
* Ler um model e gera um SQL referente
* @param Model $model instância do model para gerar o SQL
* @return string retorna o SQL do model
*/
protected function getTable(Model $model)
{
$annotation = Annotation::get(get_class($model));
$class = $annotation->getClass();
if ($class->Entity) {
$table = new stdClass();
$table->Name = $class->Entity->Name ? $class->Entity->Name : get_class($model);
$table->Columns = array();
$table->Keys = array();
foreach ($model as $field => $value) {
$property = $annotation->getProperty($field);
if ($this->isField($property)) {
$column = new stdClass();
$column->Name = $this->getField($field, $property);
if (!$column->Name) {
$column->Name = $field;
}
$column->Type = $this->getType($property);
$column->Nullable = $this->getNullable($property);
$table->Columns[] = $column;
if ($this->isKey($property)) {
$table->Keys[] = $this->getKey($field, $property);
}
}
}
return $this->getSql($table);
}
}