silverstripe-autotoc 

silverstripe-autotoc Git Source Tree

Root/src/Hacks.php

1<?php
2
3namespace eNTiDi\Autotoc;
4
5use SilverStripe\View\ViewableData;
6
7class Hacks extends ViewableData
8{
9 /**
10 * Add a new wrapper method.
11 *
12 * Similar to addWrapperMethod() but made public and working on
13 * custom instances to allow to inject custom wrappers.
14 *
15 * @param string $instance
16 * @param string $method
17 * @param string $wrap
18 */
19 public static function addWrapperMethodToInstance($instance, $method, $wrap)
20 {
21 // hasMethod() trigger the population of $extra_methods
22 $instance->hasMethod('UnexistentMethod');
23 self::$extra_methods[get_class($instance)][strtolower($method)] = [
24 'wrap' => $wrap,
25 'method' => $method,
26 ];
27 }
28
29 /**
30 * @param string $method
31 * @param \Closure $callback
32 */
33 public static function addCallbackMethodToInstance($instance, $method, $callback)
34 {
35 // hasMethod() trigger the population of $extra_methods
36 $instance->hasMethod('UnexistentMethod');
37 self::$extra_methods[get_class($instance)][strtolower($method)] = [
38 'callback' => $callback,
39 ];
40 }
41}

Archive Download this file