我已更新到Symfony 2.8.调试工具栏告诉我很多不推荐的调用,但大多数都是第三方捆绑.
有没有办法过滤掉这些弃用通知,所以我只能看到来自我的捆绑包的那些?这样我可以解决它们,而目前我必须深入了解很多通知,也许我会失去一些不赞成的电话.
我有一个非常简单的类,如下所示:
abstract class Person
{
private $id;
private $createdOn;
// ... More private properties
protected $unfound = array();
Run Code Online (Sandbox Code Playgroud)
构造函数对传递的数组$ data执行操作,并使用正确的方法将值分配给属性.如果该方法不存在,那么将密钥添加到受保护的数组中以保留它的跟踪(我称之为$ unfound,只是为了原始!).
public function __construct($data)
{
foreach ($data as $field => $value)
{
$method = 'set' . ucfirst($field);
if (method_exists($this, $method))
{
$this->$method($value);
}
else
{
$this->unfound[] = $field;
}
}
}
Run Code Online (Sandbox Code Playgroud)
设置属性值的方法列表
public function setId($id) {
$this->id = $id;
}
public function setCreatedOn($createdOn) {
$this->createdOn = $createdOn;
}
Run Code Online (Sandbox Code Playgroud)
以及获取这些指定值的方法列表
public function getId() {
return $this->id;
}
public function getCreatedOn() { …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Symfony 2 项目中使用 Doctrine embeddables。
\n\n我有一堂课Purchase
,其中有一个price
可嵌入的字段:
/**\n * Products\n *\n * @ORM\\Table(name="purchases")\n * @ORM\\Entity\n */\nclass Purchase\n{\n /**\n *\n * @ORM\\Embedded(class="AppBundle\\Entity\\Embeddable\\PriceEmbeddable")\n */\n private $price;\n\n /**\n * Set price\n *\n * @param MoneyInterface $price\n * @return $this\n */\n public function setPrice(MoneyInterface $price)\n {\n $this->price = $price;\n\n return $this;\n }\n\n /**\n * Get price\n *\n * @return MoneyInterface|float\n */\n public function getPrice()\n {\n return $this->price;\n }\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n由于价格需要货币才能完整,因此我有存储这两个值的嵌入类:
\n\n/**\n * @ORM\\Embeddable\n */\nclass PriceEmbeddable\n{\n /** @ORM\\Column(type …
Run Code Online (Sandbox Code Playgroud) 我想使用HeaderCommentFixer
提供的,PHP-CS-Fixer
但我不知道如何使用。
我试图做这样的事情:
$headerCommentFixer = new HeaderCommentFixer();
$headerCommentFixer->setHeader('test this');
return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::NONE_LEVEL)
->setUsingCache(false)
->fixers([
...
$headerCommentFixer,
...
])
->finder($finder);
Run Code Online (Sandbox Code Playgroud)
但是我得到这个错误:
[ErrorException] strpos()期望参数1为字符串,给定对象
那么,我该如何配置呢?我也检查了测试,但是不幸的是这并没有帮助我。
我想在Travis的构建环境中安装PHP扩展OAuth
。
我已经在.travis.yml
文件中尝试了这两种配置:配置1(使用before_script
):
language: php
matrix:
include:
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: hhvm
cache:
directories:
- $HOME/.composer/cache
install:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
script:
- phpunit --verbose --coverage-clover build/logs/clover.xml
- phpenv config-rm xdebug.ini || return 0
before_script:
- pecl install oauth
Run Code Online (Sandbox Code Playgroud)
配置2(使用install
):
language: php
matrix:
include:
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
- …
Run Code Online (Sandbox Code Playgroud) 我正在尝试为stripe-data
使用的字段添加属性createBuilder
.
这是我正在使用的代码:
$form = $this->formFactory->createBuilder(FormType::class, [
'action' => $this->router->generate('storeSubscription', ['id' => $store->getId()]),
'method' => 'POST',
])
->add('plan', PremiumType::class, [
'data_class' => PremiumFeaturesEmbeddable::class,
'data' => $store->getPremium(),
]);
if (null === $store->getBranchOf()->getStripeCustomer() || null === $store->getBranchOf()->getStripeCustomer()->getDefaultSource()) {
$form->add('credit_card', CreditCardStripeTokenType::class)
->add('company_data', CompanyType::class, [
'data_class' => Company::class,
'data' => $store->getBranchOf()
]);
// Remove unused data
$form->get('company_data')
->remove('brand')
->remove('primaryEmail')
->remove('description')
->remove('phoneNumber')
->remove('faxNumber')
->remove('save');
// Set data-stripe
$form->get('company_data')
->get('legalName')->setAttributes(['attr' => ['data-stripe', 'name']]);
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,此代码的最后一行获取第一个copmany_data
表单类型,然后获取该字段legalName
:在此我想设置该属性stripe-data="name"
.
但是这段代码不起作用.
要添加我必须 …
我正在开发一些经常在多个项目中使用的库,并使用 GIT 来对它们进行版本控制。
现在,我想通过 Composer 使用它们。
我的问题是:Composer 使我能够指定一些私有存储库,我可以从中提取源代码以包含在我的应用程序中(https://getcomposer.org/doc/05-repositories.md#using-private-repositories)。
然后,我找到了 Satis:https ://getcomposer.org/doc/articles/handling-private-packages-with-satis.md#satis
现在,我不太明白两者之间的差异,以及使用 Satis 而不是通过 Composer 功能使用私有存储库可以拥有哪些优势。
我真的应该设置 Setis 服务器吗?它给我带来了哪些好处?
我正在尝试使用 Guzzle 5 连接到 WooCommerce API(Guzzle 6 似乎没有 oAuth 选项 oO)。Woocommerce需要 oAuth 身份验证方法才能工作。
这是我正在使用的代码:
<?php
/**
* Example of usage of Guzzle 5 to get information
* from a WooCommerce Store.
*/
require('../vendor/autoload.php');
use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Oauth\Oauth1;
use GuzzleHttp\Exception\RequestException;
$consumer_key = 'my_consumer_key'; // Add your own Consumer Key here
$consumer_secret = 'my_consumer_secret'; // Add your own Consumer Secret here
$store_url = 'http://example.com'; // Add the home URL to the store you want to connect to here
$api_path = …
Run Code Online (Sandbox Code Playgroud) 我有一些命令可以将输出格式化到控制台。
这些命令是使用 Symfony 控制台组件编写的,并使用其样式进行格式化。
在控制台中运行时,格式很好,但这些命令通常也从我编写的队列系统中运行,因此日志会显示在 HTML 页面上。
结果真的很难理解,因为它充满了所有在控制台上有用但在网页上读取输出时完全没有用的格式“标签”。
这是我所说的一个例子:
[32mStarting command[39m
[32m===========================[39m
[34m[>] Analyzing Entity [39m[32This is the entity[39m[34m. [39m
[34m[>] Starting analyzing Entity [39m[32mThis is the entity[39m[34m. [39m
[34m[>] Creating new Job for [39m[30;42This is the entity[39;49m[34m to analyze it in [39m[30;42m+1 week[39;49m[34m (Cause: The Entity is a clone of [39m[30;42Entity2[39;49m[34m).[39m
[34m[>] New Job for [39m[30;42mEntity[39;49m[34m created. [39m
...
Run Code Online (Sandbox Code Playgroud)
如您所见,输出几乎不可读。
在将其保存到数据库之前,如何从中删除所有格式?
我正在建立一个入门程序.它非常简单:只需一个电子邮件字段和一个提交按钮.
程序如何工作
我只有一个带有两种方法的控制器:indexAction()
而endAction()
indexAction只是使用注释设置路径并以手工形式显示树枝模板:
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
class GetStartedController extends Controller
{
/**
* @Route("getstarted")
* @Template()
*/
public function indexAction()
{
return array(
// ...
);
}
/**
* @Route("getstarted/end", name="getStartedEnd")
* @Template()
*/
public function endAction(Request $request)
{
// ... other code
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,目前该方法确实无效,因为表单是直接在树枝模板中手工制作的.
以下是呈现表单的代码(在twig模板中手工制作):
{% extends "::base.html.twig" %}
{% block title %}AppBundle:GetStarted:index{% endblock %}
{% block body %}
<form id="getStarted" action="{{ path('getStartedEnd') }}" method="post">
<div class="form-group">
<input type="email" …
Run Code Online (Sandbox Code Playgroud) php ×7
symfony ×4
oauth ×2
composer-php ×1
console ×1
curl ×1
debugging ×1
doctrine-orm ×1
embeddable ×1
forms ×1
guzzle ×1
phpunit ×1
satis ×1
travis-ci ×1
unit-testing ×1
webforms ×1