Subversion Repositories PHPX

Rev

Rev 64 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 64 Rev 70
Line 30... Line 30...
30
   * @var array
30
   * @var array
31
   */
31
   */
32
  protected $_template_vars = array();
32
  protected $_template_vars = array();
33
33
34
  /**
34
  /**
-
 
35
   * Stylesheets to be inserted into the <code>head</code> element
-
 
36
   *
-
 
37
   * @var array
-
 
38
   */
-
 
39
  protected $_stylesheets = array();
-
 
40
-
 
41
  /**
-
 
42
   * Scripts to be inserted into the <code>head</code> or
-
 
43
   * <code>body</code> element
-
 
44
   *
-
 
45
   * @var array
-
 
46
   */
-
 
47
  protected $_scripts = array();
-
 
48
-
 
49
  /**
35
   * Creates a new view
50
   * Creates a new view
36
   *
51
   *
37
   * @param string $template
52
   * @param string $template
38
   *   Template resource path
53
   *   Template resource path
39
   */
54
   */
Line 133... Line 148...
133
    $this->$name = $value;
148
    $this->$name = $value;
134
    return $value;
149
    return $value;
135
  }
150
  }
136
151
137
  /**
152
  /**
-
 
153
   * Adds a CSS resource (stylesheet) to the list of external
-
 
154
   * stylesheets
-
 
155
   *
-
 
156
   * @param string $uri
-
 
157
   *   Stylesheet URI
-
 
158
   * @param mixed $key (optional)
-
 
159
   *   Array key for the script.  May be used later to exclude
-
 
160
   *   or include the code for a specific stylesheet.
-
 
161
   */
-
 
162
  public function addStylesheet ($uri, $key = null)
-
 
163
  {
-
 
164
    $stylesheets =& $this->_stylesheets;
-
 
165
-
 
166
    if ($key !== null)
-
 
167
    {
-
 
168
      $stylesheets[$key] = $uri;
-
 
169
    }
-
 
170
    else
-
 
171
    {
-
 
172
      $stylesheets[] = $uri;
-
 
173
    }
-
 
174
  }
-
 
175
-
 
176
  /**
-
 
177
   * Adds an ECMAScript resource (script) to the list of external
-
 
178
   * scripts
-
 
179
   *
-
 
180
   * @param string $uri
-
 
181
   *   Script URI
-
 
182
   * @param mixed $key (optional)
-
 
183
   *   Array key for the script.  May be used later to exclude
-
 
184
   *   or include the code for a specific script.
-
 
185
   */
-
 
186
  public function addScript ($uri, $key = null)
-
 
187
  {
-
 
188
    $scripts =& $this->_scripts;
-
 
189
-
 
190
    if ($key !== null)
-
 
191
    {
-
 
192
      $scripts[$key] = $uri;
-
 
193
    }
-
 
194
    else
-
 
195
    {
-
 
196
      $scripts[] = $uri;
-
 
197
    }
-
 
198
  }
-
 
199
-
 
200
  /**
138
   * Renders the view by including a template
201
   * Renders the view by including a template
139
   *
202
   *
140
   * @param string $template
203
   * @param string $template
141
   *   Optional alternative template resource path.
204
   *   Optional alternative template resource path.
142
   *   If not provided, the default template ($template property) will be used.
205
   *   If not provided, the default template ($template property) will be used.
Line 165... Line 228...
165
      throw new \Exception('No template defined');
228
      throw new \Exception('No template defined');
166
    }
229
    }
167
  }
230
  }
168
231
169
  /**
232
  /**
-
 
233
   * Returns the code for including all stylesheets,
-
 
234
   * with exclusions.
-
 
235
   *
-
 
236
   * @param array $exclusions (optional, future)
-
 
237
   *   The keys of the stylesheets that should be excluded
-
 
238
   * @return string
-
 
239
   */
-
 
240
  public function getStylesheets ($exclusions = array())
-
 
241
  {
-
 
242
    return (
-
 
243
      implode(PHP_EOL, array_map(function ($uri) {
-
 
244
        return '<link rel="stylesheet" href="' . $this->escape($uri) . '">';
-
 
245
      }, array_diff_key($this->_stylesheets, array_flip($exclusions))))
-
 
246
      . PHP_EOL);
-
 
247
  }
-
 
248
-
 
249
  /**
-
 
250
   * Returns the code for including a specific stylesheet
-
 
251
   *
-
 
252
   * @param mixed $key
-
 
253
   * @return string
-
 
254
   */
-
 
255
  public function getStylesheet ($key)
-
 
256
  {
-
 
257
    return '<link rel="stylesheet" href="'
-
 
258
      . $this->escape($this->_stylesheets[$key])
-
 
259
      . '">' . PHP_EOL;
-
 
260
  }
-
 
261
-
 
262
  /**
-
 
263
   * Returns the code for including all stylesheets,
-
 
264
   * with exclusions.
-
 
265
   *
-
 
266
   * @param array $exclusions (optional, future)
-
 
267
   *   The keys of the scripts that should be excluded.
-
 
268
   *   Usually you would specify those scripts that you
-
 
269
   *   want to include with {@link #getScript()}.
-
 
270
   * @return string
-
 
271
   */
-
 
272
  public function getScripts ($exclusions = array())
-
 
273
  {
-
 
274
    return (
-
 
275
     implode(PHP_EOL, array_map(function ($uri) {
-
 
276
        return '<script type="text/javascript" src="'
-
 
277
          . $this->escape($uri)
-
 
278
          . '"></script>';
-
 
279
      }, array_diff_key($this->_scripts, array_flip($exclusions))))
-
 
280
      . PHP_EOL);
-
 
281
  }
-
 
282
-
 
283
  public function getScript ($key)
-
 
284
  {
-
 
285
    return '<link rel="stylesheet" href="'
-
 
286
      . $this->escape($this->_scripts[$key])
-
 
287
      . '">' . PHP_EOL;
-
 
288
  }
-
 
289
-
 
290
  /**
170
   * Returns the content for insertion into the template
291
   * Returns the content for insertion into the template
171
   */
292
   */
172
  public function getContent()
293
  public function getContent ()
173
  {
294
  {
174
    return $this->_content;
295
    return $this->_content;