I am trying to write a library for Phalcon 4.x and use it as ODM but I have reached a point where I get the following error when trying to append a message after a save error: Fatal error: Uncaught TypeError: Return value of ApiLibrariesMongoDBAModel::appendMessage() must implement interface Phalcon MvcModelInterface. When I implement the ModelInterface I get a white screen with no errors.
<?php
namespace MyappApiLibrariesMongoDBA;
use MongoDBClient;
use MongoDBBSONObjectId;
use MongoDBBSONPersistable;
use MongoDBBSONUnserializable;
use PhalconDi;
use PhalconConfig;
use PhalconMessagesMessage;
use PhalconDbAdapterAdapterInterface;
use PhalconMvcModelInterface;
use PhalconMvcModelCriteriaInterface;
use PhalconMvcModelMetaDataInterface;
use PhalconMvcModelResultsetInterface;
class Model implements Unserializable, Persistable, ModelInterface {
/**
* @var ObjectId
*/
protected $_id;
/**
* @var Client
*/
protected static $db;
/**
* @var String
*/
protected static $model;
/**
* @var String
*/
protected static $source;
/**
* @var Config
*/
protected static $config;
public function __construct(){
self::$db = Di::getDefault()->getShared('mongodba');
$this->getConfig()->setModel()->initialize();
}
/**
* @return $this
*/
private function getConfig(){
self::$config = Di::getDefault()->getShared('config')->mongodb;
return $this;
}
/**
* @return $this
*/
private function setModel(){
self::$model = get_called_class();
return $this;
}
/**
* @return MongoDBCollection
*/
protected static function getCollection(){
return self::$db->selectCollection(self::$config->get('database'), self::$source);
}
/**
* String representation of object
* @link https://php.net/manual/en/serializable.serialize.php
* @return string the string representation of the object or null
*/
public function serialize(){
// TODO: Implement serialize() method.
}
/**
* Constructs the object
* @link https://php.net/manual/en/serializable.unserialize.php
* @param string $serialized <p>
* The string representation of the object.
* </p>
* @return void
*/
public function unserialize($serialized){
// TODO: Implement unserialize() method.
}/**
* Reads an attribute value by its name
* @param string $attribute
* @return mixed|null
*/
public function readAttribute(string $attribute){
// TODO: Implement readAttribute() method.
}
/**
* Writes an attribute value by its name
* @param string $attribute
* @param mixed $value
*/
public function writeAttribute(string $attribute, $value){
// TODO: Implement writeAttribute() method.
}
/**
* Appends a customized message on the validation process
* @param PhalconMessagesMessageInterface $message
* @return ModelInterface
*/
public function appendMessage(PhalconMessagesMessageInterface $message): ModelInterface{
// TODO: Implement appendMessage() method.
}
/**
* Assigns values to a model from an array
* @param array $columnMap
* @param array $data
* @param mixed $whiteList
* @param mixed $dataColumnMap
* @return ModelInterface
*/
public function assign(array $data, $whiteList = null, $dataColumnMap = null): ModelInterface{
// TODO: Implement assign() method.
}
/**
* Allows to calculate the average value on a column matching the specified
* conditions
* @param array $parameters
* @return double | ResultsetInterface
*/
public static function average($parameters = null){
// TODO: Implement average() method.
}
/**
* Assigns values to a model from an array returning a new model
* @param ModelInterface $base
* @param array $data
* @param int $dirtyState
* @return ModelInterface
*/
public static function cloneResult(ModelInterface $base, array $data, int $dirtyState = 0): ModelInterface{
// TODO: Implement cloneResult() method.
}
/**
* Assigns values to a model from an array returning a new model
* @param PhalconMvcModel $base
* @param array $columnMap
* @param array $data
* @param int $dirtyState
* @param bool $keepSnapshots
* @return PhalconMvcModel result
*/
public static function cloneResultMap($base, array $data, $columnMap, int $dirtyState = 0, bool $keepSnapshots = null): ModelInterface{
// TODO: Implement cloneResultMap() method.
}
/**
* Returns an hydrated result based on the data and the column map
* @param array $columnMap
* @param array $data
* @param int $hydrationMode
*/
public static function cloneResultMapHydrate(array $data, $columnMap, int $hydrationMode){
// TODO: Implement cloneResultMapHydrate() method.
}
/**
* Allows to count how many records match the specified conditions
* Returns an integer for simple queries or a ResultsetInterface
* instance for when the GROUP condition is used. The results will
* contain the count of each group.
* @param array $parameters
* @return int|PhalconMvcModelResultsetInterface
*/
public static function count($parameters = null){
// TODO: Implement count() method.
}
/**
* Inserts a model instance. If the instance already exists in the
* persistence it will throw an exception. Returning true on success or
* false otherwise.
* @return bool
*/
public function create(): bool{
// TODO: Implement create() method.
}
/**
* Deletes a model instance. Returning true on success or false otherwise.
* @return bool
*/
public function delete(): bool{
// TODO: Implement delete() method.
}
/**
* Allows to query a set of records that match the specified conditions
* @param mixed $parameters
* @return ResultsetInterface
*/
public static function find($parameters = null): ResultsetInterface{
// TODO: Implement find() method.
}
/**
* Allows to query the first record that match the specified conditions
* @param array|null $parameters
* @return ModelInterface|null
*/
public static function findFirst(? array $parameters = null): ?ModelInterface{
}
/**
* Fires an event, implicitly calls behaviors and listeners in the events
* manager are notified
* @param string $eventName
* @return bool
*/
public function fireEvent(string $eventName): bool{
// TODO: Implement fireEvent() method.
}
/**
* Fires an event, implicitly calls behaviors and listeners in the events
* manager are notified. This method stops if one of the callbacks/listeners
* returns bool false
* @param string $eventName
* @return bool
*/
public function fireEventCancel(string $eventName): bool{
// TODO: Implement fireEventCancel() method.
}
/**
* Returns one of the DIRTY_STATE_ constants telling if the record exists
* in the database or not
* @return int
*/
public function getDirtyState(): int{
// TODO: Implement getDirtyState() method.
}
/**
* Returns array of validation messages
* @return array|PhalconMessagesMessageInterface[]
*/
public function getMessages(): array{
// TODO: Implement getMessages() method.
}
/**
* Returns the models meta-data service related to the entity instance.
* @return MetaDataInterface
*/
public function getModelsMetaData(): MetaDataInterface{
// TODO: Implement getModelsMetaData() method.
}
/**
* Returns the type of the latest operation performed by the ORM
* Returns one of the OP_ class constants
* @return int
*/
public function getOperationMade(): int{
// TODO: Implement getOperationMade() method.
}
/**
* Gets internal database connection
* @return AdapterInterface
*/
public function getReadConnection(): AdapterInterface{
// TODO: Implement getReadConnection() method.
}
/**
* Returns DependencyInjection connection service used to read data
* @return string
*/
public function getReadConnectionService(): string{
// TODO: Implement getReadConnectionService() method.
}
/**
* Returns related records based on defined relations
* @param array $arguments
* @param string $alias
* @return PhalconMvcModelResultsetSimple|PhalconMvcModelResultsetSimple|false
*/
public function getRelated(string $alias, $arguments = null){
// TODO: Implement getRelated() method.
}
/**
* Returns schema name where table mapped is located
* @return string
*/
public function getSchema(): string{
// TODO: Implement getSchema() method.
}
/**
* Returns table name mapped in the model
* @return string
*/
public function getSource(): string{
// TODO: Implement getSource() method.
}
/**
* Gets internal database connection
* @return AdapterInterface
*/
public function getWriteConnection(): AdapterInterface {
// TODO: Implement getWriteConnection() method.
}
/**
* Returns DependencyInjection connection service used to write data
* @return string
*/
public function getWriteConnectionService(): string{
// TODO: Implement getWriteConnectionService() method.
}
/**
* Allows to get the maximum value of a column that match the specified
* conditions
* @param array $parameters
* @return mixed
*/
public static function maximum($parameters = null){
// TODO: Implement maximum() method.
}
/**
* Allows to get the minimum value of a column that match the specified
* conditions
* @param array $parameters
* @return mixed
*/
public static function minimum($parameters = null){
// TODO: Implement minimum() method.
}
/**
* Create a criteria for a specific model
* @param PhalconDiDiInterface $container
* @return CriteriaInterface
*/
public static function query(PhalconDiDiInterface $container = null): CriteriaInterface{
// TODO: Implement query() method.
}
/**
* Refreshes the model attributes re-querying the record from the database
* @return ModelInterface
*/
public function refresh(): ModelInterface{
// TODO: Implement refresh() method.
}
/**
* Inserts or updates a model instance. Returning true on success or false
* otherwise.
* @return bool
*/
public function save(): bool{
if(!is_null($this->_id)){
$output = $this->update();
}else{
$output = self::getCollection()->insertOne($this);
if($output->getInsertedCount() > 0){
$this->appendMessage(new Message('Inserted count was 0', self::$source, self::$model));
return false;
}
}
}
/**
* Sets both read/write connection services
* @param string $connectionService
*
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…