我想知道价值管理清单是否有良好的做法.例如,我有一个数据库表日志如下:
--------------- | logs | |-------------| | id | | idLogType | | message | | date | ---------------
我的问题是关于字段"idLogType".我知道枚举不是处理这种字段的好方法,因为如果我想添加新值,我必须改变表格.所以我要创建一个值列表.
你有什么建议来处理价值观?
class LogTypeValues {
const LOGTYPE_CREATION = 1;
const LOGTYPE_EDITION = 2;
const LOGTYPE_DELETION = 3;
private $_logTypes = array();
public function __construct() {
$this->_logTypes[self::LOGTYPE_CREATION] = "Creation";
$this->_logTypes[self::LOGTYPE_EDITION] = "Edition";
$this->_logTypes[self::LOGTYPE_DELETION] = "Deletion";
}
public function getId($logType) { ... }
public function getLogType($id) { ... }
}
$request = $pdo->prepare('INSERT INTO logs SET idLogType = :idLogType, ...');
$request->execute(array('idLogType' => …Run Code Online (Sandbox Code Playgroud) 我在课堂设计上陷入两难境地.我正在尽力尊重SOLID原则,但我不知道如何处理依赖注入.
这是我的困境:
为了说明我的困境,我试图创建一个用例.
我想创建一个脚本(我在下面部分实现),生成一个文件并打印另一个文件:
<?php
/**
* Generate a file, add it to the queue and print the next one
*/
class Script
public function run() {
#Generate file
$fileComputor = new FileComputer(...);
$file = $fileComputor->compute();
#Instantiate dependencies for printing
$db = new Db(new PdoAdapter());
$printerDriver = new Driver(new HttpRequest(new CurlAdapter()));
$log = new Log($db);
$queue = new Queue($db);
$statsUpdater = new StatsUpdater($db);
$monitor = new Monitor(new StatsdDriver(new SocketAdapter()));
#Add generated file to the queue
$queueModel->push($file);
#Print …Run Code Online (Sandbox Code Playgroud) 我有两个服务器:一个用于开发,可以轻松访问WEB,另一个用于生产,只能使用代理访问WEB.
我想从我的生产服务器调用SOAP WEB服务.
以下是代码(URL是假的):
$url = 'https://www.webservice.com/soap.php';
$wsdl = 'https://www.webservice.com/soap.php?wsdl';
$client = new SoapClient
(
$wsdl,
array
(
'location' => $url,
'proxy_host' => 'www.myproxy.com',
'proxy_port' => 8080,
)
);
$namespace = 'urn:mynamespace';
$header = array
(
'header1' => 'H1',
'header2' => 'H2',
'header3' => 'H3',
);
$client->__setSoapHeaders(new SoapHeader($namespace, 'myHeader', $header));
$params = array
(
'param1' => 'val1',
'param2' => 'val2',
'param3' => 'val3',
);
$result = $client->method($params);
Run Code Online (Sandbox Code Playgroud)
我从我的开发服务器运行它,我得到了预期的结果.现在我从我的生产服务器运行它,我得到:
PHP Warning: SoapClient::SoapClient(https://www.webservice.com/soap.php?wsdl): failed to open stream: HTTP request failed! HTTP/1.1 400 …Run Code Online (Sandbox Code Playgroud)