We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi, I'm using "hayko/mongodb": "dev-master" via composer in my CakePHP 3.8.6 project.
When I do a find(), I get a error 500 dump, stating:
syntax error, unexpected 'elseif' (T_ELSEIF) ParseError Error in: ROOT\vendor\hayko\mongodb\src\ORM\Document.php, line 70
Upon inspecting the file, it appears a closing curly-brace for the if() statement is missing.
Original code:
public function cakefy() { $document = []; foreach ($this->_document as $field => $value) { $type = gettype($value); if ($type == 'object') { switch (get_class($value)) { case 'MongoDB\BSON\ObjectId': $document[$field] = $value->__toString(); break; case 'MongoDB\BSON\UTCDateTime': $document[$field] = $value->toDateTime(); break; default: if ($value instanceof \MongoDB\BSON\Serializable) { $document[$field] = $this->serializeObjects($value); } else { throw new Exception(get_class($value) . ' conversion not implemented.'); } // THERE NEEDS TO BE AN ADDITIONAL CURLY BRACE HERE } elseif ($type == 'array') { $document[$field] = $this->cakefy(); } else { $document[$field] = $value; } } $inflector = new \Cake\Utility\Inflector(); $entityName = '\\App\\Model\\Entity\\'.$inflector->singularize($this->_registryAlias); return new $entityName($document, ['markClean' => true, 'markNew' => false, 'source' => $this->_registryAlias]); }
If I modify the code and add in the curly brace, things get back to normal and the find() works:
public function cakefy() { $document = []; foreach ($this->_document as $field => $value) { $type = gettype($value); if ($type == 'object') { switch (get_class($value)) { case 'MongoDB\BSON\ObjectId': $document[$field] = $value->__toString(); break; case 'MongoDB\BSON\UTCDateTime': $document[$field] = $value->toDateTime(); break; default: if ($value instanceof \MongoDB\BSON\Serializable) { $document[$field] = $this->serializeObjects($value); } else { throw new Exception(get_class($value) . ' conversion not implemented.'); } } // ADDED CLOSING BRACE } elseif ($type == 'array') { $document[$field] = $this->cakefy(); } else { $document[$field] = $value; } } $inflector = new \Cake\Utility\Inflector(); $entityName = '\\App\\Model\\Entity\\'.$inflector->singularize($this->_registryAlias); return new $entityName($document, ['markClean' => true, 'markNew' => false, 'source' => $this->_registryAlias]); }
The text was updated successfully, but these errors were encountered:
Can you open a PR with these changes?
Sorry, something went wrong.
No branches or pull requests
Hi,
I'm using "hayko/mongodb": "dev-master" via composer in my CakePHP 3.8.6 project.
When I do a find(), I get a error 500 dump, stating:
Upon inspecting the file, it appears a closing curly-brace for the if() statement is missing.
Original code:
If I modify the code and add in the curly brace, things get back to normal and the find() works:
The text was updated successfully, but these errors were encountered: