0

I am new to this architecture. So I have a database table class file with table attributes with getter and setter which extends an abstract class I have DAO file on same location which extends another abstract class. Above two classes are inside a same directory and comes under same namespace.

When I am trying to create instance of table class inside DAO class, it is throwing error as 'Class not found'.

Following is the code snapshot - ` <?php //Database table class Task.php

namespace TestingNamespace;

use Coeus\Core\Domain\AbstractAuditableDomainObject;
use Coeus\Core\Domain\toArray;
use Coeus\Core\Reflection\Reflect;

class Task extends AbstractAuditableDomainObject
{
    //<all getter and setters> code here
}

?>

`<?php

namespace TestingNamespace;

use Coeus\Core\Domain\AbstractDAO;
use Coeus\Core\Domain\DAOConstraintException;
use PDO;
use DateTime;
use PDOException;
use PDOStatement;
use InvalidArgumentException;
use Coeus\Core\Security\IActor;
use Coeus\Core\Domain\DAOException;
use Coeus\Core\Date\DateTimeFormat;
use Coeus\Core\Domain\DAOFindException;
use Coeus\Core\Domain\AbstractDomainObject;
use Coeus\Core\Domain\AbstractContainerAwareDAO;
use TestingNamespace\Task;

class TaskDAO extends AbstractContainerAwareDAO
{   
    public function findAll( )
    {
        $sql = '
            SELECT *
            FROM v3_task
        ';
        $tasks = [];
        try {
            $stmt = $this->pdo->query($sql);
            $tasks = $this->mapRowsToDomainObjects($stmt);
        } catch (PDOException $e) {
            throw new DAOException($e->getMessage(), (int)$e->getCode(), $e);
        } finally {
            if (isset($stmt) && $stmt instanceof PDOStatement) {
                $stmt->closeCursor();
                unset($stmt);
            }
        }
        var_dump($tasks);
        return $tasks;
    }
    
    protected function mapRowsToDomainObjects(PDOStatement $stmt, $associative = false)
    {
        $tasks = [];

        $completedBy = '';
        $completedDate = null;

        if (($aRow = $stmt->fetch(PDO::FETCH_ASSOC)) === false) {
            throw new DAOFindException();
        }
        do {
            $task = new Task();
            $task->setId($aRow['id']);
            $task->setName($aRow['name']);
            $task->setDescription($aRow['description']);
            $task->setShortCode($aRow['short_code']);
            $task->setIsActive($aRow['is_active']);
            $task->setCreateDate(
                    DateTime::createFromFormat(
                            DateTimeFormat::PERSIST_DATE_AND_TIME, $aRow['create_date']));
            $task->setCreateUser($aRow['create_user']);
            $task->setUpdateDate(
                    DateTime::createFromFormat(
                            DateTimeFormat::PERSIST_DATE_AND_TIME, $aRow['update_date']));
            $task->setUpdateUser($aRow['update_user']);

            if ($associative) {
                $tasks[$task->getId()] = $task;
            } else {
                $tasks[] = $task;
            }
        } while (($aRow = $stmt->fetch(PDO::FETCH_ASSOC)) !== false);

        return $tasks;
    }    
}

?>`

In second class on the line of - $task = new Task(); I am getting error that 'Class Task not found'

I am stuck in this from yesterday and I need to write endpoints accordingly, can anyone please help with this

0 Answers0