Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.62 (Unix) OpenSSL/1.0.2k-fips
System : Linux server1.richineiserver.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User : fdshops ( 1003)
PHP Version : 8.2.21
Disable Function : NONE
Directory :  /home/fdshops/public_html/vendor/knuckleswtf/scribe/src/Tools/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/fdshops/public_html/vendor/knuckleswtf/scribe/src/Tools/AnnotationParser.php
<?php

namespace Knuckles\Scribe\Tools;

class AnnotationParser
{
    /**
     * Parse an annotation like 'status=400 when="things go wrong" {"message": "failed"}'.
     * Fields are always optional and may appear at the start or the end of the string.
     *
     * @param string $annotationContent
     * @param array $allowedFields List of fields to look for.
     *
     * @return array{content: string, fields: string[]}
     */
    public static function parseIntoContentAndFields(string $annotationContent, array $allowedFields): array
    {
        $parsedFields = array_fill_keys($allowedFields, null);

        foreach ($allowedFields as $field) {
            preg_match("/$field=([^\\s'\"]+|\".+?\"|'.+?')\\s*/", $annotationContent, $fieldAndValue);

            if (count($fieldAndValue)) {
                [$matchingText, $attributeValue] = $fieldAndValue;
                $annotationContent = str_replace($matchingText, '', $annotationContent);

                $parsedFields[$field] = trim($attributeValue, '"\' ');
            }
        }

        return [
            'content' => trim($annotationContent),
            'fields' => $parsedFields
        ];
    }

    /**
     * Parse an annotation like 'title=This message="everything good"' into a key-value array.
     * All non key-value fields will be ignored. Useful for `@apiResourceAdditional`,
     * where users may specify arbitrary fields.
     *
     * @param string $annotationContent
     * @return array
     */
    public static function parseIntoFields(string $annotationContent): array
    {
        $fields = $matches = [];

        preg_match_all(
            '/([^\s\'"]+|".+?"|\'.+?\')=([^\s\'"]+|".+?"|\'.+?\')/',
            $annotationContent,
            $matches,
            PREG_SET_ORDER,
        );

        foreach ($matches as $match) {
            $fields[trim($match[1], '"\' ')] = trim($match[2], '"\' ');
        }

        return $fields;
    }
}

Spamworldpro Mini