예제 #1
0
 public function verify()
 {
     $this->out("{:white}Verifying that code matches documentation signatures...{:end}");
     foreach (Code::index() as $ref => $hash) {
         if (Code::hash($ref) != $hash) {
             $this->out("{:error}Warning: {$ref} is out-of-date.{:end}");
         }
     }
     $this->out("{:white}Fin.{:end}");
 }
예제 #2
0
 protected static function _codeToDoc($code)
 {
     $tokens = token_get_all($code);
     $display = array();
     $current = '';
     foreach ($tokens as $i => $token) {
         if ($i == 0 || $token[0] == T_CLOSE_TAG && $i + 1 == count($tokens)) {
             continue;
         }
         if ($token[0] == T_DOC_COMMENT) {
             if (preg_match('/@copyright/', $token[1])) {
                 continue;
             }
             if (!trim($current)) {
                 $current = '';
             }
             if ($current) {
                 $display[] = "{{{\n{$current}}}}";
                 $current = '';
             }
             $doc = Docblock::comment($token[1]);
             foreach (array('text', 'description') as $key) {
                 $doc[$key] = Code::embed($doc[$key]);
             }
             $display[] = $doc;
             continue;
         }
         $current .= is_array($token) ? $token[1] : $token;
     }
     if ($current) {
         $display[] = "{{{\n{$current}}}}";
     }
     return $display;
 }
예제 #3
0
<?php

/**
 * Initialize code index.
 */
use lithium\core\Libraries;
use lithium\action\Dispatcher;
use lithium\console\Dispatcher as ConsoleDispatcher;
use li3_docs\extensions\docs\Code;
$filter = function ($self, $params, $chain) {
    $indexPath = Libraries::get(true, 'path') . '/resources/docs.index.json';
    if (file_exists($indexPath) && is_readable($indexPath)) {
        Code::index((array) json_decode(file_get_contents($indexPath), true));
    }
    $result = $chain->next($self, $params, $chain);
    if (($index = Code::index()) && is_array($index) && is_writable(dirname($indexPath))) {
        file_put_contents($indexPath, json_encode($index));
    }
    return $result;
};
Dispatcher::applyFilter('run', $filter);
ConsoleDispatcher::applyFilter('run', $filter);
/**
 * Setup default options:
 *
 * - `'index'` _array|void_: Allows to restrict indexing to provided set of libraries.
 *   By default all libraries registered in the application are indexed.
 * - `'categories'` _array|void_: Allows manually provide a set of category names. By
 *    default categories are extracted from all indexed libraries.
 */
Libraries::add('li3_docs', array('bootstrap' => false) + Libraries::get('li3_docs') + array('url' => '/docs', 'index' => null, 'categories' => null));