twitter-helpers-surface.php
2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Yoast\WP\SEO\Surfaces;
use Yoast\WP\SEO\Exceptions\Forbidden_Property_Mutation_Exception;
use Yoast\WP\SEO\Helpers\Twitter;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class Twitter_Helpers_Surface.
*
* Surface for the indexables.
*
* @property Twitter\Image_Helper $image
*/
class Twitter_Helpers_Surface {
/**
* The DI container.
*
* @var ContainerInterface
*/
private $container;
/**
* Loader constructor.
*
* @param ContainerInterface $container The dependency injection container.
*/
public function __construct( ContainerInterface $container ) {
$this->container = $container;
}
/**
* Magic getter for getting helper classes.
*
* @param string $helper The helper to get.
*
* @return mixed The helper class.
*/
public function __get( $helper ) {
return $this->container->get( $this->get_helper_class( $helper ) );
}
/**
* Magic isset for ensuring helper exists.
*
* @param string $helper The helper to get.
*
* @return bool Whether the helper exists.
*/
public function __isset( $helper ) {
return $this->container->has( $this->get_helper_class( $helper ) );
}
/**
* Prevents setting dynamic properties and unsetting declared properties
* from an inaccessible context.
*
* @param string $name The property name.
* @param mixed $value The property value.
*
* @return void
*
* @throws Forbidden_Property_Mutation_Exception Set is never meant to be called.
*/
public function __set( $name, $value ) { // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- __set must have a name and value.
throw Forbidden_Property_Mutation_Exception::cannot_set_because_property_is_immutable( $name );
}
/**
* Prevents unsetting dynamic properties and unsetting declared properties
* from an inaccessible context.
*
* @param string $name The property name.
*
* @return void
*
* @throws Forbidden_Property_Mutation_Exception Unset is never meant to be called.
*/
public function __unset( $name ) {
throw Forbidden_Property_Mutation_Exception::cannot_unset_because_property_is_immutable( $name );
}
/**
* Get the class name from a helper slug
*
* @param string $helper The name of the helper.
*
* @return string
*/
protected function get_helper_class( $helper ) {
$helper = \implode( '_', \array_map( 'ucfirst', \explode( '_', $helper ) ) );
return "Yoast\WP\SEO\Helpers\Twitter\\{$helper}_Helper";
}
}