Passed
Push — master ( 17602b...453007 )
by Chris
04:37
created

Setup   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 3
dl 0
loc 99
c 0
b 0
f 0
rs 10
1
<?php
2
/*
3
This project is Licenced under The MIT License (MIT)
4
5
Copyright (c) 2014 Christopher Seufert
6
7
Permission is hereby granted, free of charge, to any person obtaining a copy
8
of this software and associated documentation files (the "Software"), to deal
9
in the Software without restriction, including without limitation the rights
10
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
copies of the Software, and to permit persons to whom the Software is
12
furnished to do so, subject to the following conditions:
13
14
The above copyright notice and this permission notice shall be included in
15
all copies or substantial portions of the Software.
16
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
THE SOFTWARE.
24
25
 */
26
namespace Seufert\Hamle;
27
/**
28
 * Basic HAMLE Setup Class
29
 * This class should be extended to override the Model Methods, 
30
 * to use your model
31
 *
32
 * @author Chris Seufert <[email protected]>
33
 */
34
class Setup {
35
  /**
36
   * Returns the full file path to the cache file
37
   * 
38
   * @param string $f Filename of cache file
39
   * @return string Directory to store cache in
40
   */
41
  public function cachePath($f) {
42
    $s = DIRECTORY_SEPARATOR;
43
    $dir = implode($s,[__DIR__,"..","..","cache",""]);
44
    if(!is_dir($dir)) mkdir($dir);
45
    return $dir.$f;
46
  }
47
48
  /**
49
   * Open the default model when only an ID is specified in the template
50
   *
51
   * @param mixed $id Identifier when no type is passed
52
   * @param array $sort
53
   * @param int $limit Results Limit
54
   * @param int $offset Results Offset
55
   * @return Model Instance of model class that implements hamleModel
56
   */
57
  public function getModelDefault($id, $sort = [], $limit = 0, $offset = 0) { return new Model\Zero(); }
58
59
  /**
60
   * Open a specific model type with id
61
   *
62
   * @param array[] $typeId Type ID array [type=>[id]] or [page=>[3]]
63
   * @param array $sort
64
   * @param int $limit Results Limit
65
   * @param int $offset Results Offset
66
   * @return Model
67
   * @throws Exception\RunTime
68
   */
69
  public function getModelTypeID($typeId, $sort = [], $limit = 0, $offset = 0) {
70
    if(count($typeId) > 1)
71
      throw new Exception\RunTime("Unable to open more than one ID at a time");
72
    return new Model\Zero();
73
  }
74
75
  /**
76
   * Return Iterator containing results from search of tags
77
   *
78
   * @param array[] $typeTags Type Tag Array [type=>[tag1,tag2],type2=>[]]
79
   * @param array $sort
80
   * @param int $limit Results Limit
81
   * @param int $offset Results Limit
82
   * @return Model Instance of Iterable model class
83
   */
84
  public function getModelTypeTags($typeTags, $sort = [], $limit = 0, $offset = 0) {
85
    return new Model\Zero();
86
  }
87
  /**
88
   * Give you the ability to adjust paths to template files, this includes files
89
   * loaded using '|include'.
90
   * 
91
   * @param string $f File Name and Path requested
92
   * @return string File Path to actual template file
93
   */
94
  public function templatePath($f) {
95
    return $f;
96
  }
97
  /**
98
   * Returns an array of snippets paths for application to the current template
99
   * These snippets will be applied to templates |included as well as the
100
   * initial template.
101
   * 
102
   * @return array Array of file names
103
   */
104
  public function snippetFiles() {
105
    return array();
106
  }
107
108
  /**
109
   * @return Parse\Filter[] List of HAMLE Parse Filters
110
   */
111
  public function getFilters() {
112
    return array();
113
  }
114
  /**
115
   * Function to write debug logs out
116
   * @param $s string Debug Message String
117
   */
118
  public function debugLog($s) {
119
    //var_dump($s);
120
  }
121
122
  /**
123
   * Called when |include "#fragment" is encountered
124
   * @param Hamle $hamle Current Hamle Instance
125
   * @param string $fragment Name of Fragment
126
   * @throws Exception
127
   */
128
  public function getFragment(Hamle $hamle, $fragment) {
129
    throw new Exception("Unable to Include Fragment $fragment");
130
  }
131
132
}
133