Example #1
0
 public function testOrderedExamplesWithMeta()
 {
     $t = ordered_exampls('ordered_examples/2');
     $fn = function ($itm) {
         return data_directory() . '/ordered_examples/2/' . $itm;
     };
     $this->assertEquals($t, array_map($fn, [2, 3, 1]));
 }
Example #2
0
def('is_example_exists', function ($path) {
    if (!is_example_path($path)) {
        throw new Exception('Path is not valid: ' . $path);
    }
    $path = data_directory() . '/' . $path;
    if (file_exists($path) && is_file($path)) {
        return true;
    }
    return false;
});
/**
 * Зная идентификатор - узнать на каком месте он находится в категории
 */
def('find_position', function ($id, $pth) {
    $i = 0;
    $all = ordered_exampls($pth);
    foreach ($all as $v) {
        ++$i;
        $t = last(explode('/', $v));
        if ($t == $id) {
            return $i;
        }
    }
});
/**
 * Это ссылка на сайт?
 */
def('is_normal_link', function ($href) {
    return !!preg_match('@^https?:@i', $href);
});
/**
Example #3
0
 public function examples()
 {
     return array_map(function ($pth) {
         return new Example(str_replace(data_directory() . '/', '', $pth));
     }, ordered_exampls($this->_path));
 }
Example #4
0
 public function getUsage()
 {
     $us = ordered_exampls($this->_path);
     $return = array();
     foreach ($us as $v) {
         $return[] = find_example(str_replace('./data/', '', $v));
     }
     return $return;
 }