/*!
\static
Creates a message structure out of \a $context, \a $source and \a $comment
and returns it.
196249
static function createMessage( $context, $source, $comment = null, $translation = null )
    {
        $msg = array( "context" => $context,
                      "source" => $source,
                      "comment" => $comment,
                      "translation" => $translation );
        return $msg;
    }
208486
final public static function get_create_structure() {
        $properties = self::properties_definition();
        $returns = array();

        foreach ($properties as $property => $definition) {
            if ($property == 'id') {
                // The can not be set on create.
                continue;

            } else if (isset($returns[$property]) && substr($property, -6) === 'format') {
                // We've already treated the format.
                continue;
            }

            $required = VALUE_REQUIRED;
            $default = null;

            // We cannot use isset here because we want to detect nulls.
            if (array_key_exists('default', $definition)) {
                $required = VALUE_DEFAULT;
                $default = $definition['default'];
            }

            // Magically treat the contextid fields.
            if ($property == 'contextid') {
                if (isset($properties['context'])) {
                    throw new coding_exception('There cannot be a context and a contextid column');
                }
                $returns += self::get_context_structure();

            } else {
                $returns[$property] = new external_value($definition['type'], $definition['description'], $required, $default,
                    $definition['null']);

                // Magically treat the format properties.
                if ($formatproperty = self::get_format_field($properties, $property)) {
                    if (isset($returns[$formatproperty])) {
                        throw new coding_exception('The format for \'' . $property . '\' is already defined.');
                    }
                    $returns[$formatproperty] = self::get_format_structure($property,
                        $properties[$formatproperty], VALUE_REQUIRED);
                }
            }
        }

        return new external_single_structure($returns);
    }
558533
public function getComment() : ?string 
    {
        if ( ! $this->hasComment()) {
            $this->setComment($this->getDefaultComment());
        }
        return $this->comment;
    }
806305
static function __static()
	{

		DOMXPathNavigator::$nodeTypeMap = array(
			XML_ELEMENT_NODE => XPathNodeType::Element,
			XML_ATTRIBUTE_NODE => XPathNodeType::Attribute,
			XML_TEXT_NODE => XPathNodeType::Text,
			// XML_CDATA_SECTION_NODE => 4,
			// XML_ENTITY_REF_NODE => 5,
			// XML_ENTITY_NODE => 6,
			XML_PI_NODE => XPathNodeType::ProcessingInstruction,
			XML_COMMENT_NODE => XPathNodeType::Comment,
			XML_DOCUMENT_NODE => XPathNodeType::Root,
			// XML_DOCUMENT_TYPE_NODE => XPathNodeType::Element, // .NET does not consider this an element
			// XML_DOCUMENT_FRAG_NODE => 11,
			XML_NOTATION_NODE => 12,
			// XML_HTML_DOCUMENT_NODE => 13,
			// XML_DTD_NODE => 14,
			XML_ELEMENT_DECL_NODE => XPathNodeType::Element,
			XML_ATTRIBUTE_DECL_NODE => XPathNodeType::Attribute,
			// XML_ENTITY_DECL_NODE => 17,
			XML_NAMESPACE_DECL_NODE => XPathNodeType::NamespaceURI,
		);

	}
863654
public function create()
    {
        /**
         * @var Comment $comment
         */
        $classNamespace = $this->getEntityNamespace();
        $comment = new $classNamespace();
        $comment
            ->setParent(null)
            ->setChildren(new ArrayCollection())
            ->setEnabled(true)
            ->setCreatedAt($this->now());

        return $comment;
    }
177958
public function addComment()
    {
        $userIsAllowed = $this
            ->userCredentialsProvider
            ->isAllowed();
        if (!$userIsAllowed) {
            return new JsonResponse([
                'status' => 'Error',
                'message' => 'The user is not allowed to post a comment',
            ], 401);
        }

        $sourceUUID = $this->getSourceUUID();
        if (empty($sourceUUID)) {
            return new JsonResponse([
                'status' => 'Error',
                'message' => 'Source UUID header must be defined',
            ], 400);
        }

        $authorUUID = $this
            ->userCredentialsProvider
            ->getUUID();
        if (empty($authorUUID)) {
            return new JsonResponse([
                'status' => 'Error',
                'message' => 'Author UUID header must be defined',
            ], 400);
        }

        $now = new DateTime();
        $postParameterBag = $this
            ->request
            ->request;

        $authorIsModerator = $this->userCredentialsProvider->isModerator();
        $authorRole = $authorIsModerator
            ? Author::ROLE_MODERATOR
            : Author::ROLE_USER;

        $state = $authorIsModerator
            ? State::APPROVED
            : State::NEW;

        $comment = Comment::createFromArray([
            'id' => bin2hex(random_bytes(32)),
            'source' => $sourceUUID,
            'author_uuid' => $authorUUID,
            'author_name' => $this->userCredentialsProvider->getName(),
            'author_email' => $this->userCredentialsProvider->getEmail(),
            'author_avatar' => $this->userCredentialsProvider->getAvatar(),
            'author_role' => $authorRole,
            'content' => $postParameterBag->get('content'),
            'created_at' => $now->format(DATE_ATOM),
            'state' => $state,
            'rating' => (int) $postParameterBag->get('rating', 0),
        ]);

        $this
            ->commentRepository
            ->addComment($comment);
        $this->flushRepository();
        $comment->setEditable(true);

        return new JsonResponse([
            'status' => 'OK',
            'comment' => $comment->toArray(),
            'user' => $this->userCredentialsProvider->toArray(),
        ], 200);
    }
