我正在尝试围绕我公司正在开发的api编写一个包装器.它很安静,使用Postman我可以发送一个帖子请求到一个端点,比如http://subdomain.dev.myapi.com/api/v1/auth/
使用用户名和密码作为POST数据,我会收到一个令牌.一切都按预期工作.现在,当我尝试从PHP执行相同操作时,我会返回一个GuzzleHttp\Psr7\Response
对象,但似乎无法在其中的任何位置找到令牌,就像我对Postman请求所做的那样.
相关代码如下:
$client = new Client(['base_uri' => 'http://companysub.dev.myapi.com/']);
$response = $client->post('api/v1/auth/', [
'form_params' => [
'username' => $user,
'password' => $password
]
]);
var_dump($response); //or $resonse->getBody(), etc...
Run Code Online (Sandbox Code Playgroud)
上面代码的输出看起来像(警告,传入文本墙):
object(guzzlehttp\psr7\response)#36 (6) {
["reasonphrase":"guzzlehttp\psr7\response":private]=>
string(2) "ok"
["statuscode":"guzzlehttp\psr7\response":private]=>
int(200)
["headers":"guzzlehttp\psr7\response":private]=>
array(9) {
["connection"]=>
array(1) {
[0]=>
string(10) "keep-alive"
}
["server"]=>
array(1) {
[0]=>
string(15) "gunicorn/19.3.0"
}
["date"]=>
array(1) {
[0]=>
string(29) "sat, 30 may 2015 17:22:41 gmt"
}
["transfer-encoding"]=>
array(1) {
[0]=>
string(7) "chunked"
}
["content-type"]=>
array(1) {
[0]=> …
Run Code Online (Sandbox Code Playgroud) 假设我有一个类,有这样的方法:
/*
*
* Loads the user from username.
*
* @param string $username The username
*
* @return UserInterface
*
* @throws userNotFoundException if the user is not found
*/
public function getUser($username)
{
// someFunction return an UserInterface class if found, or null if not.
$user = someFunction('SELECT ....', $username);
if ($user === null) {
throw new userNotFoundException();
}
return $user
}
Run Code Online (Sandbox Code Playgroud)
现在让我们说someFunction
可以抛出InvalidArgumentException
/ RuntimeException
/ PDOException
出于XYZ的原因.我该怎么办?什么不是?
添加可能someFunction
在php-docs中引发的所有可能异常.
/*
* …
Run Code Online (Sandbox Code Playgroud) 我正试图找到设计模型中实体之间关系的最佳方法.我会试着清楚地解释一下.
想象一下以下的Doctrine2实体:
class ImageHistory
{
/**
* @var Image
*/
protected $current;
/**
* @var \Doctrine\Common\Collections\Collection
*/
protected $old;
}
class Dog
{
protected $name;
/**
* @var ImageHistory
*/
protected $imageHistory;
}
class Cat
{
protected $name;
/**
* @var ImageHistory
*/
protected $imageHistory;
}
Run Code Online (Sandbox Code Playgroud)
我想建立两个一对多的双向学说关系,Cat
并且Dog
是关系的拥有方.两个Cat
和Dog
类都有这个实体配置:
manyToOne:
imageHistory:
targetEntity: ImageHistory
joinColumn:
name: image_history_id
referencedColumnName: id
Run Code Online (Sandbox Code Playgroud)
如何表示te关系的另一面?
oneToMany:
owner:
targetEntity: <What can I write here?>
mappedBy: imageHistory
Run Code Online (Sandbox Code Playgroud)
我想象一个解决方案,其中Cat
和Dog
继承一个 …
<?php
namespace App\Model\Entity;
use Cake\ORM\Entity;
/**
* User Entity.
*/
class User extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
* Note that '*' is set to true, which allows all unspecified fields to be
* mass assigned. For security purposes, it is advised to set '*' to false
* (or remove), and explicitly make individual fields accessible as needed.
*
* @var array
*/
protected $_accessible = [
'*' => true,
'id' …
Run Code Online (Sandbox Code Playgroud) 我想将多个变量返回到我的视图中.
$currentUser = Auth::user();
$needToBePassed = "Lorem Ipsum"
View::share ( 'currentUser', $currentUser);
Run Code Online (Sandbox Code Playgroud)
这段代码工作正常,但如果我也想分享$needToBePassed
,我该怎么办?
重写它是一个好习惯吗?
View::share ( 'currentUser', $currentUser);
View::share ( 'needToBePassed', $needToBePassed);
Run Code Online (Sandbox Code Playgroud) 在symfony 2.3中,这是service.yml中的这一行来到翻译器
在service.yml
arguments: [@translator,....
Run Code Online (Sandbox Code Playgroud)
在serviceFunctions.php中
public function __construct(Translator $translator,...) {
$this->translator = $translator;
Run Code Online (Sandbox Code Playgroud)
现在我收到错误:
必须是Symfony\Component\Translation\Translator的实例,给出了Symfony\Component\Translation\DataCollectorTranslator的实例
如何在生产模式下使用2.7 in dev中的服务?
是的我知道.当我们使用multibyte char时,我们应该使用mb_*函数.但是当我们使用strpos时?我们来看看这段代码(保存在utf-8中)
var_dump(strpos("My symbol utf-8 is the €.", "\xE2\x82\xAC")); // int(23)
Run Code Online (Sandbox Code Playgroud)
使用mb_strpos有区别吗?是不是让这项工作成绩相同?毕竟,不是strpos寻找一个字符串(多个字节)?是否有理由使用strpos?
我只是想知道作曲家在检查需求时如何检查要使用哪个php。我使用MacOS,并且在终端类型中:
composer require phpunit/phpunit
Run Code Online (Sandbox Code Playgroud)
结果是这样的:
Problem 1
- phpunit/phpunit 5.0.4 requires php >=5.6 -> your PHP version (5.5.27) or "config.platform.php" value does not satisfy that requirement....
Run Code Online (Sandbox Code Playgroud)
当我检查php版本时:
php -v
Run Code Online (Sandbox Code Playgroud)
结果是:
PHP 5.6.10(cli)(内置:2015年6月12日14:08:56)版权所有(c)1997-2015 The PHP Group Zend Engine v2.6.0,版权所有(c)1998-2015 Zend Technologies with Xdebug v2.2.5, Derick Rethans版权所有(c)2002-2014
这是:
which php
Run Code Online (Sandbox Code Playgroud)
php:别名为/Applications/MAMP/bin/php/php5.6.10/bin/php
有人可以解释一下。提前致谢!
根据请求的格式,Symfony2返回相同类型的响应(html,css,json等).这非常明显.但是,如果我以定义的格式创建模板并在该上下文中执行转义字符,但最终页面以不同的格式呈现,那么生成输出会不会有危险吗?
示例:http://symfony.com/it/doc/current/book/index.html ? _ format = json
存在无意中创建可能包含危险输出/意外情况的资源的危险?这是故意的吗?为什么?
我在本地服务器上启用了SOAP.我的代码是:
ini_set('soap.wsdl_cache_enabled', '0');
ini_set('soap.wsdl_cache_ttl', '0');
$client = new SoapClient('web_url');
$session = $client->login('username', 'pwd');
$result = $client->call($session, 'function_name', '<id>');
print_r($result);
Run Code Online (Sandbox Code Playgroud)
在我在单独的php文件上运行代码时,它已成功执行.但我得到了这个错误:
错误:找不到类'App\Controller\SoapClient'
当我尝试运行CakePHP动作的代码时.
请建议我如何在CakePHP中使用SoapClient.
php ×8
cakephp-3.0 ×2
symfony ×2
blade ×1
composer-php ×1
doctrine-orm ×1
exception ×1
guzzle ×1
guzzle6 ×1
laravel ×1
macos ×1
oop ×1
phpdoc ×1
response ×1
soap ×1
soap-client ×1
strpos ×1
symfony-2.7 ×1
utf-8 ×1