first commit
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
class OTGS_Installer_Log_Factory {
|
||||
|
||||
/**
|
||||
* @return OTGS_Installer_Log
|
||||
*/
|
||||
public function create() {
|
||||
return new OTGS_Installer_Log();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
class OTGS_Installer_Log {
|
||||
|
||||
private $time;
|
||||
private $request_url;
|
||||
private $request_args;
|
||||
private $response;
|
||||
private $component;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_time() {
|
||||
return $this->time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $time
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_time( $time ) {
|
||||
$this->time = $time;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_request_url() {
|
||||
return $this->request_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $request_url
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_request_url( $request_url ) {
|
||||
$this->request_url = $request_url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_request_args() {
|
||||
return $this->request_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $request_args
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_request_args( $request_args ) {
|
||||
$this->request_args = $request_args;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_response() {
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $response
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_response( $response ) {
|
||||
$this->response = $response;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_component() {
|
||||
return $this->component;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $component
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_component( $component ) {
|
||||
$this->component = $component;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
class OTGS_Installer_Logger_Storage {
|
||||
|
||||
const MAX_SIZE = 50;
|
||||
|
||||
const OPTION_KEY = 'otgs-installer-log';
|
||||
|
||||
const COMPONENT_SUBSCRIPTION = 'subscription-fetching';
|
||||
const COMPONENT_PRODUCTS_URL = 'products-url-fetching';
|
||||
const COMPONENT_DOWNLOAD = 'download';
|
||||
const COMPONENT_REPOSITORIES = 'repositories-fetching';
|
||||
const COMPONENT_PRODUCTS_PARSING = 'products-parsing';
|
||||
const API_CONNECTION_TEST = 'api-connection-test';
|
||||
const PRODUCTS_FILE_CONNECTION_TEST = 'products-connection-test';
|
||||
|
||||
private $log_entries;
|
||||
private $log_factory;
|
||||
private $max_size;
|
||||
|
||||
public function __construct( OTGS_Installer_Log_Factory $log_factory, $max_size = self::MAX_SIZE ) {
|
||||
$this->max_size = $max_size;
|
||||
$this->log_factory = $log_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|OTGS_Installer_Log[]
|
||||
*/
|
||||
public function get() {
|
||||
if ( ! $this->log_entries ) {
|
||||
$this->log_entries = get_option( self::OPTION_KEY );
|
||||
}
|
||||
|
||||
return $this->convert_to_object( $this->log_entries ? $this->log_entries : array() );
|
||||
}
|
||||
|
||||
public function add( OTGS_Installer_Log $log ) {
|
||||
$log->set_time( date( 'Y-d-m h:m:s' ) );
|
||||
$log_entries = $this->get();
|
||||
array_unshift( $log_entries, $log );
|
||||
$log_entries = array_slice( $log_entries, 0, $this->max_size );
|
||||
$log_entries_arr = $this->convert_to_array( $log_entries );
|
||||
update_option( self::OPTION_KEY, $log_entries_arr );
|
||||
$this->log_entries = $log_entries_arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $log_entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function convert_to_object( $log_entries ) {
|
||||
$log_converted = array();
|
||||
|
||||
foreach ( $log_entries as $log_data ) {
|
||||
$log = $this->log_factory->create();
|
||||
$log->set_request_args( $log_data['request_args'] )
|
||||
->set_request_url( $log_data['request_url'] )
|
||||
->set_response( $log_data['response'] )
|
||||
->set_time( $log_data['time'] )
|
||||
->set_component( $log_data['component'] );
|
||||
$log_converted[] = $log;
|
||||
}
|
||||
|
||||
return $log_converted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OTGS_Installer_Log[] $log_entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function convert_to_array( $log_entries ) {
|
||||
$log_converted = array();
|
||||
|
||||
foreach ( $log_entries as $log_data ) {
|
||||
$log_converted[] = array(
|
||||
'request_args' => $log_data->get_request_args(),
|
||||
'request_url' => $log_data->get_request_url(),
|
||||
'response' => $log_data->get_response(),
|
||||
'component' => $log_data->get_component(),
|
||||
'time' => $log_data->get_time(),
|
||||
);
|
||||
}
|
||||
|
||||
return $log_converted;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
class OTGS_Installer_Logger {
|
||||
|
||||
private $installer;
|
||||
private $storage;
|
||||
private $logger_factory;
|
||||
|
||||
public function __construct( WP_Installer $installer, OTGS_Installer_Logger_Storage $storage ) {
|
||||
$this->installer = $installer;
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
public function get_api_log() {
|
||||
return $this->installer->get_api_debug();
|
||||
}
|
||||
|
||||
public function add_api_log( $log ) {
|
||||
$this->installer->api_debug_log( $log );
|
||||
}
|
||||
|
||||
public function save_log( OTGS_Installer_Log $log ) {
|
||||
$this->storage->add( $log );
|
||||
}
|
||||
|
||||
public function add_log( $log ) {
|
||||
$this->installer->log( $log );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user