function __construct($pth) { if (!is_example_path($pth) or !is_example_exists($pth)) { throw new Exception("Example {$pth} not exists"); } $this->pth = $pth; $this->file_id = last(explode('/', $pth)); $category_path = implode('/', but_last(explode('/', $pth))); $this->id = find_position($this->file_id, $category_path); $this->category = Category::get($category_path); }
<?php if (!path()) { draw_page('Поваренная книга программиста', dview('index_content', main_categories())); } elseif (is_category_path(path()) && is_category_exists(path())) { is_need_cache(true); $category = new Category(path()); keywords($category->keywords()); draw_page($category->getTitle(), dview('one_category', $category)); } elseif (is_example_path(path()) && is_example_exists(path())) { is_need_cache(true); $example = new Example(path()); keywords($example->keywords()); draw_page($example->prop('desc'), view('path_block', ['id' => $example->id()]) . view('one_example', ['data' => $example, 'show_link' => true])); } else { show_404(); }
<?php if (!path()) { draw_page('Поваренная книга программиста', dview('index_content', main_categories())); } elseif (is_category_path(path())) { if (Category::isValidPath(path())) { is_need_cache(true); $category = Category::get(path()); keywords($category->keywords()); draw_page($category->getTitle(), dview('one_category', $category)); } else { show_404(); } } elseif (is_example_path(path())) { if (is_example_exists(path())) { is_need_cache(true); function example_title($example) { $cats = array(); foreach (bu::path() as $v) { if (preg_match('/^[0-9]+$/', $v)) { break; } $cats[] = Category::get($v)->name(); } return 'Пример: ' . implode('/', $cats) . ' #' . $example->id(); } $example = find_example(path()); keywords($example->keywords()); draw_page($example->prop('desc'), view('path_block', array('id' => $example->id())) . view('one_example', array('data' => $example, 'show_link' => true))); } else {
<div id="navigation"> <a href='/'>/</a> → <?php $path = bu::path(); $prefix = '/'; $last = $path[count($path) - 1]; $last_i = count($path) - 1; foreach ($path as $k => $v) { $category_path = trim($prefix . $v, '/'); if (is_category_path($category_path) && is_category_exists($category_path)) { $c = new Category($category_path); if ($k == $last_i) { echo '<b>' . $c->name() . '</b>' . "\n"; } else { echo '<a href="' . $prefix . $v . '">' . $c->name() . '</a> →' . "\n"; } } elseif (is_example_path($category_path) && is_example_exists($category_path)) { echo '<b>пример #' . $id . '</b>' . "\n"; } $prefix = $prefix . $v . '/'; } ?> </div>
public function testIsExampleExistsRaiseException() { $this->expectException(Exception::class); is_example_exists('php/HelLo.md'); }