我正在构建一个非常依赖第三方API的站点,所以我认为将API包装器打包为服务是有意义的,但是我开始找到访问它的实例.在控制器之外,例如在实体存储库中.与此相关的是能够访问控制器之外的配置值(例如在实体存储库中)也是有用的.
任何人都可以告诉我,如果这是可能的,如果没有,是否有建议的方法来做这种事情?
谢谢你的帮助
我正在尝试设置单元测试,但每当我运行"phpunit -c app"时,我都会收到此错误:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:您已请求不存在的服务"test.client".
我的测试用例中的代码只是:
public function testNonAuthenticatedPathsIndex()
{
$client = $this->createClient();
}
Run Code Online (Sandbox Code Playgroud)
如果我没有调用createClient,一切都正常运行.我已经检查过AppKernel.php以确保FrameworkBundle(我相信这个服务定义的位置)肯定仍在那里,它确实存在.
我有点困惑,因为我之前已经设法做了这件事.
谢谢你的帮助.
我正在制作一个活动网站,并且在制作和表演之间有一对多的关系,当我有一个表演对象时,如果我需要它的制作ID,那么我必须做的事情
$productionId = $performance->getProduction()->getId();
Run Code Online (Sandbox Code Playgroud)
在我确实只需要生产ID的情况下,发送另一个数据库查询来获取已经存在于某个对象中的值似乎是浪费.这有什么方法吗?
我一直在阅读Symfony2文档中的内部章节,它说如果我在kernel.controller事件中添加一个监听器,我可以交换运行的控制器,我有一些有点像这样的东西:
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
$replacementControllerName = .... //Some logic to work out the name of the new controller
$replacementController = ?? //Not sure what goes here
$event->setController($replacementController);
}
Run Code Online (Sandbox Code Playgroud)
我不确定是否曾经找到替换控制器的名称,我如何得到一个可以传递给setController的实例?
我刚刚为应用程序商店批准了一个Phonegap/Cordova iPhone应用程序,但发现它声称可以使用其他语言,包括Northern Sami.我在本地化下找到了xcode中的语言列表,并尝试删除它们但是如果我重新启动xcode它们会重新出现.
我也尝试删除资源文件夹中的lproj文件夹,但这也无济于事.
我不知道下一步该做什么,所以任何帮助都会非常感激.
我一直在关注这个指南(并通过作曲家安装了所有内容):http://docs.behat.org/cookbook/behat_and_mink.html我试图让Behat + Mink工作,但每次我尝试运行bin/behat我得到以下错误:
PHP Fatal error: Call to a member function getSession() on a non-object in vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php on line 80
Run Code Online (Sandbox Code Playgroud)
那行代码是:
return $this->getMink()->getSession($name);
Run Code Online (Sandbox Code Playgroud)
所以由于某种原因,mink属性是空的,但我不知道为什么.
我的.feature文件与指南中的文件完全相同,FeatureContext类也来自指南:
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
/**
* Features context.
*/
class FeatureContext extends MinkContext
{
}
Run Code Online (Sandbox Code Playgroud)
我的供应商/ behat/mink/behat.yml文件包含:
context:
extensions:
Behat\MinkExtension\Extension:
base_url: 'http://en.wikipedia.org/'
goutte: ~
selenium2: ~
Run Code Online (Sandbox Code Playgroud)
我也试过让我的类扩展BehatContext,然后调用useContext,但这给了我同样的错误.Behat本身似乎工作它只是Mink产生致命错误的任何东西,我不知道如何解决它.
我正在为SOAP服务编写PHP包装器并使用类映射选项,因此我可以使用对象而不是数组.这很有效,直到SOAP服务的提供者决定向他们的一个对象添加一个新属性(他们似乎喜欢这样做而不告诉任何人),此时SOAP客户端打破了错误,SOAP-ERROR: Encoding: object has no 'NewlyAddedProperty' property
因为现在wsdl中有一个属性.那不在课堂上.
我试图通过使用魔法getter并返回类似的东西来解决它false
,null
但由于它们根据wsdl不是有效值,它仍然会引发致命错误.
在理想的世界中,即使没有在类上定义属性,客户端也只会在对象上设置新属性,这可能吗?如果不仅仅是抑制错误也没关系.
我有一个使用通过第三方API检索的选项构建的预订表单,并且由于需要具有最新信息,因此API的结果无法缓存(至少不会很长时间).
我遇到的问题是我注意到表单提交时Drupal正在重新调用我的_form函数,它再次触发API调用,我想停止这样做以尝试减少API调用的次数这是制作的.
显然,如果验证失败,则需要重新绘制表单,并且需要再次进行API调用,但我想知道是否有办法在表单验证时阻止它执行此操作,因此我可以阻止它进行大量不必要的操作调用API.
谢谢你的帮助.
我的网站正在使用第三方服务进行身份验证以及其他功能,因此我设置了一项服务,为我执行所有API调用,这是我需要能够访问用户对象的服务.我已经尝试将security.context服务注入到我的API服务中,但是我收到了ServiceCircularReferenceException,因为我的用户身份验证提供程序引用了API服务(它必须为了对用户进行身份验证).所以我得到一个链
security.context -> authentication provider ->
user provider -> API service -> security.context
Run Code Online (Sandbox Code Playgroud)
我正在努力获得另一种获取用户对象的方式,我看不出任何明显的方式来分割这个链.
我的配置都在config.yml中定义,这里是相关的位
myapp.database:
class: Pogo\MyAppBundle\Service\DatabaseService
arguments:
siteid: %siteid%
entityManager: "@doctrine.orm.entity_manager"
myapp.apiservice:
class: Pogo\MyAppBundle\Service\TicketingService
arguments:
entityManager: "@myapp.database"
myapp.user_provider:
class: Pogo\MyAppBundle\Service\APIUserProvider
arguments:
entityManager: "@myapp.database"
ticketingAdapter: "@myapp.apiservice"
securityContext: "@security.context"
myapp.authenticationprovider:
class: Pogo\MyAppBundle\Service\APIAuthenticationProvider
arguments:
userChecker: "@security.user_checker"
encoderFactory: "@security.encoder_factory"
userProvider: "@myapp.user_provider"
Run Code Online (Sandbox Code Playgroud)
myapp.user_provider是我在security.yml中定义为我的用户提供者服务的服务,我认为它是由security.context引用的.
我无法让身份验证工作,但它似乎只在非常具体的情况下发生.身份验证是通过第三方API完成的,所以我编写了自己的用户提供程序类,在该类中有一些代码可以同步API和Symfony之间的数据,作为同步过程的一部分,它决定了用户应该拥有哪些角色.执行此操作后,它通过ManyToMany关系设置角色和用户之间的关系.
我的User对象中的getRoles()方法从数据库中获取角色对象,并将其转换为字符串数组,角色名称来自我的数据库,所有角色名称都以ROLE_开头.
如果我使用不应该有额外角色的帐户登录,它可以正常工作,但是如果我登录到应该有角色的帐户,我只会被发送回登录屏幕而没有错误消息.
我检查了日志并看到了这些条目:
security.INFO: User "test105@example.com" has been authenticated successfully [] []
event.DEBUG: Notified event "security.interactive_login" to listener "Pogo\MyBundle\Listener\LoginListener::onSecurityInteractivelogin". [] []
event.DEBUG: Listener "Symfony\Component\Security\Http\Firewall::onKernelRequest" stopped propagation of the event "kernel.request". [] []
event.DEBUG: Listener "Symfony\Bundle\FrameworkBundle\EventListener\RouterListener" was not called for event "kernel.request". [] []
event.DEBUG: Listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener" was not called for event "kernel.request". [] []
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\Firewall\ContextListener::onKernelResponse". [] []
security.DEBUG: Write SecurityContext in the session [] []
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] …
Run Code Online (Sandbox Code Playgroud) 我正在尝试(并且失败)了解spray-json如何将json提要转换为对象.如果我有一个简单的键 - >值json feed然后它似乎工作正常但我想要读取的数据出现在这样的列表中:
[{
"name": "John",
"age": "30"
},
{
"name": "Tom",
"age": "25"
}]
Run Code Online (Sandbox Code Playgroud)
我的代码看起来像这样:
package jsontest
import spray.json._
import DefaultJsonProtocol._
object JsonFun {
case class Person(name: String, age: String)
case class FriendList(items: List[Person])
object FriendsProtocol extends DefaultJsonProtocol {
implicit val personFormat = jsonFormat2(Person)
implicit val friendListFormat = jsonFormat1(FriendList)
}
def main(args: Array[String]): Unit = {
import FriendsProtocol._
val input = scala.io.Source.fromFile("test.json")("UTF-8").mkString.parseJson
val friendList = input.convertTo[FriendList]
println(friendList)
}
}
Run Code Online (Sandbox Code Playgroud)
如果我更改我的测试文件,所以它只有一个人不在数组中运行val friendList = input.convertTo[Person]
然后它工作,一切都解析但是一旦我尝试解析一个数组它失败并出现错误Object expected in …
有没有人知道是否可以让一个包使用注释阅读器来读取非Doctrine对象的新自定义注释?到目前为止,我所看到的一切都是为了控制器或以某种方式扩展Doctrine.
我希望能做的是这样的:
class MyTestClass {
/**
* @MyBundleName\Foo
*/
public $foo_var;
/**
* @MyBundleName\Bar
*/
public $bar_var;
}
Run Code Online (Sandbox Code Playgroud)
然后有一些代码,当给定一个实例时MyTestClass
可以解决哪个注释应用于哪个属性.