boot();
}
return self::$instance;
}
/**
* Register hooks.
*
* @return void
*/
public function boot(): void {
if ( Compatibility::is_supported() ) {
( new Admin() )->register();
( new Scheduler( $this ) )->register();
PublicDownload::register();
add_action( 'backupino_job_completed', array( $this, 'notify_completed_job' ) );
add_action( 'init', array( $this, 'maybe_flush_notifications' ), 20 );
} else {
add_action( 'admin_notices', array( $this, 'render_compatibility_notice' ) );
}
if ( defined( 'WP_CLI' ) && WP_CLI ) {
Commands::register( $this );
}
}
/**
* Show blocking requirements as an admin notice.
*
* @return void
*/
public function render_compatibility_notice(): void {
if ( ! Capabilities::user_can_manage() ) {
return;
}
$issues = Compatibility::blocking_issues();
printf(
'
%s
',
esc_html__( 'Backupino cannot run on this server:', 'backupino' )
);
foreach ( $issues as $issue ) {
printf( '- %s
', esc_html( $issue ) );
}
echo '
';
}
/**
* Clock.
*
* @return Clock
*/
public function clock(): Clock {
if ( null === $this->clock ) {
$this->clock = new SystemClock();
}
return $this->clock;
}
/**
* Settings.
*
* @return Settings
*/
public function settings(): Settings {
if ( null === $this->settings ) {
$this->settings = new Settings( new WpOptions() );
}
return $this->settings;
}
/**
* Paths.
*
* @return Paths
*/
public function paths(): Paths {
if ( null === $this->paths ) {
$this->paths = Paths::from_wordpress();
}
return $this->paths;
}
/**
* Database adapter.
*
* @return Db
*/
public function db(): Db {
if ( null === $this->db ) {
$this->db = new WpDbAdapter();
}
return $this->db;
}
/**
* Permanent download link service.
*
* @return DownloadLink
*/
public function download_link(): DownloadLink {
if ( null === $this->download_link ) {
$this->download_link = new DownloadLink( new WpOptions() );
}
return $this->download_link;
}
/**
* Notification sender.
*
* @return Notifier
*/
public function notifier(): Notifier {
if ( null === $this->notifier ) {
$this->notifier = new Notifier( $this->settings(), new WpOptions(), $this->download_link() );
}
return $this->notifier;
}
/**
* Human readable site name for messages.
*
* @return string
*/
public function site_name(): string {
$host = (string) wp_parse_url( home_url(), PHP_URL_HOST );
if ( '' !== $host ) {
return $host;
}
return (string) home_url();
}
/**
* Announce a finished backup.
*
* @param mixed $job Finished job.
* @return void
*/
public function notify_completed_job( $job ): void {
if ( ! $job instanceof Job ) {
return;
}
$this->notifier()->announce( $job, $this->site_name() );
}
/**
* Flush any queued notifications via native WordPress HTTP API.
*
* @return void
*/
public function maybe_flush_notifications(): void {
$queue = get_option( 'backupino_notify_queue', array() );
if ( is_array( $queue ) && ! empty( $queue ) ) {
$this->notifier()->flush();
}
}
/**
* Logger.
*
* @return Logger
*/
public function logger(): Logger {
if ( null === $this->logger ) {
$this->logger = new Logger(
$this->paths()->logs() . '/backupino.log',
(string) $this->settings()->get( 'advanced.log_level', 'info' )
);
}
return $this->logger;
}
/**
* Jobs repository.
*
* @return JobRepository
*/
public function jobs(): JobRepository {
if ( null === $this->jobs ) {
$this->jobs = new JobRepository( $this->db(), $this->clock() );
}
return $this->jobs;
}
/**
* Pipeline.
*
* @return Pipeline
*/
public function pipeline(): Pipeline {
if ( null === $this->pipeline ) {
$this->pipeline = new Pipeline(
array(
new ScanStage(),
new FilesStage(),
new DatabaseStage(),
new FinalizeStage(),
)
);
}
return $this->pipeline;
}
/**
* Job runner.
*
* @return JobRunner
*/
public function runner(): JobRunner {
if ( null === $this->runner ) {
$this->runner = new JobRunner(
$this->jobs(),
$this->pipeline(),
$this->settings(),
$this->paths(),
$this->logger(),
$this->db(),
$this->clock()
);
}
return $this->runner;
}
/**
* Storage manager.
*
* @return StorageManager
*/
public function storages(): StorageManager {
if ( null === $this->storages ) {
$this->storages = new StorageManager( $this->settings(), $this->paths() );
}
return $this->storages;
}
}