WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
класс не описан

Yoast\WP\SEO

Main{} Yoast 1.0

Class Main.

Хуков нет.

Возвращает

Null. Ничего.

Использование

$Main = new Main();
// use class methods

Методы

  1. __get( $property )
  2. __isset( $property )
  3. get_container()
  4. is_development()
  5. load()

Код Main{} Yoast 15.6.2

<?php
class Main {

	/**
	 * The API namespace constant.
	 *
	 * @var string
	 */
	const API_V1_NAMESPACE = 'yoast/v1';

	/**
	 * The WP CLI namespace constant.
	 *
	 * @var string
	 */
	const WP_CLI_NAMESPACE = 'yoast';

	/**
	 * The DI container.
	 *
	 * @var Cached_Container|null
	 */
	private $container;

	/**
	 * Surface classes that provide our external interface.
	 *
	 * @var string[]
	 */
	private $surfaces = [
		'classes' => Classes_Surface::class,
		'meta'    => Meta_Surface::class,
		'helpers' => Helpers_Surface::class,
	];

	/**
	 * Loads the plugin.
	 *
	 * @throws Exception If loading fails and YOAST_ENVIRONMENT is development.
	 */
	public function load() {
		if ( $this->container ) {
			return;
		}

		try {
			$this->container = $this->get_container();

			if ( ! $this->container ) {
				return;
			}

			$this->container->get( Loader::class )->load();
		} catch ( Exception $e ) {
			if ( $this->is_development() ) {
				throw $e;
			}
			// Don't crash the entire site, simply don't load.
			// TODO: Add error notifications here.
		}
	}

	/**
	 * Magic getter for retrieving a property.
	 *
	 * @param string $property The property to retrieve.
	 *
	 * @throws Exception When the property doesn't exist.
	 *
	 * @return string The value of the property.
	 */
	public function __get( $property ) {
		if ( isset( $this->{$property} ) ) {
			$this->{$property} = $this->container->get( $this->surfaces[ $property ] );

			return $this->{$property};
		}
		throw new Exception( "Property $property does not exist." );
	}

	/**
	 * Checks if the given property exists as a surface.
	 *
	 * @param string $property The property to retrieve.
	 *
	 * @return bool True when property is set.
	 */
	public function __isset( $property ) {
		return isset( $this->surfaces[ $property ] );
	}

	/**
	 * Loads the DI container.
	 *
	 * @throws Exception If something goes wrong generating the DI container.
	 *
	 * @return null|Cached_Container The DI container.
	 */
	private function get_container() {
		if ( $this->is_development() && \class_exists( '\Yoast\WP\SEO\Dependency_Injection\Container_Compiler' ) ) {
			// Exception here is unhandled as it will only occur in development.
			Container_Compiler::compile( $this->is_development() );
		}

		if ( \file_exists( __DIR__ . '/generated/container.php' ) ) {
			require_once __DIR__ . '/generated/container.php';

			return new Cached_Container();
		}

		return null;
	}

	/**
	 * Returns whether or not we're in an environment for Yoast development.
	 *
	 * @return bool Whether or not to load in development mode.
	 */
	private function is_development() {
		return \defined( 'YOAST_ENVIRONMENT' ) && \YOAST_ENVIRONMENT === 'development';
	}
}