-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Labels
Description
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]);
}
Reactions are currently unavailable