My method:
public function getUpdatedColumns(Shop $shop): array
{
$uow = $this->entityManager->getUnitOfWork();
$uow->computeChangeSets();
return $uow->getEntityChangeSet($shop);
}
What I get is this:
array(1) {
["mailConfig"]=>
array(2) {
[0]=>
string(25) "{"transport": "sendgrid"}"
[1]=>
string(24) "{"transport":"sendgrid"}"
}
}
and because of this whitespace, getEntityChangeSet returns result when the field is not actually updated. Is there a workaround when we are working with JSON ? The database field is JSON as well if that matters.
Related
I'm trying to use partials on an entity which contains a ManyToOne or OneToMany relation.
My DQL looks like this:
SELECT partial a.{created, updated} , partial b.{id, value, entity} FROM App\Entity\DataSetting a INNER JOIN a.fileEntityValues b
The problem is that "partial b" has a property called "entity" which is another field with relation defined like this.
/**
* #ORM\ManyToOne(targetEntity="App\Entity\FileEntity")
* #ORM\JoinColumn(name="file_entity_id", referencedColumnName="id")
*/
private $entity;
But when i execute the previous query I don't get errors but the "entity" field is just not displayed in the result:
[0]=>
array(9) {
["id"]=>
int(36)
["created"]=>
object(DateTime)#3022 (3) {
["date"]=>
string(26) "2020-12-31 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
["updated"]=>
object(DateTime)#3021 (3) {
["date"]=>
string(26) "2020-12-31 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
["fileEntityValues"]=>
array(4) {
[0]=>
array(2) {
["id"]=>
int(72)
["value"]=>
string(4) "1112"
// WHY entity field not displayed
}
[1]=>
array(2) {
["id"]=>
int(73)
["value"]=>
string(4) "1111"
}
WHY ?
#claudio how did you print the debug output?
see, if you used dump(), or var_dump(), fileEntityValues.entities should be an ArrayCollection()
I guess you dumped an object serialization, excluding in some way fileEntityValues.entity
can you:
paste how you printed the debug
paste both entities, or at least the constructors
paste the result of dump($entity)
hint: don't use partials, they are in some way discouraged also by Doctrine and can lead to incoherent behaviors
I'm trying to create a query using the LIKE clause in Doctrine Query Language.
My query is as following:
public function findByName($keyword){
$em = $this->getEntityManager();
$consulta = $em->createQuery('SELECT o FROM AppBundle:Items o WHERE o.name LIKE :keyword');
$consulta->setParameter('keyword', '%'.$keyword.'%');
return $consulta->getResult();
}
I'm getting the next errors:
Notice: Trying to access array offset on value of type null
While if I do the same query but instead of LIKE i simply use =, the query executes correctly and I get the results. What could I be doing wrong here?
Thanks for the help.
Debug info:
object(Doctrine\ORM\Query)#901 (24) {
["_state":"Doctrine\ORM\Query":private]=> int(2)
["_parsedTypes":"Doctrine\ORM\Query":private]=> array(0) { }
["_dql":"Doctrine\ORM\Query":private]=> string(57) "SELECT o FROM
AppBundle:Coche o WHERE o.modelo = :keyword"
["_parserResult":"Doctrine\ORM\Query":private]=> NULL
["_firstResult":"Doctrine\ORM\Query":private]=> NULL
["_maxResults":"Doctrine\ORM\Query":private]=> NULL
["_queryCache":"Doctrine\ORM\Query":private]=> NULL
["_expireQueryCache":"Doctrine\ORM\Query":private]=> bool(false)
["_queryCacheTTL":"Doctrine\ORM\Query":private]=> NULL
["_useQueryCache":"Doctrine\ORM\Query":private]=> bool(true)
["parameters":protected]=>
object(Doctrine\Common\Collections\ArrayCollection)#946 (1) {
["elements":"Doctrine\Common\Collections\ArrayCollection":private]=>
array(1) { [0]=> object(Doctrine\ORM\Query\Parameter)#913 (3) {
["name":"Doctrine\ORM\Query\Parameter":private]=> string(7) "keyword"
["value":"Doctrine\ORM\Query\Parameter":private]=> int(1)
["type":"Doctrine\ORM\Query\Parameter":private]=> string(7) "integer"
} } } ["_resultSetMapping":protected]=> NULL ["_em":protected]=>
object(Doctrine\ORM\EntityManager)#740 (11) {
["config":"Doctrine\ORM\EntityManager":private]=>
object(Doctrine\ORM\Configuration)#564 (1) {
["_attributes":protected]=> array(14) { ["entityNamespaces"]=>
array(1) { ["AppBundle"]=> string(16) "AppBundle\Entity" }
["metadataCacheImpl"]=> object(Doctrine\Common\Cache\ArrayCache)#566
(6) { ["data":"Doctrine\Common\Cache\ArrayCache":private]=> array(0) {
} ["hitsCount":"Doctrine\Common\Cache\ArrayCache":private]=> int(0)
["missesCount":"Doctrine\Common\Cache\ArrayCache":private]=> int(0)
["upTime":"Doctrine\Common\Cache\ArrayCache":private]=>
int(1598445780)
["namespace":"Doctrine\Common\Cache\CacheProvider":private]=>
string(79)
"sf_orm_default_061d80f6e71229c042b639f23634872f7045193d957ba060c640bf0458feeae2"
["namespaceVersion":"Doctrine\Common\Cache\CacheProvider":private]=>
NULL } ["queryCacheImpl"]=>
public function LikeExpression()
{
$stringExpr = $this->StringExpression();
$not = false;
if ($this->lexer->isNextToken(Lexer::T_NOT)) {
$this->match(Lexer::T_NOT);
$not = true;
}
$this->match(Lexer::T_LIKE);
if ($this->lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) {
$this->match(Lexer::T_INPUT_PARAMETER);
$stringPattern = new AST\InputParameter($this->lexer->token['value']);
} else {
$stringPattern = $this->StringPrimary();
}
$escapeChar = null;
//////// Highlighted error area//////////
if ($this->lexer->lookahead['type'] === Lexer::T_ESCAPE) {
$this->match(Lexer::T_ESCAPE);
$this->match(Lexer::T_STRING);
$escapeChar = new AST\Literal(AST\Literal::STRING, $this->lexer->token['value']);
}
////////////////////////////////////////
$likeExpr = new AST\LikeExpression($stringExpr, $stringPattern, $escapeChar);
$likeExpr->not = $not;
return $likeExpr;
}
Since PHP 7.1, they introduced const visibility, and I need to read it thorugh reflection. I went as far as creating my ReflectionClass like this:
$rc = new ReflectionClass(static::class);
The function getConstants() returns a name/value map and getConstant($name) just its value. Both doesn't return visibility information. Shouldn't there be a ReflectionConst class similarly to functions, properties, etc.?
Is there any other way to obtain this information?
Reflection changes for this are touched on in the feature's RFC, though I don't know if they've been documented elsewhere yet.
The new class is ReflectionClassConstant with relevant methods (among others):
isPublic()
isPrivate()
isProtected()
ReflectionClass has two new methods:
getReflectionConstants() - returns an array of ReflectionClassConstants
getReflectionConstant() - retrieves a ReflectionClassConstant by name
Example:
class Foo
{
private const BAR = 42;
}
$r = new ReflectionClass(Foo::class);
var_dump(
$r->getReflectionConstants(),
$r->getReflectionConstant('BAR')->isPrivate()
);
Outputs:
array(1) {
[0]=>
object(ReflectionClassConstant)#2 (2) {
["name"]=>
string(3) "BAR"
["class"]=>
string(3) "Foo"
}
}
bool(true)
I have a problem to get the orginal name of a file uploaded byoneupuploaderbundle
If i use
$this->getRequest()->files[0]->getClientOriginalName();
(See this post Get Uploaded File's Original Name )
I have this error :
FatalErrorException: Error: Cannot use object of
type Symfony\Component\HttpFoundation\FileBag as array in
/home/.../UploadListener.php
line 17
but i think is correct, see the var_dump :
$request = $event->getRequest();
var_dump($request->files);
give :
object(Symfony\Component\HttpFoundation\FileBag)#11 (1) {
["parameters":protected]=>
array(1) {
["file"]=>
array(1) {
[0]=>
object(Symfony\Component\HttpFoundation\File\UploadedFile)#12 (7) {
["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
bool(false)
["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
string(22) "silk_icons_preview.png"
["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
string(9) "image/png"
["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
int(116463)
["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
int(0)
["pathName":"SplFileInfo":private]=>
string(14) "/tmp/php3GUXwQ"
["fileName":"SplFileInfo":private]=>
string(9) "php3GUXwQ"
}
}
}
}
Thanks !
You have to do that :
$this->getRequest()->files->get('file')->getClientOriginalName();
The 'file' value is the name of your file input.
My function :
public function onUpload(PostPersistEvent $event) {
$test = $event->getRequest()->files->get('upload')->getClientOriginalName();
var_dump($test);
}
My form :
<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone" name="upload" type="file" method="post" id="doc"></form>
Do :
FatalErrorException: Error: Call to a member function
getClientOriginalName() on a non-object in
/home/www/.../UploadListener.php line 19
Running a test which has this line:
$authorizeForm = $crawler->selectButton('Authorize')->form();
outputs this error:
There was 1 error:
1) Citiqa\ApiBundle\Tests\Controller\SecurityControllerTest::testLoginAndAuthorize
InvalidArgumentException: The current node list is empty.
/home/oris/src/citiqa-api/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php:648
/home/oris/src/citiqa-api/src/Citiqa/ApiBundle/Tests/Controller/SecurityControllerTest.php:28
I've taken a look at Crawler.php and saw the problematic function:
public function form(array $values = null, $method = null)
{
//var_dump($this);
if (!count($this)) {
throw new \InvalidArgumentException('The current node list is empty.');
}
$form = new Form($this->getNode(0), $this->uri, $method);
if (null !== $values) {
$form->setValues($values);
}
return $form;
}
$this is in this case the crawler object which extends \SplObjectStorage which implements the Countable interface, so we should be fine. I've tried to var_dump($this); on form() and I see this:
object(Symfony\Component\DomCrawler\Crawler)#1354 (2) {
["uri":"Symfony\Component\DomCrawler\Crawler":private]=>
string(37) "https://localhost/oauth/v2/auth_login"
["storage":"SplObjectStorage":private]=>
array(1) {
["0000000075b694bd000000002b32afe0"]=>
array(2) {
["obj"]=>
object(DOMElement)#529 (18) {
["tagName"]=>
string(6) "button"
["schemaTypeInfo"]=>
NULL
["nodeName"]=>
string(6) "button"
["nodeValue"]=>
string(5) "login"
["nodeType"]=>
int(1)
["parentNode"]=>
string(22) "(object value omitted)"
["childNodes"]=>
string(22) "(object value omitted)"
["firstChild"]=>
string(22) "(object value omitted)"
["lastChild"]=>
string(22) "(object value omitted)"
["previousSibling"]=>
string(22) "(object value omitted)"
["nextSibling"]=>
string(22) "(object value omitted)"
["attributes"]=>
string(22) "(object value omitted)"
["ownerDocument"]=>
string(22) "(object value omitted)"
["namespaceURI"]=>
NULL
["prefix"]=>
string(0) ""
["localName"]=>
string(6) "button"
["baseURI"]=>
NULL
["textContent"]=>
string(5) "login"
}
["inf"]=>
NULL
}
}
}
object(Symfony\Component\DomCrawler\Crawler)#1852 (2) {
["uri":"Symfony\Component\DomCrawler\Crawler":private]=>
string(155) "https://localhost/oauth/v2/auth?client_id=1_5ndcb2XXXXX&redirect_uri=http%3A%2F%2Fwww.google.com&response_type=token"
["storage":"SplObjectStorage":private]=>
array(0) {
}
}
phpunit version is 3.6.10
Funny thing is, this test is completing successfully on another machine, with a different phpunit version (3.7.21). could this be a version / error reporting level issue?