是否有可能从现有MySQL数据库自动生成YAML模式文件?
我需要为Doctrine创建模型,但手动编写模型类对我来说似乎非常无聊.我已经拥有带有表格和所有关系的MySQL数据库,所以如果有某种方法可以从中生成Doctrine模型,它会对我有所帮助.
首先,我使用StringLength验证器验证密码长度,因此我想将其保留在PasswordStrength验证器之外.任何想法如何改善这个?
我认为我对数组和array_diff的方法并不是很优雅,但我能想到的另一种方法是正则表达式,它更加难看.
<?php
class My_Validate_PasswordStrength extends Zend_Validate_Abstract
{
const MSG_NO_NUMBER = 'msgNoNumber';
const MSG_NO_LOWER_CASE_LETTER = 'msgNoLowerCaseLetter';
const MSG_NO_UPPER_CASE_LETTER = 'msgNoUpperCaseLetter';
protected $_messageTemplates = array(
self::MSG_NO_NUMBER => "'%value%' must contain at least one number",
self::MSG_NO_LOWER_CASE_LETTER => "'%value%' must contain at least one lower case letter",
self::MSG_NO_UPPER_CASE_LETTER => "'%value%' must contain at least one upper case letter"
);
public function isValid($value)
{
$this->_setValue($value);
$arr = str_split($value);
$numbers = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$lowerCaseLetters = array('a', 'b', …Run Code Online (Sandbox Code Playgroud) 因此,我得到了一个远程API规范,该规范将用于创建一组类以与我的应用程序中的该API通信。
在设计将用作API客户端的这些类时,我应该注意什么设计模式?
我想备份两个表:table1和table2.
table1来自数据库database1.
table2来自数据库database2.
有没有办法用一个mysqldump调用转储它们?
我知道我能做到:
mysqldump -S unixSocket --skip-comments --default-character-set=utf8 --databases database1 --tables table1 > /tmp/file.sql
Run Code Online (Sandbox Code Playgroud)
但是如何从不同的数据库转储两个表?
所以这不起作用:
foreach ($element->attributes as $attribute) {
$element->removeAttribute($attribute->name);
}
Run Code Online (Sandbox Code Playgroud)
如果节点有2个属性,则只删除第一个属性.
我尝试克隆DOMNamedNodeMap但没有成功:
$attributesCopy = clone $element->attributes;
foreach ($attributesCopy as $attribute) {
$element->removeAttribute($attribute->name);
}
Run Code Online (Sandbox Code Playgroud)
仍然只删除第一个属性.
这个问题在这里解释:http://php.net/manual/en/class.domnamednodemap.php 显然它是一个功能,而不是一个bug.但是评论中没有提到解决方案.
如何检测iPhone是否有视网膜显示器?有可靠的方法吗?要么是纯PHP,要么是Zend Framework这样做的方式.
编辑:
我刚刚意识到我正在使用 auto-complete.el 0.2 版本。我想我需要使用 auto-complete.el 版本 0.1。我可以从哪里下载它?我只能在 Google 上找到较新的版本。
我正在尝试在 Emacs 中为 Python 设置自动完成功能。
我使用的是 Ubuntu LTS 版本,我安装了 Python 和 Emacs。
这是我的 .emacs 文件:
(setq-default indent-tabs-mode nil) ; always replace tabs with spaces
(setq-default tab-width 4) ; set tab width to 4 for all buffers
(add-to-list 'load-path "~/.emacs.d/vendor")
(progn (cd "~/.emacs.d/vendor")
(normal-top-level-add-subdirs-to-load-path))
(require 'python)
(require 'auto-complete)
(require 'yasnippet)
(autoload 'python-mode "python-mode" "Python Mode." t)
(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
(add-to-list 'interpreter-mode-alist '("python" . python-mode))
;; Initialize Pymacs
(autoload 'pymacs-apply …Run Code Online (Sandbox Code Playgroud) 所以我创建了一个实现SessionhandlerInterface的类并将其设置为会话处理程序:
$sessionHandler = new SessionHandler();
session_set_save_handler($sessionHandler);
session_start();
Run Code Online (Sandbox Code Playgroud)
问题是,从不调用write函数.
如果我使用session_set_save_handler的第二个参数并将其设置为false:
session_set_save_handler($sessionHandler, false);
Run Code Online (Sandbox Code Playgroud)
然后它正常工作.有人可以向我解释这种行为吗?我使用的是PHP 5.4.6.
在文档中写道:
当使用对象作为会话保存处理程序时,使用PHP注册shutdown函数非常重要,以避免PHP内部在关闭时内部销毁对象的方式产生意外的副作用,并可能阻止调用write和close.通常,您应该使用register_shutdown_function()函数注册'session_write_close'.
从PHP 5.4.0开始,您可以使用session_register_shutdown()或在使用OOP方法调用session_set_save_handler()并传递实现SessionHandlerInterface的实例时使用'register shutdown'标志.
但我并不完全明白这一点.
如何使用PHPUnit在控制器操作中测试重定向?
class IndexControllerTest extends PHPUnit_Framework_TestCase
{
protected $_controller;
protected $_request;
protected $_response;
protected $_routeMatch;
protected $_event;
public function setUp()
{
$this->_controller = new IndexController;
$this->_request = new Request;
$this->_response = new Response;
$this->_routeMatch = new RouteMatch(array('controller' => 'index'));
$this->_routeMatch->setMatchedRouteName('default');
$this->_event = new MvcEvent();
$this->_event->setRouteMatch($this->_routeMatch);
$this->_controller->setEvent($this->_event);
}
public function testIndexActionRedirectsToLoginPageWhenNotLoggedIn()
{
$this->_controller->dispatch($this->_request, $this->_response);
$this->assertEquals(200, $this->_response->getStatusCode());
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码在运行单元测试时导致此错误:
Zend\Mvc\Exception\DomainException: Url plugin requires that controller event compose a router; none found
Run Code Online (Sandbox Code Playgroud)
这是因为我在控制器动作中进行重定向.如果我不进行重定向,则单元测试工作正常.有任何想法吗?
我已将此行添加到我的composer.json中:
"gedmo/doctrine-extensions": "dev-master"
Run Code Online (Sandbox Code Playgroud)
这是在我的模块的module.config.php中:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity'),
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
),
),
),
),
Run Code Online (Sandbox Code Playgroud)
然后我想在我的实体中使用带时间戳的注释,例如:
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime",nullable=true)
*/
private $created;
/**
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime",nullable=true)
*/
private $updated;
Run Code Online (Sandbox Code Playgroud)
但这不起作用.当我使用上面的注释持久化实体时,创建和更新的列为NULL.