예제 #1
0
 /**
  * Load a RiveScript document from a file.
  *
  * @param array|string  $file
  */
 public function load($files)
 {
     $files = !is_array($files) ? (array) $files : $files;
     foreach ($files as $file) {
         $this->tree = $this->parser->process($file, $this->tree);
     }
 }
예제 #2
0
<?php

/*
 * @ author: Alexandr Kozyr;
 * @ email: kozyr1av@gmail.com;
 * this file aggregates all moves for parsing and saving data to db
 */
if (isset($argv[0])) {
    error_reporting(E_ALL | E_STRICT);
    ini_set('display_errors', 'On');
    ini_set('max_execution_time', '3600');
    require_once 'class/DbConnect.class.php';
    require_once 'class/Parser.class.php';
    $test = new Parser(DbConnect::MySqlConnecton($config));
    $test->process();
} else {
    die('Script should start with shell');
}
예제 #3
0
 /**
  * @param string $apiTitle
  * @param string $directoryToScan
  * @param bool   $recursion
  *
  * @return array
  * @throws \Com\PaulDevelop\Library\Common\ArgumentException
  * @throws \Com\PaulDevelop\Library\Common\TypeCheckException
  */
 public function process($apiTitle = '', $directoryToScan = '', $recursion = true)
 {
     //
     $responseSchemes = new AnnotationCollection();
     // action
     $ramlDocument = '#%RAML 0.8' . PHP_EOL;
     $isFirst = true;
     $fileList = self::getFiles($directoryToScan, $recursion);
     foreach ($fileList as $file) {
         $fileAnnotations = Parser::process($file);
         if (($titleAnnotation = self::findAnnotation($fileAnnotations->getFileLevel(), 'title')) == null || ($titleAnnotation = self::findAnnotation($fileAnnotations->getFileLevel(), 'title')) !== null && $titleAnnotation->getParameter()['title']->getValue() != $apiTitle) {
             continue;
         }
         if ($isFirst) {
             $isFirst = false;
             $fileLevelAnnotations = $fileAnnotations->getFileLevel();
             // title
             if (($annotation = $this->findAnnotation($fileLevelAnnotations, 'title')) !== null) {
                 $ramlDocument .= self::stringifySimpleAnnotation($annotation);
             }
             // version
             if (($annotation = $this->findAnnotation($fileLevelAnnotations, 'version')) !== null) {
                 $ramlDocument .= self::stringifySimpleAnnotation($annotation);
             }
             // base uri
             if (($annotation = $this->findAnnotation($fileLevelAnnotations, 'baseUri')) !== null) {
                 $ramlDocument .= self::stringifySimpleAnnotation($annotation);
             }
             // protocols
             if (count($annotations = $this->findAnnotations($fileLevelAnnotations, 'protocol')) > 0) {
                 $ramlDocument .= 'protocols: [';
                 $protocolString = '';
                 /** @var Annotation $annotation */
                 foreach ($annotations as $annotation) {
                     $protocolString .= ($protocolString != '' ? ', ' : '') . $annotation->getParameter()['protocol']->getValue();
                 }
                 $ramlDocument .= $protocolString . ']' . PHP_EOL;
             }
             // security schemes
             if (count($annotations = $this->findAnnotations($fileLevelAnnotations, 'securityScheme')) > 0) {
                 $ramlDocument .= 'securitySchemes:' . PHP_EOL;
                 /** @var Annotation $annotation */
                 foreach ($annotations as $annotation) {
                     $ramlDocument .= '  - ' . $annotation->getParameter()['name']->getValue() . ':' . PHP_EOL;
                     $ramlDocument .= '      type: ' . $annotation->getParameter()['type']->getValue() . PHP_EOL;
                 }
             }
             if (count($annotations = $this->findAnnotations($fileLevelAnnotations, 'responseScheme')) > 0) {
                 // store response schemes for later use
                 /** @var Annotation $annotation */
                 foreach ($annotations as $annotation) {
                     $responseSchemes->add($annotation, $annotation->getParameter()['name']->getValue());
                 }
             }
         }
         /** @var AnnotationCollection $annotations */
         foreach ($fileAnnotations->getMethodsLevel() as $methodAnnotations) {
             $ramlDocument .= PHP_EOL;
             // resource
             if (($annotation = $this->findAnnotation($methodAnnotations, 'resource')) !== null) {
                 $ramlDocument .= $annotation->getParameter()['resource']->getValue() . ':' . PHP_EOL;
             }
             // http verb
             $httpVerb = 'GET';
             if (($annotation = $this->findAnnotation($methodAnnotations, 'httpVerb')) !== null) {
                 $httpVerb = $annotation->getParameter()['verb']->getValue();
                 $ramlDocument .= '  ' . strtolower($annotation->getParameter()['verb']->getValue()) . ':' . PHP_EOL;
             }
             // description
             if (($annotation = $this->findAnnotation($methodAnnotations, 'description')) !== null) {
                 $ramlDocument .= '    description: ' . $annotation->getParameter()['description']->getValue() . PHP_EOL;
             }
             // secured by
             if (count($annotations = $this->findAnnotations($methodAnnotations, 'securedBy')) > 0) {
                 $ramlDocument .= '    securedBy: [';
                 $securedByString = '';
                 /** @var Annotation $annotation */
                 foreach ($annotations as $annotation) {
                     $securedByString .= ($securedByString != '' ? ', ' : '') . $annotation->getParameter()['scheme']->getValue();
                 }
                 $ramlDocument .= $securedByString . ']' . PHP_EOL;
             }
             if ($httpVerb == 'GET') {
                 // foreach parameter
                 if (count($annotations = $this->findAnnotations($methodAnnotations, 'parameter')) > 0) {
                     $ramlDocument .= '    queryParameters:' . PHP_EOL;
                     /** @var Annotation $annotation */
                     foreach ($annotations as $annotation) {
                         $ramlDocument .= '      ' . $annotation->getParameter()['name']->getValue() . ':' . PHP_EOL;
                         // display name
                         if (($parameter = $annotation->getParameter()['displayName']) != null) {
                             /** @var AnnotationParameter $parameter */
                             $ramlDocument .= '        displayName: ' . $parameter->getValue() . PHP_EOL;
                         }
                         // description
                         if (($parameter = $annotation->getParameter()['description']) != null) {
                             /** @var AnnotationParameter $parameter */
                             $ramlDocument .= '        description: ' . $parameter->getValue() . PHP_EOL;
                         }
                         // type
                         if (($parameter = $annotation->getParameter()['type']) != null) {
                             /** @var AnnotationParameter $parameter */
                             $ramlDocument .= '        type: ' . $parameter->getValue() . PHP_EOL;
                         }
                         // pattern
                         if (($parameter = $annotation->getParameter()['pattern']) != null) {
                             /** @var AnnotationParameter $parameter */
                             $ramlDocument .= '        pattern: ' . $parameter->getValue() . PHP_EOL;
                         }
                         // required
                         if (($parameter = $annotation->getParameter()['required']) != null) {
                             /** @var AnnotationParameter $parameter */
                             $ramlDocument .= '        required: ' . $parameter->getValue() . PHP_EOL;
                         }
                         // example
                         if (($parameter = $annotation->getParameter()['example']) != null) {
                             /** @var AnnotationParameter $parameter */
                             $ramlDocument .= '        example: ' . $parameter->getValue() . PHP_EOL;
                         }
                     }
                 }
             } else {
                 if ($httpVerb == 'POST' || $httpVerb == 'PATCH') {
                     $ramlDocument .= '    body:' . PHP_EOL;
                     $ramlDocument .= '      application/x-www-form-urlencoded:' . PHP_EOL;
                     $ramlDocument .= '        formParameter:' . PHP_EOL;
                     // foreach parameter
                     if (count($annotations = $this->findAnnotations($methodAnnotations, 'parameter')) > 0) {
                         /** @var Annotation $annotation */
                         foreach ($annotations as $annotation) {
                             $ramlDocument .= '          ' . $annotation->getParameter()['name']->getValue() . ':' . PHP_EOL;
                             // display name
                             if (($parameter = $annotation->getParameter()['displayName']) != null) {
                                 /** @var AnnotationParameter $parameter */
                                 $ramlDocument .= '            displayName: ' . $parameter->getValue() . PHP_EOL;
                             }
                             // description
                             if (($parameter = $annotation->getParameter()['description']) != null) {
                                 /** @var AnnotationParameter $parameter */
                                 $ramlDocument .= '            description: ' . $parameter->getValue() . PHP_EOL;
                             }
                             // type
                             if (($parameter = $annotation->getParameter()['type']) != null) {
                                 /** @var AnnotationParameter $parameter */
                                 $ramlDocument .= '            type: ' . $parameter->getValue() . PHP_EOL;
                             }
                             // pattern
                             if (($parameter = $annotation->getParameter()['pattern']) != null) {
                                 /** @var AnnotationParameter $parameter */
                                 $ramlDocument .= '            pattern: ' . $parameter->getValue() . PHP_EOL;
                             }
                             // required
                             if (($parameter = $annotation->getParameter()['required']) != null) {
                                 /** @var AnnotationParameter $parameter */
                                 $ramlDocument .= '            required: ' . $parameter->getValue() . PHP_EOL;
                             }
                             // example
                             if (($parameter = $annotation->getParameter()['example']) != null) {
                                 /** @var AnnotationParameter $parameter */
                                 $ramlDocument .= '            example: ' . $parameter->getValue() . PHP_EOL;
                             }
                         }
                     }
                 }
             }
             // responses
             if (count($annotations = $this->findAnnotations($methodAnnotations, 'response')) > 0) {
                 $ramlDocument .= '    responses:' . PHP_EOL;
                 /** @var Annotation $annotation */
                 foreach ($annotations as $annotation) {
                     // statusCode
                     if (($parameter = $annotation->getParameter()['statusCode']) != null) {
                         /** @var AnnotationParameter $parameter */
                         $ramlDocument .= '      ' . $parameter->getValue() . PHP_EOL;
                     }
                     // description
                     if (($parameter = $annotation->getParameter()['description']) != null) {
                         /** @var AnnotationParameter $parameter */
                         $ramlDocument .= '        description: ' . $parameter->getValue() . PHP_EOL;
                     }
                     // contentType
                     if (($parameter = $annotation->getParameter()['contentType']) != null) {
                         $ramlDocument .= '        body:' . PHP_EOL;
                         /** @var AnnotationParameter $parameter */
                         $ramlDocument .= '          ' . $parameter->getValue() . PHP_EOL;
                     }
                     // schema
                     if (($parameter = $annotation->getParameter()['schema']) != null) {
                         /** @var $responseScheme Annotation */
                         if (($responseScheme = $responseSchemes[$parameter->getValue()]) != null) {
                             /** @var $url AnnotationParameter */
                             if (($url = $responseScheme->getParameter()['url']) != null) {
                                 $ramlDocument .= '            schema: !include ' . $url->getValue() . PHP_EOL;
                             }
                         }
                     }
                     // example
                     if (($parameter = $annotation->getParameter()['example']) != null) {
                         /** @var $responseScheme Annotation */
                         if (($responseScheme = $responseSchemes[$parameter->getValue()]) != null) {
                             /** @var $url AnnotationParameter */
                             if (($url = $responseScheme->getParameter()['url']) != null) {
                                 $ramlDocument .= '            example: !include ' . $url->getValue() . PHP_EOL;
                             }
                         }
                     }
                 }
             }
         }
     }
     // return
     return $ramlDocument;
 }
