", $this->controlSize);
274 | }
275 |
276 | /**
277 | * Checks if both the label size and control size are invalid
278 | *
279 | * @param int $labelSize The size of the label
280 | * @param int $controlSize The size of the control group
281 | * @return bool
282 | */
283 | protected function sizesAreInvalid($labelSize = null, $controlSize = null)
284 | {
285 | // If both are null then we have a valid size
286 | if (!isset($labelSize) && !isset($controlSize)) {
287 | return false;
288 | }
289 |
290 | // So at least one of these is null
291 | if (isset($labelSize)) {
292 | if ($this->sizeIsInvalid($labelSize)) {
293 | return true;
294 | }
295 | } else {
296 | $labelSize = 0;
297 | }
298 |
299 | if (isset($controlSize)) {
300 | if ($this->sizeIsInvalid($controlSize)) {
301 | return true;
302 | }
303 | } else {
304 | $controlSize = 0;
305 | }
306 |
307 | return $this->sizeIsInvalid($labelSize + $controlSize);
308 | }
309 |
310 | /**
311 | * Checks if the size is invalid
312 | *
313 | * @param int $size The size
314 | * @return bool True if the size is below 1 or greater than 11,
315 | * false otherwise
316 | */
317 | protected function sizeIsInvalid($size)
318 | {
319 | return $size < 1 || $size > 12;
320 | }
321 | }
322 |
--------------------------------------------------------------------------------
/src/Bootstrapper/DropdownButton.php:
--------------------------------------------------------------------------------
1 | ";
19 |
20 | /**
21 | * Constant for primary buttons
22 | */
23 | const PRIMARY = 'btn-primary';
24 |
25 | /**
26 | * Constant for danger buttons
27 | */
28 | const DANGER = 'btn-danger';
29 |
30 | /**
31 | * Constant for warning buttons
32 | */
33 | const WARNING = 'btn-warning';
34 |
35 | /**
36 | * Constant for success buttons
37 | */
38 | const SUCCESS = 'btn-success';
39 |
40 | /**
41 | * Constant for default buttons
42 | */
43 | const NORMAL = 'btn-default';
44 |
45 | /**
46 | * Constant for info buttons
47 | */
48 | const INFO = 'btn-info';
49 |
50 | /**
51 | * Constant for large buttons
52 | */
53 | const LARGE = 'btn-lg';
54 |
55 | /**
56 | * Constant for small buttons
57 | */
58 | const SMALL = 'btn-sm';
59 |
60 | /**
61 | * Constant for extra small buttons
62 | */
63 | const EXTRA_SMALL = 'btn-xs';
64 |
65 | /**
66 | * @var string The label for this button
67 | */
68 | protected $label;
69 |
70 | /**
71 | * @var array The contents of the dropdown button
72 | */
73 | protected $contents = [];
74 |
75 | /**
76 | * @var string The type of the button
77 | */
78 | protected $type = 'btn-default';
79 |
80 | /**
81 | * @var string The size of the button
82 | */
83 | protected $size;
84 |
85 | /**
86 | * @var bool Whether the drop icon should be a seperate button
87 | */
88 | protected $split = false;
89 |
90 | /**
91 | * @var bool Whether the button should drop up
92 | */
93 | protected $dropup = false;
94 |
95 | /**
96 | * Set the label of the button
97 | *
98 | * @param $label
99 | * @return $this
100 | */
101 | public function labelled($label)
102 | {
103 | $this->label = $label;
104 |
105 | return $this;
106 | }
107 |
108 | /**
109 | * Set the contents of the button
110 | *
111 | * @param array $contents The contents of the dropdown button
112 | * @return $this
113 | */
114 | public function withContents(array $contents)
115 | {
116 | $this->contents = $contents;
117 |
118 | return $this;
119 | }
120 |
121 | /**
122 | * Sets the type of the button
123 | *
124 | * @param string $type The type of the button
125 | * @return $this
126 | */
127 | public function setType($type)
128 | {
129 | $this->type = $type;
130 |
131 | return $this;
132 | }
133 |
134 | /**
135 | * Sets the size of the button
136 | *
137 | * @param string $size The size of the button
138 | * @return $this
139 | */
140 | public function setSize($size)
141 | {
142 | $this->size = $size;
143 |
144 | return $this;
145 | }
146 |
147 | /**
148 | * Splits the button
149 | *
150 | * @return $this
151 | */
152 | public function split()
153 | {
154 | $this->split = true;
155 |
156 | return $this;
157 | }
158 |
159 | /**
160 | * Sets the button to drop up
161 | *
162 | * @return $this
163 | */
164 | public function dropup()
165 | {
166 | $this->dropup = true;
167 |
168 | return $this;
169 | }
170 |
171 | /**
172 | * Creates a normal dropdown button
173 | *
174 | * @param string $label The label
175 | * @return $this
176 | */
177 | public function normal($label = '')
178 | {
179 | $this->setType(self::NORMAL);
180 |
181 | return $this->labelled($label);
182 | }
183 |
184 | /**
185 | * Creates a primary dropdown button
186 | *
187 | * @param string $label The label
188 | * @return $this
189 | */
190 | public function primary($label = '')
191 | {
192 | $this->setType(self::PRIMARY);
193 |
194 | return $this->labelled($label);
195 | }
196 |
197 | /**
198 | * Creates a danger dropdown button
199 | *
200 | * @param string $label The label
201 | * @return $this
202 | */
203 | public function danger($label = '')
204 | {
205 | $this->setType(self::DANGER);
206 |
207 | return $this->labelled($label);
208 | }
209 |
210 | /**
211 | * Creates a warning dropdown button
212 | *
213 | * @param string $label The label
214 | * @return $this
215 | */
216 | public function warning($label = '')
217 | {
218 | $this->setType(self::WARNING);
219 |
220 | return $this->labelled($label);
221 | }
222 |
223 | /**
224 | * Creates a success dropdown button
225 | *
226 | * @param string $label The label
227 | * @return $this
228 | */
229 | public function success($label = '')
230 | {
231 | $this->setType(self::SUCCESS);
232 |
233 | return $this->labelled($label);
234 | }
235 |
236 | /**
237 | * Creates a info dropdown button
238 | *
239 | * @param string $label The label
240 | * @return $this
241 | */
242 | public function info($label = '')
243 | {
244 | $this->setType(self::INFO);
245 |
246 | return $this->labelled($label);
247 | }
248 |
249 | /**
250 | * Sets the size to large
251 | *
252 | * @return $this
253 | */
254 | public function large()
255 | {
256 | $this->setSize(self::LARGE);
257 |
258 | return $this;
259 | }
260 |
261 |
262 | /**
263 | * Sets the size to small
264 | *
265 | * @return $this
266 | */
267 | public function small()
268 | {
269 | $this->setSize(self::SMALL);
270 |
271 | return $this;
272 | }
273 |
274 | /**
275 | * Sets the size to extra small
276 | *
277 | * @return $this
278 | */
279 | public function extraSmall()
280 | {
281 | $this->setSize(self::EXTRA_SMALL);
282 |
283 | return $this;
284 | }
285 |
286 | /**
287 | * Renders the dropdown button
288 | *
289 | * @return string
290 | */
291 | public function render()
292 | {
293 | if ($this->dropup) {
294 | $string = "
";
295 | } else {
296 | $string = "
";
297 | }
298 | $attributes = new Attributes(
299 | $this->attributes,
300 | [
301 | 'class' => "btn {$this->type} dropdown-toggle",
302 | 'data-toggle' => 'dropdown',
303 | 'type' => 'button'
304 | ]
305 | );
306 |
307 | if ($this->size) {
308 | $attributes->addClass($this->size);
309 | }
310 |
311 | if ($this->split) {
312 | $splitAttributes = new Attributes(
313 | ['class' => $attributes['class'], 'type' => 'button']
314 | );
315 | $splitAttributes['class'] = str_replace(
316 | ' dropdown-toggle',
317 | '',
318 | $splitAttributes['class']
319 | );
320 | $string .= "";
321 | $string .= "";
322 | } else {
323 | $string .= "";
324 | }
325 |
326 | $string .= "";
329 | $string .= "
";
330 |
331 | return $string;
332 | }
333 |
334 | /**
335 | * Render the inner items
336 | *
337 | * @return string
338 | */
339 | protected function renderItems()
340 | {
341 | $string = '';
342 | foreach ($this->contents as $item) {
343 | if (is_array($item)) {
344 | $string .= "
{$item['label']}";
345 | } else {
346 | $string .= $item;
347 | }
348 | }
349 |
350 | return $string;
351 | }
352 | }
353 |
--------------------------------------------------------------------------------
/src/Bootstrapper/Exceptions/AccordionException.php:
--------------------------------------------------------------------------------
1 | $method();
41 |
42 | case 1:
43 | return $instance->$method($args[0]);
44 |
45 | case 2:
46 | return $instance->$method($args[0], $args[1]);
47 |
48 | case 3:
49 | return $instance->$method($args[0], $args[1], $args[2]);
50 |
51 | case 4:
52 | return $instance->$method(
53 | $args[0],
54 | $args[1],
55 | $args[2],
56 | $args[3]
57 | );
58 |
59 | default:
60 | return call_user_func_array(array($instance, $method), $args);
61 | }
62 | }
63 |
64 | /**
65 | * Get an instance out of the IoC, or the cached instance
66 | *
67 | * @param string $facade The facade accessor
68 | * @return mixed The Bootstrapper object
69 | */
70 | private static function getInstance($facade)
71 | {
72 | if (!isset(static::$instances[$facade])) {
73 | static::$instances[$facade] = static::getFacadeRoot();
74 | }
75 |
76 | return static::$instances[$facade];
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/Bootstrapper/Facades/Breadcrumb.php:
--------------------------------------------------------------------------------
1 | ";
17 | const PRIMARY = 'btn-primary';
18 | const DANGER = 'btn-danger';
19 | const WARNING = 'btn-warning';
20 | const SUCCESS = 'btn-success';
21 | const INFO = 'btn-info';
22 | const LARGE = 'btn-lg';
23 | const SMALL = 'btn-sm';
24 | const EXTRA_SMALL = 'btn-xs';
25 |
26 | /**
27 | * {@inheritdoc}
28 | * @return string
29 | */
30 | protected static function getFacadeAccessor()
31 | {
32 | return 'bootstrapper::dropdownbutton';
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Bootstrapper/Facades/Form.php:
--------------------------------------------------------------------------------
1 | open($attributes);
102 | }
103 |
104 | /**
105 | * Opens a horizontal form
106 | *
107 | * @param array $attributes
108 | * @return string
109 | */
110 | public function horizontal($attributes = [])
111 | {
112 | $attributes['class'] = isset($attributes['class']) ?
113 | self::FORM_HORIZONTAL . ' ' . $attributes['class'] :
114 | self::FORM_HORIZONTAL;
115 |
116 | return $this->open($attributes);
117 | }
118 |
119 | /**
120 | * Creates a validation block
121 | *
122 | * @param string $type The type of validation
123 | * @param string $label The label
124 | * @param string $input The input
125 | * @param array $attributes The attributes of the validation block
126 | * @return string
127 | */
128 | public function validation($type, $label, $input, $attributes = [])
129 | {
130 | $attributes['class'] = isset($attributes['class']) ?
131 | "form-group {$type} " . $attributes['class'] :
132 | "form-group {$type} ";
133 | $attributes = new Attributes($attributes);
134 |
135 | return "
{$label}{$input}
";
136 | }
137 |
138 | /**
139 | * Creates a success validation block
140 | *
141 | * @param string $label The label
142 | * @param string $input The input
143 | * @param array $attributes The attributes of the validation block
144 | * @return string
145 | * @see Bootstrapper\\Form::validation()
146 | */
147 | public function success($label, $input, $attributes = [])
148 | {
149 | return ($this->validation(
150 | self::FORM_SUCCESS,
151 | $label,
152 | $input,
153 | $attributes
154 | ));
155 | }
156 |
157 | /**
158 | * Creates a warning validation block
159 | *
160 | * @param string $label The label
161 | * @param string $input The input
162 | * @param array $attributes The attributes of the validation block
163 | * @return string
164 | * @see Bootstrapper\\Form::validation()
165 | */
166 | public function warning($label, $input, $attributes = [])
167 | {
168 | return ($this->validation(
169 | Form::FORM_WARNING,
170 | $label,
171 | $input,
172 | $attributes
173 | ));
174 | }
175 |
176 | /**
177 | * Creates an error validation block
178 | *
179 | * @param string $label The label
180 | * @param string $input The input
181 | * @param array $attributes The attributes of the validation block
182 | * @return string
183 | * @see Bootstrapper\\Form::validation()
184 | */
185 | public function error($label, $input, $attributes = [])
186 | {
187 | return ($this->validation(
188 | Form::FORM_ERROR,
189 | $label,
190 | $input,
191 | $attributes
192 | ));
193 | }
194 |
195 | /**
196 | * Creates a feedback block with an icon
197 | *
198 | * @param string $label The label
199 | * @param string $input The input
200 | * @param string $icon The icon
201 | * @param array $attributes The attributes of the block
202 | * @return string
203 | */
204 | public function feedback($label, $input, $icon, $attributes = [])
205 | {
206 | $attributes['class'] = isset($attributes['class']) ?
207 | 'form-group has-feedback ' . $attributes['class'] :
208 | 'form-group has-feedback';
209 | $attributes = new Attributes($attributes);
210 | $icon = "
";
211 |
212 | return "
{$label}{$input}{$icon}
";
213 | }
214 |
215 | /**
216 | * Creates a help block
217 | *
218 | * @param string $helpText The help text
219 | * @param array $attributes
220 | * @return string
221 | */
222 | public function help($helpText, $attributes = [])
223 | {
224 | $attributes['class'] = isset($attributes['class']) ?
225 | 'help-block ' . $attributes['class'] :
226 | 'help-block';
227 | $attributes = new Attributes($attributes);
228 |
229 | return "
{$helpText}";
230 | }
231 |
232 | /**
233 | * Opens a horizontal form with a given model
234 | *
235 | * @param mixed $model
236 | * @param array $attributes
237 | * @return string
238 | * @see Bootstrapper\Form::horizontal()
239 | * @see Illuminate\Html::model()
240 | */
241 | public function horizontalModel($model, $attributes = [])
242 | {
243 | $attributes['class'] = isset($attributes['class']) ?
244 | self::FORM_HORIZONTAL . ' ' . $attributes['class'] :
245 | self::FORM_HORIZONTAL;
246 |
247 | return $this->model($model, $attributes);
248 | }
249 |
250 | /**
251 | * Opens a inline form with a given model
252 | *
253 | * @param mixed $model
254 | * @param array $attributes
255 | * @return string
256 | * @see Bootstrapper\Form::inline()
257 | * @see Illuminate\Html::model()
258 | */
259 | public function inlineModel($model, $attributes = [])
260 | {
261 | $attributes['class'] = isset($attributes['class']) ?
262 | self::FORM_INLINE . ' ' . $attributes['class'] :
263 | self::FORM_INLINE;
264 |
265 | return $this->model($model, $attributes);
266 | }
267 |
268 | /**
269 | * {@inheritdoc}
270 | * @param string $name
271 | * @param array $list
272 | * @param null $selected
273 | * @param array $selectAttributes
274 | * @param array $optionsAttributes
275 | * @return string
276 | */
277 | public function select(
278 | $name,
279 | $list = [],
280 | $selected = null,
281 | array $selectAttributes = [],
282 | array $optionsAttributes = [],
283 | array $optgroupsAttributes = []
284 | ) {
285 | $selectAttributes['class'] = isset($selectAttributes['class']) ?
286 | self::FORM_CONTROL . ' ' . $selectAttributes['class'] :
287 | self::FORM_CONTROL;
288 |
289 | return parent::select($name, $list, $selected, $selectAttributes, $optionsAttributes, $optgroupsAttributes);
290 | }
291 |
292 | /**
293 | * {@inheritdoc}
294 | * @param string $name The name of the text area
295 | * @param string|null $value The default value
296 | * @param array $attributes The attributes of the text area
297 | * @return string
298 | */
299 | public function textarea($name, $value = null, $attributes = array())
300 | {
301 | $attributes['class'] = isset($attributes['class']) ?
302 | self::FORM_CONTROL . ' ' . $attributes['class'] :
303 | self::FORM_CONTROL;
304 |
305 | return parent::textarea($name, $value, $attributes);
306 | }
307 |
308 | /**
309 | * {@inheritdoc}
310 | * @param string $name The name of the password input
311 | * @param array $attributes The attributes of the input
312 | * @return string
313 | */
314 | public function password($name, $attributes = array())
315 | {
316 | $attributes['class'] = isset($attributes['class']) ?
317 | self::FORM_CONTROL . ' ' . $attributes['class'] :
318 | self::FORM_CONTROL;
319 |
320 | return parent::password($name, $attributes);
321 | }
322 |
323 | /**
324 | * {@inheritdoc}
325 | * @param string $name The name of the text input
326 | * @param string|null $value The default value
327 | * @param array $attributes The attributes of the input
328 | * @return string
329 | */
330 | public function text($name, $value = null, $attributes = array())
331 | {
332 | $attributes['class'] = isset($attributes['class']) ?
333 | self::FORM_CONTROL . ' ' . $attributes['class'] :
334 | self::FORM_CONTROL;
335 |
336 | return parent::text($name, $value, $attributes);
337 | }
338 |
339 | /**
340 | * {@inheritdoc}
341 | * @param string $name The name of the email input
342 | * @param string|null $value The default value of the input
343 | * @param array $attributes The attributes of the email input
344 | * @return string
345 | */
346 | public function email($name, $value = null, $attributes = array())
347 | {
348 | $attributes['class'] = isset($attributes['class']) ?
349 | self::FORM_CONTROL . ' ' . $attributes['class'] :
350 | self::FORM_CONTROL;
351 |
352 | return parent::email($name, $value, $attributes);
353 | }
354 |
355 | /**
356 | * Creates a datetime form element
357 | *
358 | * @param string $name The name of the element
359 | * @param null $value The value
360 | * @param array $attributes The attributes
361 | * @return string
362 | * @see Illuminate\FormBuilder\input()
363 | */
364 | public function datetime($name, $value = null, $attributes = array())
365 | {
366 | $attributes['class'] = isset($attributes['class']) ?
367 | self::FORM_CONTROL . ' ' . $attributes['class'] :
368 | self::FORM_CONTROL;
369 |
370 | return parent::input('datetime', $name, $value, $attributes);
371 | }
372 |
373 | /**
374 | * Creates a datetime local element
375 | *
376 | * @param string $name The name of the element
377 | * @param null $value
378 | * @param array $attributes
379 | * @return string
380 | * @see Illuminate\FormBuilder\input()
381 | */
382 | public function datetimelocal($name, $value = null, $attributes = array())
383 | {
384 | $attributes['class'] = isset($attributes['class']) ?
385 | self::FORM_CONTROL . ' ' . $attributes['class'] :
386 | self::FORM_CONTROL;
387 |
388 | return parent::input('datetime-local', $name, $value, $attributes);
389 | }
390 |
391 | /**
392 | * Creates a date input
393 | *
394 | * @param string $name The name of the element
395 | * @param null $value
396 | * @param array $attributes
397 | * @return string
398 | */
399 | public function date($name, $value = null, $attributes = array())
400 | {
401 | $attributes['class'] = isset($attributes['class']) ?
402 | self::FORM_CONTROL . ' ' . $attributes['class'] :
403 | self::FORM_CONTROL;
404 |
405 | return parent::input('date', $name, $value, $attributes);
406 | }
407 |
408 | /**
409 | * Creates a month input
410 | *
411 | * @param string $name The name of the element
412 | * @param null $value
413 | * @param array $attributes
414 | * @return string
415 | */
416 | public function month($name, $value = null, $attributes = array())
417 | {
418 | $attributes['class'] = isset($attributes['class']) ?
419 | self::FORM_CONTROL . ' ' . $attributes['class'] :
420 | self::FORM_CONTROL;
421 |
422 | return parent::input('month', $name, $value, $attributes);
423 | }
424 |
425 | /**
426 | * Creates a week form element
427 | *
428 | * @param string $name The name of the element
429 | * @param null $value
430 | * @param array $attributes
431 | * @return string
432 | */
433 | public function week($name, $value = null, $attributes = array())
434 | {
435 | $attributes['class'] = isset($attributes['class']) ?
436 | self::FORM_CONTROL . ' ' . $attributes['class'] :
437 | self::FORM_CONTROL;
438 |
439 | return parent::input('week', $name, $value, $attributes);
440 | }
441 |
442 | /**
443 | * Creates a time form element
444 | *
445 | * @param string $name The name of the element
446 | * @param null $value
447 | * @param array $attributes
448 | * @return string
449 | */
450 | public function time($name, $value = null, $attributes = array())
451 | {
452 | $attributes['class'] = isset($attributes['class']) ?
453 | self::FORM_CONTROL . ' ' . $attributes['class'] :
454 | self::FORM_CONTROL;
455 |
456 | return parent::input('time', $name, $value, $attributes);
457 | }
458 |
459 | /**
460 | * Creates a number form element
461 | *
462 | * @param string $name The name of the element
463 | * @param null $value
464 | * @param array $attributes
465 | * @return string
466 | */
467 | public function number($name, $value = null, $attributes = array())
468 | {
469 | $attributes['class'] = isset($attributes['class']) ?
470 | self::FORM_CONTROL . ' ' . $attributes['class'] :
471 | self::FORM_CONTROL;
472 |
473 | return parent::input('number', $name, $value, $attributes);
474 | }
475 |
476 | /**
477 | * Creates a url form element
478 | *
479 | * @param string $name The name of the element
480 | * @param null $value
481 | * @param array $attributes
482 | * @return string
483 | */
484 | public function url($name, $value = null, $attributes = array())
485 | {
486 | $attributes['class'] = isset($attributes['class']) ?
487 | self::FORM_CONTROL . ' ' . $attributes['class'] :
488 | self::FORM_CONTROL;
489 |
490 | return parent::input('url', $name, $value, $attributes);
491 | }
492 |
493 | /**
494 | * Creates a search element
495 | *
496 | * @param string $name The name of the element
497 | * @param null $value
498 | * @param array $attributes
499 | * @return string
500 | */
501 | public function search($name, $value = null, $attributes = array())
502 | {
503 | $attributes['class'] = isset($attributes['class']) ?
504 | self::FORM_CONTROL . ' ' . $attributes['class'] :
505 | self::FORM_CONTROL;
506 |
507 | return parent::input('search', $name, $value, $attributes);
508 | }
509 |
510 | /**
511 | * Creates a tel element
512 | *
513 | * @param string $name The name of the element
514 | * @param null $value
515 | * @param array $attributes
516 | * @return string
517 | */
518 | public function tel($name, $value = null, $attributes = array())
519 | {
520 | $attributes['class'] = isset($attributes['class']) ?
521 | self::FORM_CONTROL . ' ' . $attributes['class'] :
522 | self::FORM_CONTROL;
523 |
524 | return parent::input('tel', $name, $value, $attributes);
525 | }
526 |
527 | /**
528 | * Creates a color element
529 | *
530 | * @param string $name The name of the element
531 | * @param null $value
532 | * @param array $attributes
533 | * @return string
534 | */
535 | public function color($name, $value = null, $attributes = array())
536 | {
537 | $attributes['class'] = isset($attributes['class']) ?
538 | self::FORM_CONTROL . ' ' . $attributes['class'] :
539 | self::FORM_CONTROL;
540 |
541 | return parent::input('color', $name, $value, $attributes);
542 | }
543 |
544 | /**
545 | * Determine whether the form element with the given name
546 | * has any validation errors.
547 | *
548 | * @param string $name
549 | * @return bool
550 | */
551 | public function hasErrors($name)
552 | {
553 | $session = $this->getSessionStore();
554 | if (is_null($session) || !$session->has('errors')) {
555 | // If the session is not set, or the session doesn't contain
556 | // any errors, the form element does not have any errors
557 | // applied to it.
558 | return false;
559 | }
560 | // Get the errors from the session.
561 | $errors = $session->get('errors');
562 | // Check if the errors contain the form element with the given name.
563 | return $errors->has($this->transformKey($name));
564 | }
565 |
566 | /**
567 | * Get the formatted errors for the form element with the given name.
568 | *
569 | * @param string $name
570 | * @return string
571 | */
572 | public function getFormattedError($name)
573 | {
574 | if (!$this->hasErrors($name)) {
575 | // If the form element does not have any errors, return
576 | // an emptry string.
577 | return '';
578 | }
579 | // Get the errors from the session.
580 | $errors = $this->getSessionStore()->get('errors');
581 |
582 | // Return the formatted error message, if the form element has any.
583 | return $errors->first($this->transformKey($name), $this->help(':message'));
584 | }
585 | }
586 |
--------------------------------------------------------------------------------
/src/Bootstrapper/Helpers.php:
--------------------------------------------------------------------------------
1 | config = $config;
39 | }
40 |
41 | /**
42 | * Slugifies a string
43 | *
44 | * @param string $string
45 | * @return mixed
46 | */
47 | public static function slug($string)
48 | {
49 | return preg_replace('/[^A-Za-z0-9-]+/', '-', strtolower($string));
50 | }
51 |
52 | /**
53 | * Outputs a link to the Bootstrap CDN
54 | *
55 | * @param bool $withTheme Gets the bootstrap theme as well
56 | * @return string
57 | */
58 | public function css($withTheme = true)
59 | {
60 | $version = $this->config->getBootstrapperVersion();
61 | $string = "
";
62 | if ($withTheme) {
63 | $string .= "
";
65 | }
66 |
67 | return $string;
68 | }
69 |
70 | /**
71 | * Outputs a link to the Jquery and Bootstrap CDN
72 | *
73 | * @return string
74 | */
75 | public function js()
76 | {
77 | $jquery = $this->config->getJQueryVersion();
78 | $bootstrap = $this->config->getBootstrapperVersion();
79 |
80 | return ""
81 | . "";
82 | }
83 |
84 | /**
85 | * Generate an id of the form "x-class-name-x". These should always be
86 | * unique.
87 | *
88 | * @param RenderedObject $caller The object that called this
89 | * @return string A unique id
90 | */
91 | public static function generateId(RenderedObject $caller)
92 | {
93 | $class = get_class($caller);
94 |
95 | if (isset(self::$counts[$class])) {
96 | $count = self::$counts[$class];
97 | self::$counts[$class] += 1;
98 | } else {
99 | $count = 1;
100 | self::$counts[$class] = 2;
101 | }
102 |
103 | return static::slug(implode(' ', [$count, $class, $count]));
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/Bootstrapper/Icon.php:
--------------------------------------------------------------------------------
1 | config = $config;
37 | }
38 |
39 | /**
40 | * Renders the object
41 | *
42 | * @return string
43 | * @throws IconException
44 | */
45 | public function render()
46 | {
47 | if (is_null($this->icon)) {
48 | throw IconException::noIconSpecified();
49 | }
50 |
51 | $baseClass = $this->config->getIconPrefix();
52 | $icon = $this->icon;
53 | $attributes = new Attributes(
54 | $this->attributes,
55 | [
56 | 'class' => "$baseClass $baseClass-$icon"
57 | ]
58 | );
59 |
60 | $tag = $this->config->getIconTag();
61 |
62 | return "<$tag $attributes>$tag>";
63 | }
64 |
65 | /**
66 | * Creates a span link with the correct icon link
67 | *
68 | * @param string $icon The icon name
69 | * @return string
70 | */
71 | public function create($icon)
72 | {
73 | $this->icon = $this->normaliseIconString($icon);
74 |
75 | return $this;
76 | }
77 |
78 | /**
79 | * Magic method to create icons. Meaning the $icon->test is the same as
80 | * $icon->create('test')
81 | *
82 | * @param $method The icon name
83 | * @param $parameters The parameters. Not used
84 | * @return string
85 | */
86 | public function __call($method, $parameters)
87 | {
88 | return $this->create($method);
89 | }
90 |
91 | /**
92 | * Replaces underscores with a minus sign, and convert camelCase to dash
93 | * separated
94 | *
95 | * @param string $icon
96 | * @return string
97 | */
98 | private function normaliseIconString($icon)
99 | {
100 | // replace underscores with minus sign
101 | // and transform from camelCaseString to camel-case-string
102 | $icon = strtolower(
103 | preg_replace(
104 | '/(?<=\\w)(?=[A-Z])/',
105 | "-$1",
106 | str_replace('_', '-', $icon)
107 | )
108 | );
109 |
110 | return $icon;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/Bootstrapper/Image.php:
--------------------------------------------------------------------------------
1 | src) {
57 | throw new ImageException("You must specify the source");
58 | }
59 |
60 | $attributes = new Attributes(
61 | $this->attributes,
62 | ['src' => $this->src, 'alt' => $this->alt]
63 | );
64 |
65 | return "
![]()
";
66 | }
67 |
68 | /**
69 | * Sets the source of the image
70 | *
71 | * @param string $source The source of the image
72 | * @return $this
73 | */
74 | public function withSource($source)
75 | {
76 | $this->src = $source;
77 |
78 | return $this;
79 | }
80 |
81 | /**
82 | * Sets the alt text of the image
83 | *
84 | * @param string $alt The alt text of the image
85 | * @return $this
86 | */
87 | public function withAlt($alt)
88 | {
89 | $this->alt = $alt;
90 |
91 | return $this;
92 | }
93 |
94 | /**
95 | * Sets the image to be responsive
96 | *
97 | * @return $this
98 | */
99 | public function responsive()
100 | {
101 | $this->addClass([self::IMAGE_RESPONSIVE]);
102 |
103 | return $this;
104 | }
105 |
106 | /**
107 | * Creates a rounded image
108 | *
109 | * @param null|string $src The source of the image. Pass null to use the
110 | * previous value of the source
111 | * @param null|string $alt The alt text of the image. Pass null to use
112 | * the previous value
113 | * @return $this
114 | */
115 | public function rounded($src = null, $alt = null)
116 | {
117 | $this->addClass([self::IMAGE_ROUNDED]);
118 |
119 | if (!isset($src)) {
120 | $src = $this->src;
121 | }
122 | if (!isset($alt)) {
123 | $alt = $this->alt;
124 | }
125 |
126 | return $this->withSource($src)->withAlt($alt);
127 | }
128 |
129 | /**
130 | * Creates a circle image
131 | *
132 | * @param null|string $src The source of the image. Pass null to use the
133 | * previous value of the source
134 | * @param null|string $alt The alt text of the image. Pass null to use
135 | * the previous value
136 | * @return $this
137 | */
138 | public function circle($src = null, $alt = null)
139 | {
140 | $this->addClass([self::IMAGE_CIRCLE]);
141 |
142 | if (!isset($src)) {
143 | $src = $this->src;
144 | }
145 | if (!isset($alt)) {
146 | $alt = $this->alt;
147 | }
148 |
149 | return $this->withSource($src)->withAlt($alt);
150 | }
151 |
152 | /**
153 | * Creates a thumbnail image
154 | *
155 | * @param null|string $src The source of the image. Pass null to use the
156 | * previous value of the source
157 | * @param null|string $alt The alt text of the image. Pass null to use
158 | * the previous value
159 | * @return $this
160 | */
161 | public function thumbnail($src = null, $alt = null)
162 | {
163 | $this->addClass([self::IMAGE_THUMBNAIL]);
164 |
165 | if (!isset($src)) {
166 | $src = $this->src;
167 | }
168 | if (!isset($alt)) {
169 | $alt = $this->alt;
170 | }
171 |
172 | return $this->withSource($src)->withAlt($alt);
173 | }
174 |
175 | /**
176 | * BC version of Image::addClass()
177 | *
178 | * @param string|array $class
179 | * @return $this
180 | */
181 | public function addClass($class)
182 | {
183 | if (is_string($class)) {
184 | trigger_error(
185 | 'Passing strings to Image::getClass ' .
186 | 'is depreciated, and will be removed in a future version of ' .
187 | 'Bootstrapper',
188 | E_USER_DEPRECATED
189 | );
190 | $class = [$class];
191 | }
192 |
193 | return parent::addClass($class);
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/src/Bootstrapper/InputGroup.php:
--------------------------------------------------------------------------------
1 | "input-group {$this->size}"];
54 | $attributes = new Attributes($this->attributes, $attributes);
55 |
56 | $string = "
";
57 | if (is_array($this->prepend)) {
58 | $string .= $this->renderAddon($this->prepend);
59 | }
60 |
61 | $string .= $this->contents;
62 |
63 | if (is_array($this->append)) {
64 | $string .= $this->renderAddon($this->append);
65 | }
66 |
67 | $string .= "
";
68 |
69 | return $string;
70 | }
71 |
72 | /**
73 | * Renders an addon
74 | *
75 | * @param array $addon The addon to render
76 | * @return string
77 | */
78 | protected function renderAddon(array $addon)
79 | {
80 | $string = "";
81 | if ($addon['isButton']) {
82 | $string .= "
";
83 | } else {
84 | $string .= "";
85 | }
86 | $string .= $addon['value'];
87 | $string .= "";
88 |
89 | return $string;
90 | }
91 |
92 |
93 | /**
94 | * Sets the contents of the input group
95 | *
96 | * @param string $contents The new contents
97 | * @return $this
98 | */
99 | public function withContents($contents)
100 | {
101 | $this->contents = $contents;
102 |
103 | return $this;
104 | }
105 |
106 | /**
107 | * Sets the size of the input group
108 | *
109 | * @param string $size The new size
110 | * @return $this
111 | */
112 | public function setSize($size)
113 | {
114 | $this->size = $size;
115 |
116 | return $this;
117 | }
118 |
119 | /**
120 | * Prepends something to the input
121 | *
122 | * @param string $prepend The value to prepend
123 | * @param bool $isButton Whether the value is a button
124 | * @return $this
125 | */
126 | public function prepend($prepend, $isButton = false)
127 | {
128 | $this->prepend = ['value' => $prepend, 'isButton' => $isButton];
129 |
130 | return $this;
131 | }
132 |
133 | /**
134 | * Prepend a button
135 | *
136 | * @param string $button The button to prepend
137 | * @return $this
138 | */
139 | public function prependButton($button)
140 | {
141 | return $this->prepend($button, true);
142 | }
143 |
144 | /**
145 | * Appends something to the input
146 | *
147 | * @param string $append The value to append
148 | * @param bool $isButton Whether the value is a button
149 | * @return $this
150 | */
151 | public function append($append, $isButton = false)
152 | {
153 | $this->append = ['value' => $append, 'isButton' => $isButton];
154 |
155 | return $this;
156 | }
157 |
158 | /**
159 | * Append a button
160 | *
161 | * @param string $button The button to append
162 | * @return $this
163 | */
164 | public function appendButton($button)
165 | {
166 | return $this->append($button, true);
167 | }
168 |
169 | /**
170 | * Makes the input group large
171 | *
172 | * @return $this
173 | */
174 | public function large()
175 | {
176 | $this->setSize(self::LARGE);
177 |
178 | return $this;
179 | }
180 |
181 | /**
182 | * Makes the input group small
183 | *
184 | * @return $this
185 | */
186 | public function small()
187 | {
188 | $this->setSize(self::SMALL);
189 |
190 | return $this;
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/src/Bootstrapper/Interfaces/TableInterface.php:
--------------------------------------------------------------------------------
1 | attributes,
65 | [
66 | 'class' => "label {$this->type}"
67 | ]
68 | );
69 |
70 | return "{$this->contents}";
71 | }
72 |
73 | /**
74 | * Sets the contents of the label
75 | *
76 | * @param string $contents The new contents of the label
77 | * @return $this
78 | */
79 | public function withContents($contents)
80 | {
81 | $this->contents = $contents;
82 |
83 | return $this;
84 | }
85 |
86 | /**
87 | * Sets the type of the label. Assumes that the label- prefix is already set
88 | *
89 | * @param string $type The new type
90 | * @return $this
91 | */
92 | public function setType($type)
93 | {
94 | $this->type = $type;
95 |
96 | return $this;
97 | }
98 |
99 | /**
100 | * Creates a primary label
101 | *
102 | * @param string $contents The contents of the label
103 | * @return $this
104 | */
105 | public function primary($contents = '')
106 | {
107 | $this->setType(self::LABEL_PRIMARY);
108 |
109 | return $this->withContents($contents);
110 | }
111 |
112 | /**
113 | * Creates a success label
114 | *
115 | * @param string $contents The contents of the label
116 | * @return $this
117 | */
118 | public function success($contents = '')
119 | {
120 | $this->setType(self::LABEL_SUCCESS);
121 |
122 | return $this->withContents($contents);
123 | }
124 |
125 | /**
126 | * Creates an info label
127 | *
128 | * @param string $contents The contents of the label
129 | * @return $this
130 | */
131 | public function info($contents = '')
132 | {
133 | $this->setType(self::LABEL_INFO);
134 |
135 | return $this->withContents($contents);
136 | }
137 |
138 | /**
139 | * Creates a warning label
140 | *
141 | * @param string $contents The contents of the label
142 | * @return $this
143 | */
144 | public function warning($contents = '')
145 | {
146 | $this->setType(self::LABEL_WARNING);
147 |
148 | return $this->withContents($contents);
149 | }
150 |
151 | /**
152 | * Creates a danger label
153 | *
154 | * @param string $contents The contents of the label
155 | * @return $this
156 | */
157 | public function danger($contents = '')
158 | {
159 | $this->setType(self::LABEL_DANGER);
160 |
161 | return $this->withContents($contents);
162 | }
163 |
164 | /**
165 | * Creates a label
166 | *
167 | * @param string $contents The contents of the label
168 | * @param string $type The type to use
169 | * @return $this
170 | */
171 | public function create($contents, $type = self::LABEL_DEFAULT)
172 | {
173 | $this->setType($type);
174 |
175 | return $this->withContents($contents);
176 | }
177 |
178 | /**
179 | * Creates a normal label
180 | *
181 | * @param string $contents The contents of the label
182 | * @return $this
183 | */
184 | public function normal($contents = '')
185 | {
186 | $this->setType(self::LABEL_DEFAULT);
187 |
188 | return $this->withContents($contents);
189 | }
190 | }
191 |
--------------------------------------------------------------------------------
/src/Bootstrapper/MediaObject.php:
--------------------------------------------------------------------------------
1 | list) {
37 | return $this->renderList();
38 | }
39 |
40 | if (!$this->contents) {
41 | throw new MediaObjectException(
42 | "You need to give the object some contents"
43 | );
44 | }
45 |
46 | return $this->renderItem($this->contents, 'div');
47 | }
48 |
49 | /**
50 | * Sets the contents of the media object
51 | *
52 | * @param array $contents The contents of the media object
53 | * @return $this
54 | */
55 | public function withContents(array $contents)
56 | {
57 | $this->contents = $contents;
58 |
59 | // Check if it's an array of arrays
60 | $this->list = isset($contents[0]);
61 |
62 | return $this;
63 | }
64 |
65 | /**
66 | * Force the media object to become a list
67 | *
68 | * @return $this
69 | */
70 | public function asList()
71 | {
72 | $this->list = true;
73 |
74 | return $this;
75 | }
76 |
77 | /**
78 | * Renders a list
79 | *
80 | * @return string
81 | */
82 | protected function renderList()
83 | {
84 | $attributes = new Attributes(
85 | $this->attributes,
86 | ['class' => 'media-list']
87 | );
88 |
89 | $this->attributes = [];
90 |
91 | $string = "";
92 | foreach ($this->contents as $item) {
93 | $string .= $this->renderItem($item, 'li');
94 | }
95 | $string .= "
";
96 |
97 | return $string;
98 | }
99 |
100 | /**
101 | * Renders an item in the string
102 | *
103 | * @param array $contents
104 | * @param string $tag The tag to wrap the item in
105 | * @return string
106 | * @throws MediaObjectException
107 | */
108 | protected function renderItem(array $contents, $tag)
109 | {
110 | $position = $this->getPosition($contents);
111 | $heading = $this->getHeading($contents);
112 | $image = $this->getImage($contents, $heading);
113 | $link = $this->getLink($contents, $image, $position);
114 | $body = $this->getBody($contents);
115 |
116 | $attributes = new Attributes($this->attributes, ['class' => 'media']);
117 |
118 | $string = "<{$tag} {$attributes}>";
119 | $string .= $link;
120 | $string .= "";
121 |
122 | if ($heading) {
123 | $string .= "";
124 | }
125 |
126 | $string .= $body;
127 | $string .= "
{$tag}>";
128 |
129 | return $string;
130 | }
131 |
132 | /**
133 | * Get the position
134 | *
135 | * @param array $contents
136 | * @return string pull-right if the position key equals right. pull-left
137 | * otherwise
138 | */
139 | protected function getPosition(array $contents)
140 | {
141 | if (isset($contents['position']) && $contents['position'] == 'right') {
142 | return 'pull-right';
143 | }
144 |
145 | return 'pull-left';
146 | }
147 |
148 | /**
149 | * Get the image of the media object
150 | *
151 | * @param array $contents
152 | * @param string $alt The alt text of the image
153 | * @return string
154 | * @throws MediaObjectException if there is no image set
155 | */
156 | protected function getImage(array $contents, $alt)
157 | {
158 | if (!isset($contents['image'])) {
159 | throw new MediaObjectException(
160 | "You must pass in an image to each object"
161 | );
162 | }
163 | $image = $contents['image'];
164 |
165 | $attributes = new Attributes(
166 | ['class' => 'media-object', 'src' => $image, 'alt' => $alt]
167 | );
168 |
169 | return "
";
170 | }
171 |
172 | /**
173 | * Get the heading of the media object
174 | *
175 | * @param array $contents
176 | * @return string
177 | */
178 | protected function getHeading(array $contents)
179 | {
180 | return isset($contents['heading']) ? $contents['heading'] : '';
181 | }
182 |
183 | /**
184 | * Turn the image into a link/div
185 | *
186 | * @param array $contents The contents array
187 | * @param string $image The image
188 | * @param string $position The position
189 | * @return string
190 | */
191 | protected function getLink(array $contents, $image, $position)
192 | {
193 | if (isset($contents['link'])) {
194 | return "{$image}";
195 | }
196 |
197 | return "{$image}
";
198 | }
199 |
200 | /**
201 | * Get the body of the contents array
202 | *
203 | * @param array $contents
204 | * @return string
205 | * @throws MediaObjectException if the body key has not been set
206 | */
207 | protected function getBody(array $contents)
208 | {
209 | if (!isset($contents['body'])) {
210 | throw new MediaObjectException(
211 | 'You must pass in the body to each object'
212 | );
213 | }
214 |
215 | $string = $contents['body'];
216 |
217 | if (isset($contents['nest'])) {
218 | $object = new MediaObject();
219 | $string .= $object->withContents($contents['nest']);
220 | }
221 |
222 | return $string;
223 | }
224 | }
225 |
--------------------------------------------------------------------------------
/src/Bootstrapper/Modal.php:
--------------------------------------------------------------------------------
1 | attributes, ['class' => 'modal']);
49 |
50 | $string = $this->renderButton($attributes);
51 |
52 | $string .= "";
53 |
54 | $string .= $this->renderHeader();
55 | $string .= $this->renderBody();
56 | $string .= $this->renderFooter();
57 |
58 | $string .= "
";
59 |
60 | return $string;
61 | }
62 |
63 | /**
64 | * Sets the title of the modal
65 | *
66 | * @param string $title
67 | * @return $this
68 | */
69 | public function withTitle($title)
70 | {
71 | $this->title = $title;
72 |
73 | return $this;
74 | }
75 |
76 | /**
77 | * Renders the header of the modal
78 | *
79 | * @return string
80 | */
81 | protected function renderHeader()
82 | {
83 | $title = '';
84 | if ($this->title) {
85 | $title .= "{$this->title}
";
86 | }
87 |
88 | return "";
90 | }
91 |
92 | /**
93 | * Sets the body of the modal
94 | *
95 | * @param string $body The new body of the modal
96 | * @return $this
97 | */
98 | public function withBody($body)
99 | {
100 | $this->body = $body;
101 |
102 | return $this;
103 | }
104 |
105 | /**
106 | * Renders the body
107 | *
108 | * @return string
109 | */
110 | protected function renderBody()
111 | {
112 | return $this->body ? "{$this->body}
" : '';
113 | }
114 |
115 | /**
116 | * Renders the footer
117 | *
118 | * @return string
119 | */
120 | protected function renderFooter()
121 | {
122 | return $this->footer ? "" : '';
123 | }
124 |
125 | /**
126 | * Set the footer of the modal
127 | *
128 | * @param string $footer The footer
129 | * @return $this
130 | */
131 | public function withFooter($footer)
132 | {
133 | $this->footer = $footer;
134 |
135 | return $this;
136 | }
137 |
138 | /**
139 | * Sets the name of the modal
140 | *
141 | * @param string $name The name of the modal
142 | * @return $this
143 | */
144 | public function named($name)
145 | {
146 | $this->name = $name;
147 | $this->attributes['id'] = $name;
148 |
149 | return $this;
150 | }
151 |
152 | /**
153 | * Sets the button
154 | *
155 | * @param Button $button The button to open the modal with
156 | * @return $this
157 | */
158 | public function withButton(Button $button = null)
159 | {
160 | if ($button) {
161 | $this->button = $button;
162 | } else {
163 | $button = new Button();
164 |
165 | $this->button = $button->withValue('Open Modal');
166 | }
167 |
168 | return $this;
169 | }
170 |
171 | /**
172 | * Renders the button
173 | *
174 | * @param Attributes $attributes The attributes of the modal
175 | * @return string
176 | */
177 | protected function renderButton(Attributes $attributes)
178 | {
179 | if (!$this->button) {
180 | return '';
181 | }
182 |
183 | if (!isset($attributes['id'])) {
184 | $attributes['id'] = Helpers::generateId($this);
185 | }
186 |
187 | $this->button->addAttributes(
188 | ['data-toggle' => 'modal', 'data-target' => "#{$attributes['id']}"]
189 | )->render();
190 |
191 | return $this->button->render();
192 | }
193 | }
194 |
--------------------------------------------------------------------------------
/src/Bootstrapper/Navbar.php:
--------------------------------------------------------------------------------
1 | url = $url;
76 | }
77 |
78 | /**
79 | * Renders the navbar
80 | *
81 | * @return string
82 | */
83 | public function render()
84 | {
85 | $attributes = new Attributes(
86 | $this->attributes,
87 | [
88 | 'class' => "navbar {$this->type} {$this->position}",
89 | 'role' => 'navigation'
90 | ]
91 | );
92 |
93 | $string = "";
94 | $string .= $this->fluid ?
95 | "
" :
96 | "
";
97 | $string .= $this->renderHeader();
98 | $string .= $this->renderContent();
99 | $string .= "
";
100 |
101 | return $string;
102 | }
103 |
104 | /**
105 | * Renders the inner content
106 | *
107 | * @return string
108 | */
109 | protected function renderContent()
110 | {
111 | $string = "
";
121 |
122 | return $string;
123 | }
124 |
125 | /**
126 | * Renders the header
127 | *
128 | * @return string
129 | */
130 | protected function renderHeader()
131 | {
132 | $string = "";
141 |
142 | return $string;
143 | }
144 |
145 | /**
146 | * Sets the brand of the navbar
147 | *
148 | * @param string $brand The brand
149 | * @param null|string $link The link. If not set we default to linking to
150 | * '/' using the UrlGenerator
151 | * @return $this
152 | */
153 | public function withBrand($brand, $link = null)
154 | {
155 | if (!isset($link)) {
156 | $link = $this->url->to('/');
157 | }
158 |
159 | $this->brand = compact('brand', 'link');
160 |
161 | return $this;
162 | }
163 |
164 | /**
165 | * Sets the brand of the navbar
166 | *
167 | * @param string $image The brand image
168 | * @param null|string $link The link. If not set we default to linking to
169 | * '/' using the UrlGenerator
170 | * @param string $altText The alt text for the image
171 | * @return $this
172 | */
173 | public function withBrandImage($image, $link = null, $altText = '')
174 | {
175 | $altText = $altText !== '' ? " alt='{$altText}'" : '';
176 |
177 | return $this->withBrand("

", $link);
178 | }
179 |
180 | /**
181 | * Adds some content to the navbar
182 | *
183 | * @param mixed $content Anything that can become a string! If you pass in a
184 | * Bootstrapper\Navigation object we'll make sure
185 | * it's a navbar on render.
186 | * @return $this
187 | */
188 | public function withContent($content)
189 | {
190 | $this->content[] = $content;
191 |
192 | return $this;
193 | }
194 |
195 | /**
196 | * Sets the navbar to be inverse
197 | *
198 | * @param string $position
199 | * @param array $attributes
200 | * @return $this
201 | */
202 | public function inverse($position = null, $attributes = [])
203 | {
204 | if (isset($position)) {
205 | $this->setPosition($position);
206 | $this->withAttributes($attributes);
207 | }
208 |
209 | $this->setType(self::NAVBAR_INVERSE);
210 |
211 | return $this;
212 | }
213 |
214 | /**
215 | * Sets the position to top
216 | *
217 | * @return $this
218 | */
219 | public function staticTop()
220 | {
221 | $this->setPosition(self::NAVBAR_STATIC);
222 |
223 | return $this;
224 | }
225 |
226 | /**
227 | * Sets the type of the navbar
228 | *
229 | * @param string $type The type of the navbar. Assumes that the navbar-
230 | * prefix is there
231 | * @return $this
232 | */
233 | public function setType($type)
234 | {
235 | $this->type = $type;
236 |
237 | return $this;
238 | }
239 |
240 | /**
241 | * Sets the position of the navbar
242 | *
243 | * @param string $position The position of the navbar. Assumes that the
244 | * navbar- prefix is there
245 | * @return $this
246 | */
247 | public function setPosition($position)
248 | {
249 | $this->position = $position;
250 |
251 | return $this;
252 | }
253 |
254 | /**
255 | * Sets the position of the navbar to the top
256 | *
257 | * @return $this
258 | */
259 | public function top()
260 | {
261 | $this->setPosition(self::NAVBAR_TOP);
262 |
263 | return $this;
264 | }
265 |
266 | /**
267 | * Sets the position of the navbar to the bottom
268 | *
269 | * @return $this
270 | */
271 | public function bottom()
272 | {
273 | $this->setPosition(self::NAVBAR_BOTTOM);
274 |
275 | return $this;
276 | }
277 |
278 | /**
279 | * Creates a navbar with a position and attributes
280 | *
281 | * @param string $position The position of the navbar
282 | * @param array $attributes The attributes of the navbar
283 | * @return $this
284 | */
285 | public function create($position, $attributes = [])
286 | {
287 | $this->setPosition($position);
288 |
289 | return $this->withAttributes($attributes);
290 | }
291 |
292 | /**
293 | * Sets the navbar to be fluid
294 | *
295 | * @return $this
296 | */
297 | public function fluid()
298 | {
299 | $this->fluid = true;
300 |
301 | return $this;
302 | }
303 | }
304 |
--------------------------------------------------------------------------------
/src/Bootstrapper/Navigation.php:
--------------------------------------------------------------------------------
1 |
56 | *
title - The text to show
57 | *
link - The link
58 | *
active - (optional) Forces the link to be active
59 | *
disabled - (optional) Forces the link to be disabled. Note that
60 | * active has priority over this
61 | *
linkAttributes - The attributes for the link
62 | *
callback - A callback. If it return a result that is EXACTLY
63 | * equal to false then the link won't be shown
64 | *
65 | * To create a dropdown, the inner array should instead be [$title, $links],
66 | * where $links is an array of arrays for links
67 | */
68 | protected $links = [];
69 |
70 | /**
71 | * @var UrlGenerator A laravel URL generator
72 | */
73 | protected $url;
74 |
75 | /**
76 | * @var bool Whether we should automatically activate links
77 | */
78 | protected $autoroute = true;
79 |
80 | /**
81 | * @var bool Whether the links are justified or not
82 | */
83 | protected $justified = false;
84 |
85 | /**
86 | * @var bool Whether the navigation links are stacked or not
87 | */
88 | protected $stacked = false;
89 |
90 | /**
91 | * @var string Whether the navigation should be floated
92 | */
93 | protected $float;
94 |
95 | /**
96 | * Creates a new instance of Navigation
97 | *
98 | * @param UrlGenerator $urlGenerator
99 | */
100 | public function __construct(UrlGenerator $urlGenerator)
101 | {
102 | $this->url = $urlGenerator;
103 | }
104 |
105 | /**
106 | * Renders the navigation object
107 | *
108 | * @return string
109 | */
110 | public function render()
111 | {
112 | $attributes = new Attributes(
113 | $this->attributes,
114 | ['class' => "nav {$this->type}"]
115 | );
116 |
117 | if ($this->justified) {
118 | $attributes->addClass('nav-justified');
119 | }
120 |
121 | if ($this->stacked) {
122 | $attributes->addClass('nav-stacked');
123 | }
124 |
125 | if ($this->float) {
126 | $attributes->addClass($this->float);
127 | }
128 |
129 | $string = "
";
130 |
131 | foreach ($this->links as $link) {
132 | $string .= $this->renderItem($link);
133 | }
134 |
135 | $string .= "
";
136 |
137 | return $string;
138 | }
139 |
140 | /**
141 | * Creates a pills navigation block
142 | *
143 | * @param array $links The links
144 | * @param array $attributes The attributes. Does not overwrite the
145 | * previous values if not set
146 | * @see Bootstrapper\Navigatation::$links
147 | * @return $this
148 | */
149 | public function pills(array $links = [], array $attributes = null)
150 | {
151 | $this->type = self::NAVIGATION_PILLS;
152 |
153 | if (!isset($attributes)) {
154 | $attributes = $this->attributes;
155 | }
156 |
157 | return $this->links($links)->withAttributes($attributes);
158 | }
159 |
160 | /**
161 | * Sets the links of the navigation object
162 | *
163 | * @param array $links The links
164 | * @return $this
165 | * @see Bootstrapper\Navigation::$links
166 | */
167 | public function links(array $links)
168 | {
169 | $this->links = $links;
170 |
171 | return $this;
172 | }
173 |
174 | /**
175 | * Creates a navigation tab object.
176 | *
177 | * @param array $links The links to be passed in
178 | * @param array $attributes The attributes of the navigation object. Will
179 | * overwrite unless not set.
180 | * @return $this
181 | */
182 | public function tabs(array $links = [], array $attributes = null)
183 | {
184 | $this->type = self::NAVIGATION_TABS;
185 | if (!isset($attributes)) {
186 | $attributes = $this->attributes;
187 | }
188 |
189 | return $this->links($links)->withAttributes($attributes);
190 | }
191 |
192 | /**
193 | * Renders a link
194 | *
195 | * @param array $link A link to be rendered
196 | * @return string
197 | */
198 | protected function renderLink(array $link)
199 | {
200 | $string = '';
201 |
202 | if (isset($link['callback'])) {
203 | $callback = $link['callback'];
204 |
205 | if ($callback() === false) {
206 | return $string;
207 | }
208 | }
209 |
210 | if ($this->itemShouldBeActive($link)) {
211 | $string .= '
';
212 | } elseif (isset($link['disabled']) && $link['disabled']) {
213 | $string .= '';
214 | } else {
215 | $string .= '';
216 | }
217 |
218 | if (isset($link['linkAttributes'])) {
219 | $linkAttributes = $link['linkAttributes'];
220 | } else {
221 | $linkAttributes = [];
222 | }
223 |
224 | $linkAttributes = new Attributes(
225 | $linkAttributes,
226 | ['href' => $link['link']]
227 | );
228 |
229 | $string .= "{$link['title']}";
230 |
231 | return $string;
232 | }
233 |
234 | /**
235 | * Sets the autorouting. Pass false to turn it off, true to turn it on
236 | *
237 | * @param bool $autoroute Whether the autorouting should be on
238 | * @return $this
239 | */
240 | public function autoroute($autoroute)
241 | {
242 | $this->autoroute = $autoroute;
243 |
244 | return $this;
245 | }
246 |
247 | /**
248 | * Renders the dropdown
249 | *
250 | * @param array $link The link to render
251 | * @return string
252 | */
253 | protected function renderDropdown(array $link)
254 | {
255 | if ($this->dropdownShouldBeActive($link)) {
256 | $string = '
';
257 | } else {
258 | $string = '';
259 | }
260 |
261 | $string .= "";
262 | $string .= "{$link[0]} ";
263 | $string .= '';
270 | $string .= '';
271 |
272 | return $string;
273 | }
274 |
275 | /**
276 | * Checks to see if the dropdown should be active
277 | *
278 | * @param array $dropdown The dropdown array
279 | * @return bool
280 | */
281 | protected function dropdownShouldBeActive(array $dropdown)
282 | {
283 | if ($this->autoroute) {
284 | foreach ($dropdown[1] as $item) {
285 | if ($this->itemShouldBeActive($item)) {
286 | return true;
287 | }
288 | }
289 | }
290 | return false;
291 | }
292 |
293 | /**
294 | * Checks to see if the given item should be active
295 | *
296 | * @param mixed $link A link to check whether it should be active
297 | * @return bool
298 | */
299 | protected function itemShouldBeActive($link)
300 | {
301 | if (is_string($link)) {
302 | return false;
303 | }
304 | $auto = $this->autoroute && $this->url->current() == $link['link'];
305 | $manual = isset($link['active']) && $link['active'];
306 |
307 | return $auto || $manual;
308 | }
309 |
310 | /**
311 | * Turns the navigation object into one for navbars
312 | *
313 | * @return $this
314 | */
315 | public function navbar()
316 | {
317 | $this->type = self::NAVIGATION_NAVBAR;
318 |
319 | return $this;
320 | }
321 |
322 | /**
323 | * Makes the navigation links justified
324 | *
325 | * @return $this
326 | */
327 | public function justified()
328 | {
329 | $this->justified = true;
330 |
331 | return $this;
332 | }
333 |
334 | /**
335 | * Makes the navigation stacked
336 | *
337 | * @return $this
338 | */
339 | public function stacked()
340 | {
341 | $this->stacked = true;
342 |
343 | return $this;
344 | }
345 |
346 | /**
347 | * Makes the navigation links float right
348 | *
349 | * @return $this
350 | */
351 | public function right()
352 | {
353 | $this->float = self::NAVBAR_RIGHT;
354 |
355 | return $this;
356 | }
357 |
358 | /**
359 | * Makes the navigation links float left
360 | *
361 | * @return $this
362 | */
363 | public function left()
364 | {
365 | $this->float = self::NAVBAR_LEFT;
366 |
367 | return $this;
368 | }
369 |
370 | /**
371 | * Renders a separator
372 | *
373 | * @param string $separator
374 | * @return string
375 | */
376 | protected function renderSeparator($separator)
377 | {
378 | return "
";
379 | }
380 |
381 | /**
382 | * Renders an item
383 | *
384 | * @param string|array $link The item to render
385 | * @return string
386 | */
387 | private function renderItem($link)
388 | {
389 | if (!is_array($link)) {
390 | $string = $this->renderSeparator($link);
391 | } elseif (isset($link['link'])) {
392 | $string = $this->renderLink($link);
393 | } else {
394 | $string = $this->renderDropdown($link);
395 | }
396 |
397 | return $string;
398 | }
399 | }
400 |
--------------------------------------------------------------------------------
/src/Bootstrapper/Panel.php:
--------------------------------------------------------------------------------
1 | attributes,
80 | ['class' => "panel {$this->type}"]
81 | );
82 | $string = "
";
83 |
84 | if ($this->header) {
85 | $string .= $this->renderHeader();
86 | }
87 |
88 | if ($this->body) {
89 | $string .= $this->renderBody();
90 | }
91 |
92 | if ($this->table) {
93 | $string .= $this->renderTable();
94 | }
95 |
96 | if ($this->footer) {
97 | $string .= $this->renderFooter();
98 | }
99 |
100 | $string .= "
";
101 |
102 | return $string;
103 | }
104 |
105 | /**
106 | * Creates a primary panel
107 | *
108 | * @return $this
109 | */
110 | public function primary()
111 | {
112 | $this->setType(self::PRIMARY);
113 |
114 | return $this;
115 | }
116 |
117 | /**
118 | * Creates a success panel
119 | *
120 | * @return $this
121 | */
122 | public function success()
123 | {
124 | $this->setType(self::SUCCESS);
125 |
126 | return $this;
127 | }
128 |
129 | /**
130 | * Creates an info panel
131 | *
132 | * @return $this
133 | */
134 | public function info()
135 | {
136 | $this->setType(self::INFO);
137 |
138 | return $this;
139 | }
140 |
141 | /**
142 | * Creates an warning panel
143 | *
144 | * @return $this
145 | */
146 | public function warning()
147 | {
148 | $this->setType(self::WARNING);
149 |
150 | return $this;
151 | }
152 |
153 | /**
154 | * Creates an danger panel
155 | *
156 | * @return $this
157 | */
158 | public function danger()
159 | {
160 | $this->setType(self::DANGER);
161 |
162 | return $this;
163 | }
164 |
165 | /**
166 | * Sets the type of the panel
167 | *
168 | * @param string $type The new type. Assume the panel- prefix
169 | * @return $this
170 | */
171 | public function setType($type)
172 | {
173 | $this->type = $type;
174 |
175 | return $this;
176 | }
177 |
178 | /**
179 | * Sets the header of the panel
180 | *
181 | * @param string $header The header
182 | * @return $this
183 | */
184 | public function withHeader($header)
185 | {
186 | $this->header = $header;
187 |
188 | return $this;
189 | }
190 |
191 | /**
192 | * Renders the header
193 | *
194 | * @return string
195 | */
196 | protected function renderHeader()
197 | {
198 | $string = "
";
199 | $string .= "
{$this->header}
";
200 | $string .= '';
201 |
202 | return $string;
203 | }
204 |
205 | /**
206 | * Sets the body of the panel
207 | *
208 | * @param string $body The body
209 | * @return $this
210 | */
211 | public function withBody($body)
212 | {
213 | $this->body = $body;
214 |
215 | return $this;
216 | }
217 |
218 | /**
219 | * Renders the body
220 | *
221 | * @return string
222 | */
223 | protected function renderBody()
224 | {
225 | return "
{$this->body}
";
226 | }
227 |
228 | /**
229 | * Sets the table of the panel
230 | *
231 | * @param string|Table $table The table
232 | * @return $this
233 | */
234 | public function withTable($table)
235 | {
236 | $this->table = $table;
237 |
238 | return $this;
239 | }
240 |
241 | /**
242 | * Renders the body
243 | *
244 | * @return string
245 | */
246 | protected function renderTable()
247 | {
248 | if ($this->table instanceof Table) {
249 | return $this->table->render();
250 | } else {
251 | return $this->table;
252 | }
253 | }
254 |
255 | /**
256 | * Sets the footer
257 | *
258 | * @param string $footer The new footer
259 | * @return $this
260 | */
261 | public function withFooter($footer)
262 | {
263 | $this->footer = $footer;
264 |
265 | return $this;
266 | }
267 |
268 | /**
269 | * Renders the footer
270 | *
271 | * @return string
272 | */
273 | protected function renderFooter()
274 | {
275 | return "";
276 | }
277 |
278 | /**
279 | * Creates a normal panel
280 | *
281 | * @return $this
282 | */
283 | public function normal()
284 | {
285 | $this->setType(self::NORMAL);
286 |
287 | return $this;
288 | }
289 | }
290 |
--------------------------------------------------------------------------------
/src/Bootstrapper/ProgressBar.php:
--------------------------------------------------------------------------------
1 | ";
79 |
80 | $attributes = new Attributes(
81 | $this->attributes,
82 | [
83 | 'class' => "progress-bar {$this->type}",
84 | 'role' => 'progressbar',
85 | 'aria-valuenow' => "{$this->value}",
86 | 'aria-valuemin' => '0',
87 | 'aria-valuemax' => '100',
88 | 'style' => $this->value ? "width: {$this->value}%" : ''
89 | ]
90 | );
91 |
92 | if ($this->striped) {
93 | $attributes->addClass('progress-bar-striped');
94 | }
95 |
96 | if ($this->animated) {
97 | $attributes->addClass('active');
98 | }
99 |
100 | $string .= "
";
101 |
102 | $string .= $this->visible ?
103 | sprintf($this->visibleString, $this->value) :
104 | "{$this->value}% complete";
105 |
106 | $string .= "
";
107 |
108 | $string .= "
";
109 |
110 | return $string;
111 | }
112 |
113 | /**
114 | * Sets the type of the progress bar
115 | *
116 | * @param string $type The type
117 | * @return $this
118 | */
119 | public function setType($type)
120 | {
121 | $this->type = $type;
122 |
123 | return $this;
124 | }
125 |
126 | /**
127 | * Sets the value of the progress bar
128 | *
129 | * @param int $value The value of the progress bar The value of the
130 | * progress bar
131 | * @return $this
132 | */
133 | public function value($value)
134 | {
135 | $this->value = $value;
136 |
137 | return $this;
138 | }
139 |
140 | /**
141 | * Whether the amount should be visible
142 | *
143 | * @param string $string The string to show to the user. We internally
144 | * will use sprintf to show this, so you must
145 | * include a %s somewhere so we can add this in
146 | * @return $this
147 | */
148 | public function visible($string = '%s%%')
149 | {
150 | $this->visible = true;
151 | $this->visibleString = $string;
152 |
153 | return $this;
154 | }
155 |
156 | /**
157 | * Creates a success progress bar
158 | *
159 | * @param int $value The value of the progress bar
160 | * @return $this
161 | */
162 | public function success($value = 0)
163 | {
164 | $this->setType(self::PROGRESS_BAR_SUCCESS);
165 |
166 | return $this->value($value);
167 | }
168 |
169 | /**
170 | * Creates an info progress bar
171 | *
172 | * @param int $value The value of the progress bar
173 | * @return $this
174 | */
175 | public function info($value = 0)
176 | {
177 | $this->setType(self::PROGRESS_BAR_INFO);
178 |
179 | return $this->value($value);
180 | }
181 |
182 | /**
183 | * Creates a warning progress bar
184 | *
185 | * @param int $value The value of the progress bar
186 | * @return $this
187 | */
188 | public function warning($value = 0)
189 | {
190 | $this->setType(self::PROGRESS_BAR_WARNING);
191 |
192 | return $this->value($value);
193 | }
194 |
195 | /**
196 | * Creates a danger progress bar
197 | *
198 | * @param int $value The value of the progress bar
199 | * @return $this
200 | */
201 | public function danger($value = 0)
202 | {
203 | $this->setType(self::PROGRESS_BAR_DANGER);
204 |
205 | return $this->value($value);
206 | }
207 |
208 | /**
209 | * Creates a normal progress bar
210 | *
211 | * @param int $value The value of the progress bar
212 | * @return $this
213 | */
214 | public function normal($value = 0)
215 | {
216 | $this->setType(self::PROGRESS_BAR_NORMAL);
217 |
218 | return $this->value($value);
219 | }
220 |
221 | /**
222 | * Sets the progress bar to be striped
223 | *
224 | * @return $this
225 | */
226 | public function striped()
227 | {
228 | $this->striped = true;
229 |
230 | return $this;
231 | }
232 |
233 | /**
234 | * Sets the progress bar to be animated
235 | *
236 | * @return $this
237 | */
238 | public function animated()
239 | {
240 | $this->animated = true;
241 |
242 | return $this->striped();
243 | }
244 |
245 | /**
246 | * Stacks several progress bars together
247 | *
248 | * @param array $items The progress bars. Should be an array of arrays,
249 | * which are a list of methods and parameters.
250 | * @return string
251 | */
252 | public function stack(array $items)
253 | {
254 | $string = '';
255 | foreach ($items as $progressBar) {
256 | $string .= $this->generateFromArray($progressBar);
257 | }
258 | $string .= '
';
259 |
260 | return $string;
261 | }
262 |
263 | /**
264 | * Generates a progress bar from an array
265 | *
266 | * @param array $progressBar An array of methods with variables if required,
267 | * eg 'value=2', 'animated'
268 | * @return mixed
269 | */
270 | protected function generateFromArray(array $progressBar)
271 | {
272 | $bar = new static;
273 |
274 | foreach ($progressBar as $attribute) {
275 | $exploded = explode('=', $attribute);
276 | $method = $exploded[0];
277 | $vars = isset($exploded[1]) ? $exploded[1] : null;
278 | if (isset($vars)) {
279 | $bar->$method($vars);
280 | } else {
281 | $bar->$method();
282 | }
283 | }
284 |
285 | // Now to remove the outer divs
286 | $string = $bar->render();
287 |
288 | $string = str_replace('', '', $string);
289 | $string = str_replace('