PluginProbe
WP-Stateless – Google Cloud Storage / 2.2.4
WP-Stateless – Google Cloud Storage v2.2.4
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / lib / cli / class-sm-cli-scaffold.php

class-sm-cli-scaffold.php in WP-Stateless – Google Cloud Storage 2.2.4, at lib/cli/class-sm-cli-scaffold.php

86 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SM_CLI_Scaffold {
4
5 /**
6 * Storage for dynamic properties
7 * Used by magic __set, __get
8 *
9 * @protected
10 * @type array
11 */
12 protected $_properties = array();
13
14 /**
15 * @param $args
16 * @param $assoc_args
17 */
18 public function __construct( $args, $assoc_args ) {
19 if ( php_sapi_name() != 'cli' ) {
20 die('Must run from command line');
21 }
22
23 $this->args = $args;
24 $this->assoc_args = $assoc_args;
25 foreach( $assoc_args as $k => $v ) {
26 $this->{$k} = $v;
27 }
28
29 /* Set default Limit */
30 $this->limit = is_numeric( $this->limit ) && $this->limit > 0 ? $this->limit : 100;
31 }
32
33 /**
34 * Forces data printing to command line ignoring buffer.
35 *
36 * @param string $msg
37 */
38 public function output( $msg = '' ) {
39 $args = $this->assoc_args;
40 if( !isset( $args['log'] ) ) return null;
41 echo date( 'H:i:s', time() ) . ': ' . $msg . ' ' . $this->memory_usage() . PHP_EOL;
42 @ob_flush();
43 flush();
44 }
45
46 /**
47 * Returns Memory Usage information.
48 */
49 public function memory_usage() {
50 $args = $this->assoc_args;
51 if( !isset( $args['memory-usage'] ) ) return null;
52 static $last_usage = 0;
53 $differences = $last_usage ? number_format( ( memory_get_usage() / 1024 / 1024 ) - $last_usage, 3 ) . 'Mb' : 'none';
54 $current_usage = number_format( $last_usage = memory_get_usage() / 1024 / 1024, 3 ) . 'Mb';
55 return sprintf( "Memory Usage: %s. Diff: %s.", $current_usage, $differences );
56 }
57
58 /**
59 * Returns domain of current blog.
60 *
61 */
62 public function get_current_blog_domain() {
63 $url = get_home_url();
64 $pieces = parse_url( $url );
65 $domain = isset( $pieces[ 'host' ] ) ? $pieces['host'] : false;
66 return $domain;
67 }
68
69 /**
70 * @param $key
71 *
72 * @return null
73 */
74 public function __get( $key ) {
75 return isset( $this->_properties[ $key ] ) ? $this->_properties[ $key ] : NULL;
76 }
77
78 /**
79 * @param $key
80 * @param $value
81 */
82 public function __set( $key, $value ) {
83 $this->_properties[ $key ] = $value;
84 }
85
86 }