307027
public static function comment($comment) {
		$text = null;
		$tags = [];
		$description = null;
		$comment = trim(preg_replace('/^(\s*\/\*\*|\s*\*{1,2}\/|\s*\* ?)/m', '', $comment));
		$comment = str_replace("\r\n", "\n", $comment);

		if ($items = preg_split('/\n@/ms', $comment, 2)) {
			list($description, $tags) = $items + ['', ''];
			$tags = $tags ? static::tags("@{$tags}") : [];
		}

		if (strpos($description, "\n\n")) {
			list($description, $text) = explode("\n\n", $description, 2);
		}
		$text = trim($text);
		$description = trim($description);
		return compact('description', 'text', 'tags');
	}
449142
public static function add_discussion_post_returns() {
        return new external_single_structure(
            array(
                'postid' => new external_value(PARAM_INT, 'new post id'),
                'warnings' => new external_warnings(),
                'post' => post_exporter::get_read_structure(),
                'messages' => new external_multiple_structure(
                    new external_single_structure(
                        array(
                            'type' => new external_value(PARAM_TEXT, "The classification to be used in the client side", VALUE_REQUIRED),
                            'message' => new external_value(PARAM_TEXT,'untranslated english message to explain the warning', VALUE_REQUIRED)
                        ), 'Messages'), 'list of warnings', VALUE_OPTIONAL
                ),
                //'alertmessage' => new external_value(PARAM_RAW, 'Success message to be displayed to the user.'),
            )
        );
    }
1259720
public function createCommentStory(AnCommandContext $context)
    {
        //called by the comment controller as as callback
        $entity = $context->comment;
        $parent = $context->comment->parent;

        $owner = $entity->author;

        if ($parent->isOwnable()) {
            $owner = $parent->owner;
        }

        $data = array(
            'name' => $parent->getIdentifier()->name.'_comment',
            'component' => $parent->component,
            'comment' => $entity,
            'object' => $parent,
            'owner' => $owner,
            'target' => $parent->isOwnable()  ? $parent->owner : null,
        );

        $story = $this->_mixer->createStory($data);

        if ($this->isNotifier()) {
            //story owner
            $data['subscribers'] = array($story->owner);

            //all the not subscribers
            if ($parent->isSubscribable()) {
                $data['subscribers'][] = $parent->subscriberIds->toArray();
            }

            $notification = $this->_mixer->createNotification($data);

            $notification->setType('post');
        }

        $story->save();
    }
1223109
function handleMessageNode( $contextName, $message )
    {
        $source = null;
        $translation = null;
        $comment = null;
        $message_children = $message->childNodes;
        for( $i = 0; $i < $message_children->length; $i++ )
        {
            $message_child = $message_children->item( $i );
            if ( $message_child->nodeType == XML_ELEMENT_NODE )
            {
                $childName = $message_child->tagName;
                if ( $childName  == "source" )
                {
                    if ( $message_child->childNodes->length > 0 )
                    {
                        $source = '';
                        foreach ( $message_child->childNodes as $textEl )
                        {
                            if ( $textEl instanceof DOMText )
                            {
                                $source .= $textEl->nodeValue;
                            }
                            else if ( $textEl instanceof DOMElement && $textEl->tagName == 'byte' )
                            {
                                $source .= chr( intval( '0' . $textEl->getAttribute( 'value' ) ) );
                            }
                        }
                    }
                }
                else if ( $childName == "translation" )
                {
                    if ( $message_child->childNodes->length > 0 )
                    {
                        $translation = '';
                        foreach ( $message_child->childNodes as $textEl )
                        {
                            if ( $textEl instanceof DOMText )
                            {
                                $translation .= $textEl->nodeValue;
                            }
                            else if ( $textEl instanceof DOMElement && $textEl->tagName == 'byte' )
                            {
                                $translation .= chr( intval( '0' . $textEl->getAttribute( 'value' ) ) );
                            }
                        }
                    }
                }
                else if ( $childName == "comment" )
                {
                    $comment_el = $message_child->firstChild;
                    $comment = $comment_el->nodeValue;
                }
                else if ( $childName == "translatorcomment" )
                {
                    //Ignore it.
                }
                else if ( $childName == "location" )
                {
                    //Handle location element. No functionality yet.
                }
                else
                    eZDebug::writeError( "Unknown element name: " . $childName, __METHOD__ );
            }
        }
        if ( $source === null )
        {
            eZDebug::writeError( "No source name found, skipping message in context '{$contextName}'", __METHOD__ );
            return false;
        }
        if ( $translation === null ) // No translation provided, then take the source as a reference
        {
//             eZDebug::writeError( "No translation, skipping message", __METHOD__ );
            $translation = $source;
        }
        /* we need to convert ourselves if we're using libxml stuff here */
        if ( $message instanceof DOMElement )
        {
            $codec = eZTextCodec::instance( "utf8" );
            $source = $codec->convertString( $source );
            $translation = $codec->convertString( $translation );
            $comment = $codec->convertString( $comment );
        }

        $this->insert( $contextName, $source, $translation, $comment );
        return true;
    }
