-
Notifications
You must be signed in to change notification settings - Fork 1
1.3 Implement the User Class
Go back to 1.2 Creating a Class Interface
Now that we have an interface for our User object, we can write the class that will implement the interface.
View lib/User.php
At this time our implementation is extremely simple. For now, our greet() method only returns the phrase "Welcome, visitor" (our equivalent of "Hello World!"). All other methods are implemented (since our interface forces an implementation) so we throw Cougar's NotImplementedException.
Notice also that the User class contains a constructor. It's purpose here is simple: receive a reference to a Cougar Security Context and store it in a protected property.
Cougar's Security Context glues the security components of the Cougar Framework together. The context allows us to authenticate using authentication providers, retrieve the authenticated identity and authorize the identity using one of the authorization providers. Later on we will use the Security Context to make security decisions, so we'll add it to the class from the start.
Cougar defines its own exceptions. They extend PHP's built-in Exception class and add a numeric HTTP Response code. By using the NotImplementedException Cougar will automatically know the exception should return an HTTP 501 return code.
Continue to 1.4 Testing the User Class