Skip to content

Instantly share code, notes, and snippets.

@spiroski
Last active February 28, 2016 21:59
Show Gist options
  • Save spiroski/4596529745d2c4777009 to your computer and use it in GitHub Desktop.
Save spiroski/4596529745d2c4777009 to your computer and use it in GitHub Desktop.
<?php
class User
{
private $id;
private $firstName;
private $lastName;
private $email;
private $password;
public function __construct(UserId $id, Name $name, Email $email, Password $password, Roles $roles)
{
// ....
}
// Getters and private setters where I map the VOs ...
public function verifyCredentials(Credentials $credentials)
{
// Logic for verifying email and password
}
}
class Course
{
private $id;
private $title;
public function __construct(Course $id, $title)
{
// ...
}
}
class SchoolClass
{
private $id;
private $course;
private $professor;
private $students;
public function __construct(SchoolClassId $id, Course $course, Professor $professor, ArrayCollection $students)
{
...
}
}
// This is the part I'm asking about
class Student
{
// This is some property that doesn't belong to User, only to Student
// Which makes me think Student is an entity
private $hasScholarship = false;
public function __construct(UserID $userId, ArrayCollection $enrolledClasses)
{
// ...
}
public function name()
{
// How would i return $user->name() here ?
}
}
// Now let's say we already handled login
class DashboardController
{
private $authenticationService;
public function index()
{
$authenticatedUser = $this->authenticationService->getUser();
if ($authenticatedUser->inRole('student')) {
// Problematic part as well
// How to create student object? Factory? just create it here?
return view('dashboard.student.index')->with('student', $student);
} else if ($authenticatedUser->inRole('professor')) {
// create a proffesor object ( same problem is applied as with Student, but let's focus on Student
return view('dashboard.professor.index')->with('professor', $professor);
}
}
public function myClasses()
{
$authenticatedUser = $this->authenticationService->getUser();
// Create $student somehow
$classes = $student->classes();
return view('dasboard.student.myclasses')->with('classes', $classes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment