传递这个选项数组时:
$this->service_options = array(
array( 'key' => 'ADDENDIO_SERVICE_LIFETIME', 'value' => '15' ),
array( 'key' => 'DB_NAME', 'value' => 'db_name' ),
array( 'key' => 'DB_USER', 'value' => 'db_user' ),
array( 'key' => 'DB_PASS', 'value' => 'db_pass' ),
array( 'key' => 'SSH_USER', 'value' => 'ssh_root' ),
array( 'key' => 'SSH_PASS', 'value' => 'ssh_pass' ),
array( 'key' => 'VIRTUAL_HOST', 'value' => 'mytestcontainer.n1.addendio.com' ),
array( 'key' => 'DB_HOST', 'value' => '127.0.0.1' ),
array(
'key' => 'WP_CLI',
'value' => array(
'wp core download --version=4.7.4 --locale=en_US',
'wp core config --dbname={DB_NAME} --dbuser={DB_USER} --dbpass={DB_PASS} --dbhost={DB_HOST}',
'wp core install --url=http://mytestcontainer.n1.addendio.com --title=WordPress --admin_user=admin --admin_password=parol --admin_email=testadmin@mail.com --skip-plugins --skip-themes',
'wp plugin install akismet',
'wp plugin activate akismet',
'wp option add dwpb_enable=yes=--autoload=yes',
'wp option add dwpbcd_use=yes=--autoload=yes',
'wp option add dwpbcd_time_left="2017-05-03 03:06"=--autoload=yes',
'wp option add dwpbcd_text="Before shutdown."=--autoload=yes',
'wp option add dwpbcd_link_text="Get a FREE 60 minutes sandbox by registering to Addendio.com" --autoload=yes',
'wp option add dwpbcd_link_url="https://addendio.com/wp-login.php?action=register" --autoload=yes',
'wp option add dwpbcd_link_target="_blank" --autoload=yes',
'wp plugin install rating-widget',
'wp plugin activate rating-widget',
),
),
);
并像这样处理它们:
public function create_service() {
$user = Addendio_Sandbox_Management::USERNAME;
$password = Addendio_Sandbox_Management::API_KEY;
$service = wp_safe_remote_post(
self::HOST . self::URL,
array(
'httpversion' => '1.1',
'headers' => array(
'Content-type' => 'application/json',
'Accept' => 'application/json',
'charset' => 'utf-8',
'Authorization' => 'Basic ' . base64_encode( "{$user}:{$password}" ),
),
'body' => json_encode( array(
'image' => self::IMAGE,
'container_envvars' => $this->service_options,
'target_num_containers' => 1,
) ),
)
);
}
WP_CLI变量以奇怪的方式进入API:
[u'wp core download --version=4.7.4 --locale=en_US', u'wp core config --dbname={DB_NAME} --dbuser={DB_USER} --dbpass={DB_PASS} --dbhost={DB_HOST}', u'wp core install --url=http://mytestcontainer.n1.addendio.com --title=WordPress --admin_user=admin --admin_password=parol --admin_email=testadmin@mail.com --skip-plugins --skip-themes', u'wp plugin install akismet', u'wp plugin activate akismet', u'wp option add dwpb_enable=yes=--autoload=yes', u'wp option add dwpbcd_use=yes=--autoload=yes', u'wp option add dwpbcd_time_left="2017-05-03 03:06"=--autoload=yes', u'wp option add dwpbcd_text="Before shutdown."=--autoload=yes', u'wp option add dwpbcd_link_text="Get a FREE 60 minutes sandbox by registering to Addendio.com" --autoload=yes', u'wp option add dwpbcd_link_url="https://addendio.com/wp-login.php?action=register" --autoload=yes', u'wp option add dwpbcd_link_target="_blank" --autoload=yes', u'wp plugin install rating-widget', u'wp plugin activate rating-widget']
似乎WP_CLI数组中每个项目的第一个引号都替换为: 的u'
我尝试使用不同常量参数的json_encode,但仍然没有运气。 也许有人遇到类似的问题?