不确定这应该在这里还是程序员.
我想就如何为内部项目生成API文档提出一些建议.我对Git相对较新,我们正在尝试实施一些合理的构建/部署实践.
我们讨论过的一件事是确保我们的代码库有充分的文档记录,并使用像PhpDocumentor2或许多类似工具之一生成文档.
我们已经开始实施类似于此处详述的工作流程.
例如,在标记版本时git中的pre或post提交挂钩.或者,当我合并开发到发布分支时,只需手动创建文档并提交到存储库?
如果新的doc发布与git发布/标记相关,我可能误解了这个过程?
在同一个存储库中?不同的存储库?像Read The Docs或仅在内部托管?我们正在开发的当前项目很小,但如果成功的话,我们希望将来将这个过程推广到其他更大的项目.
该项目是Magento扩展,我们希望提供API文档,单元测试和PSR符合代码.我缺乏有关整个工作流程如何集成的信息.PHPunit和PHPDocumentor2通过Composer在本地安装.
我听过并看过Travis Ci,但我不确定Docs是否属于那个类别.
这个问题可能看起来很小和/或微不足道,但是,我在集成和git工作流方面没有多少经验,我找不到太多的信息.
我在尝试对使用ZfcUser进行身份验证的操作进行单元测试时遇到问题.我需要一些方法来模拟ZfcUser Controller插件,但我不太确定如何做到这一点.我已成功地为表格和模型生成了一些单元测试,但是控制器需要大量注入的对象并导致问题.有谁知道如何设置ZfcUser模拟器来成功测试控制器?
这是我的测试(从ZF2教程复制):
<?php
namespace SmsTest\Controller;
use SmsTest\Bootstrap;
use Sms\Controller\SmsController;
use Zend\Http\Request;
use Zend\Http\Response;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\Router\RouteMatch;
use Zend\Mvc\Router\Http\TreeRouteStack as HttpRouter;
use PHPUnit_Framework_TestCase;
class SmsControllerTest extends PHPUnit_Framework_TestCase
{
protected $controller;
protected $request;
protected $response;
protected $routeMatch;
protected $event;
protected function setUp()
{
$serviceManager = Bootstrap::getServiceManager();
$this->controller = new SmsController();
$this->request = new Request();
$this->routeMatch = new RouteMatch(array('controller' => 'index'));
$this->event = new MvcEvent();
$config = $serviceManager->get('Config');
$routerConfig = isset($config['router']) ? $config['router'] : array();
$router = HttpRouter::factory($routerConfig);
$this->event->setRouter($router);
$this->event->setRouteMatch($this->routeMatch);
$this->controller->setEvent($this->event); …Run Code Online (Sandbox Code Playgroud) 我有以下代码在图像上打印文本.我还在文本周围添加了一个调试框.但是,我注意到左边的文本位于PHP给我的框之外imagettfbbox.
这看起来像字体swash的问题.无论如何还有这个吗?我可以弄清楚斜线开始和实际位置之间的距离imagettfbbox吗?
我不认为这是字体的问题,因为我尝试使用一些脚本样式字体,结果是相似的.
<?php
$font = 'scriptin.ttf';
$text = 'Ipsum';
$size = 30;
$image = imagecreatetruecolor(200, 200);
$fontColour = imagecolorallocate($image, hexdec('11'), hexdec('11'), hexdec('11'));
$bgColour = imagecolorallocate($image, hexdec('CC'), hexdec('CC'), hexdec('CC'));
imagefilledrectangle($image, 0, 0, 200, 200, $bgColour);
$dimensions = imagettfbbox($size, 0, $font, $text);
imagefilledrectangle(
$image,
$dimensions[0] + 40,
$dimensions[7] + 50,
$dimensions[2] + 40,
$dimensions[3] + 50,
imagecolorallocate($image, mt_rand(1, 180), mt_rand(1, 180), mt_rand(1, 180))
);
imagettftext(
$image,
$size,
0,
40,
50,
$fontColour,
$font,
$text
);
header('Content-Type: image/png');
imagepng($image); …Run Code Online (Sandbox Code Playgroud) 基本上它在锡上说的是:
if(is_dir($dir))
echo $dir . " is a directory\n";
if(is_readable($dir))
echo $dir . " is readable\n";
if($this->handle = opendir($dir))
echo $dir . " opened\n";
Run Code Online (Sandbox Code Playgroud)
返回:
\\ HTPC\MOVIES是一个目录
\\ HTPC\MOVIES开通了
哪个很奇怪?我可以遍历目录中的文件,但显然它是不可读的.这并不重要,因为我说我仍然可以阅读文件,但我发现它有点奇怪.
有人有想法吗?
或者任何框架.
以Zend Framework 2为例,我有以下表类:
<?php
namespace Contact\Model;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Log\Logger;
class UserContactsTable extends AbstractTableGateway
{
protected $tableGateway;
/**
*
* @var \Zend\Log\Logger Instance
*/
protected $logger;
public function __construct(TableGateway $tableGateway, Logger $logger )
{
$this->tableGateway = $tableGateway;
$this->logger = $logger;
}
/**
* Save a contact
*
* @param \Sms\Model\UserContact $userContact
*/
public function saveUserContact(UserContact $userContact)
{
$data = array(
'user_id' => $userContact->user_id,
'contact_id' => $userContact->contact_id
);
try {
$this->tableGateway->insert($data);
} catch (\Exception $e) {
//log
$this->logger->crit($omeErrMsg); …Run Code Online (Sandbox Code Playgroud) php error-handling model-view-controller logging zend-framework2
我在我的表格中使用这个:
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'county',
'registerInArrayValidator' => false,
'attributes' => array(
'id' => 'county',
'options' => array(
//'null'=>'[Select county]',
),
),
'options' => array(
'label' => 'county',
),
));
Run Code Online (Sandbox Code Playgroud)
并使用js设置值县字段.验证后,我收到错误:haystack选项是必需的
是否可以在 Postgres 中执行以下操作:
SELECT column_name FROM information_schema WHERE table_name = 'somereport' AND data_type = 'integer';
SELECT SUM(coulmn_name[0]),SUM(coulmn_name[1]) ,SUM(coulmn_name[3]) FROM somereport;
Run Code Online (Sandbox Code Playgroud)
换句话说,我需要根据特定条件从表中选择一组列,然后对表中的每一列求和。
我知道我可以在循环中执行此操作,因此我可以独立计算每个列,但显然这需要对从信息模式查询返回的每个列进行查询。例如:
FOR r IN select column_name from information_schema where report_view_name = 'somereport' and data_type = 'integer';
LOOP
SELECT SUM(r.column_name) FROM somereport;
END
Run Code Online (Sandbox Code Playgroud) 嗨,我试图掌握Zend 2,我在表网关中的where子句有一些问题.
下面是我的表类:
//module\Detectos\src\Detectos\Model\OperatingSystemTable.php
namespace Detectos\Model;
use Zend\Db\TableGateway\TableGateway;
class OperatingSystemsTable
{
public function findOs($userAgent)
{
$resultSet = $this->tableGateway->select();
foreach ($resultSet as $osRow)
{
//check if the OS pattern of this row matches the user agent passed in
if (preg_match('/' . $osRow->getOperatingSystemPattern() . '/i', $userAgent)) {
return $osRow; // Operating system was matched so return $oses key
}
}
return 'Unknown'; // Cannot find operating system so return Unknown
}
}
Run Code Online (Sandbox Code Playgroud)
模型是这样的:
class Detectos
{
public $id;
public $operating_system;
public $operating_system_pattern; …Run Code Online (Sandbox Code Playgroud) 我的任务是构建一个字体预览系统.
用户提供一些文本,文本使用用户请求的字体呈现为图像.图像传送给用户.
对于实际渲染有任何安全隐患吗?我该如何验证传入的文本?我需要吗?我应该删除标签吗?
忽略存储和检索图像的问题,我理解了很多.如果有任何针对图像渲染文本的攻击,我只是好奇.
编辑:图片将是PNG的
php ×6
fonts ×2
build ×1
deployment ×1
dynamic-sql ×1
forms ×1
gd ×1
git ×1
image ×1
logging ×1
php-gd ×1
phpunit ×1
plpgsql ×1
postgresql ×1
security ×1
sql ×1
tablegateway ×1
unit-testing ×1
validation ×1
zfcuser ×1