38519
public static function create($comment) {
    $block_comment = new LineCommentBlockNode();
    $comment = trim($comment);
    $lines = array_map('rtrim', explode("\n", $comment));
    foreach ($lines as $line) {
      $comment_node = new CommentNode(T_COMMENT, '// ' . $line . "\n");
      $block_comment->addChild($comment_node);
    }
    return $block_comment;
  }
551051
protected function _commentNode()
    {
        $this->_codeNode();
        $token = $this->_stream->current(true);
        $this->_states['body'] = $token[1];
        $node = new NodeDef($this->_states['body'], 'comment');
        return $this->_contextualize($node);
    }
1160932
function () {
                var comment;

                if (input.charAt(i) !== '/') { return; }

                if (input.charAt(i + 1) === '/') {
                    return new(tree.Comment)($re(/^\/\/.*/), true, i, env.currentFileInfo);
                }
                comment = $re(/^\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/);
                if (comment) {
                    return new(tree.Comment)(comment, false, i, env.currentFileInfo);
                }
            }
1156994
public function msginitString(string $source, string $refname): PoFile
    {
        if (!($this->poFile instanceof PoFile)) {
            $this->poFile = new PoFile;
        }

        $tokens = token_get_all($source);

        $translateTags = array_merge($this->gettextTags, $this->pgettextTags, $this->ngettextTags);
        $commentText=null;
        $commentLine=(-10);
        $tokenCount = count($tokens);
        $i = 0;
        while ($i<$tokenCount) {
            $token = $tokens[$i];
            if (is_array($token) && $token[0] == T_STRING && in_array($token[1], $translateTags)) {
                $entry = new PoEntry;
                $gtt = array();
                list(, $text, $line) = $token;
                $entry->add(PoTokens::REFERENCE, $refname . ':' . $line);
                $gtt['line']=$line;
                $gtt['function']=$text;
                $gtt['args'] = array();
                $la = 1;
                while (is_array($tokens[$i + $la]) &&  $tokens[$i + $la][0] == T_WHITESPACE) {
                    $la++;
                }
                if ($tokens[$i + $la] == '(') {
                    while ((')' != $token=$tokens[$i + $la]) && ($la < 10)) {
                        if (is_array($token) && (
                            $token[0] == T_CONSTANT_ENCAPSED_STRING
                            || $token[0] == T_ENCAPSED_AND_WHITESPACE
                        )) {
                            list(, $text, $line) = $token;
                            $gtt['args'][]=$text;
                        }
                        $la++;
                    }
                    if (count($gtt['args'])) {
                        if (in_array($gtt['function'], $this->gettextTags)) {
                            $entry->set(PoTokens::MESSAGE, $this->escapeForPo($gtt['args'][0]));
                        } elseif (count($gtt['args'])>1 && in_array($gtt['function'], $this->pgettextTags)) {
                            $entry->set(PoTokens::CONTEXT, $this->escapeForPo($gtt['args'][0]));
                            $entry->set(PoTokens::MESSAGE, $this->escapeForPo($gtt['args'][1]));
                        } elseif (count($gtt['args'])>1 && in_array($gtt['function'], $this->ngettextTags)) {
                            $entry->set(PoTokens::MESSAGE, $this->escapeForPo($gtt['args'][0]));
                            $entry->set(PoTokens::PLURAL, $this->escapeForPo($gtt['args'][1]));
                        }
                        $this->checkPhpFormatFlag($entry);
                        if ($gtt['line']==($commentLine+1)) {
                            $entry->set(PoTokens::EXTRACTED_COMMENTS, $this->stripComment($commentText));
                        }
                        $this->poFile->mergeEntry($entry);
                    }
                }
            } elseif (is_array($token) && $token[0] == T_COMMENT) {
                list(, $commentText, $commentLine) = $token;
            }
            $i++;
        }

        return $this->poFile;
    }
1156770
public function getCommentTree($source, $context)
    {
        $key = $this->getSpecificSourceCacheKey(
            $source,
            $context
        );

        return isset($this->commentTree[$key])
            ? $this->commentTree[$key]
            : [];
    }
1354303
function &getDebugAsXMLComment()
    {
        // it would be nice to use a memory stream here to use
        // memory more efficiently
        while (strpos($this->debug_str, '--')) {
            $this->debug_str = str_replace('--', '- -', $this->debug_str);
        }
        $ret = "<!--\n" . $this->debug_str . "\n-->";

        return $ret;
    }
495441
static function __static()
    {
        if (extension_loaded(self::BACKING_OPENSSL)) {
            self::useOpenSslBacking();
        } elseif (extension_loaded(self::BACKING_MCRYPT)) {
            self::useMcryptBacking();
        } else {
            self::usePlaintextBacking();
        }
    }