예제 #4
0
파일: index.php 프로젝트: mudruy/karmasiv
header('Content-Type: text/html; charset=utf-8');
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=utf-8");
$query = isset($_GET['q']) ? $_GET['q'] : 'Пушкин';
$format = isset($_GET['f']) ? $_GET['f'] : 'json';
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/'));
include 'Logger.php';
include 'BrowserAdapter.php';
include 'BrowserCurl.php';
include 'simplehtmldom/simple_html_dom.php';
include 'Parser.php';
$br = new Ap_Browser_BrowserCurl();
$url = 'http://193.27.243.130/cgi-bin/irbis64r_91/cgiirbis_64.exe';
$params = array('X_S21P03' => 'K=', 'I21DBN' => 'IBIS', 'P21DBN' => 'IBIS', 'X_S21STR' => $query, 'X_S21P01' => '4', 'X_S21P02' => '1', 'X_S21LOG' => '1', 'S21COLORTERMS' => '1', 'S21FMT' => 'infow_wh', 'S21STN' => '1', 'S21CNR' => '20', 'S21REF' => '3', 'C21COM' => 'S', 'C21COM1' => 'Поиск');
$br->post($url, $params);
$html = str_get_html($br->getResponseText());
$res = array();
// find all link
foreach ($html->find('.advanced tr td[width="95%"]') as $e) {
    $str = str_replace('<br>', "\n", $e->innertext);
    $str = strip_tags($str, '<b></b>');
    $res[] = $str;
}
$parser = new Parser();
$parsedResult = $parser->process($res);
if ($format == 'json') {
    echo json_encode($parsedResult);
} else {
    Logger::dump($parsedResult);
}