| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Surfaces; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Helpers\Open_Graph; |
| 6 |
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface; |
| 7 |
|
| 8 |
/** |
| 9 |
* Class Open_Graph_Helpers_Surface. |
| 10 |
* |
| 11 |
* Surface for the indexables. |
| 12 |
* |
| 13 |
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded -- 4 words is fine. |
| 14 |
* |
| 15 |
* @property Open_Graph\Image_Helper $image |
| 16 |
*/ |
| 17 |
class Open_Graph_Helpers_Surface { |
| 18 |
|
| 19 |
/** |
| 20 |
* The DI container. |
| 21 |
* |
| 22 |
* @var ContainerInterface |
| 23 |
*/ |
| 24 |
private $container; |
| 25 |
|
| 26 |
/** |
| 27 |
* Loader constructor. |
| 28 |
* |
| 29 |
* @param ContainerInterface $container The dependency injection container. |
| 30 |
*/ |
| 31 |
public function __construct( ContainerInterface $container ) { |
| 32 |
$this->container = $container; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Magic getter for getting helper classes. |
| 37 |
* |
| 38 |
* @param string $helper The helper to get. |
| 39 |
* |
| 40 |
* @return mixed The helper class. |
| 41 |
*/ |
| 42 |
public function __get( $helper ) { |
| 43 |
return $this->container->get( $this->get_helper_class( $helper ) ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Magic isset for ensuring helper exists. |
| 48 |
* |
| 49 |
* @param string $helper The helper to get. |
| 50 |
* |
| 51 |
* @return bool The helper class. |
| 52 |
*/ |
| 53 |
public function __isset( $helper ) { |
| 54 |
return $this->container->has( $this->get_helper_class( $helper ) ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Get the class name from a helper slug |
| 59 |
* |
| 60 |
* @param string $helper The name of the helper. |
| 61 |
* |
| 62 |
* @return string |
| 63 |
*/ |
| 64 |
protected function get_helper_class( $helper ) { |
| 65 |
$helper = \implode( '_', \array_map( 'ucfirst', \explode( '_', $helper ) ) ); |
| 66 |
return "Yoast\WP\SEO\Helpers\Open_Graph\\{$helper}_Helper"; |
| 67 |
} |
| 68 |
} |
| 69 |
|