Skip to content

1.3 Implement the User Class

jpkoontz edited this page Nov 15, 2013 · 3 revisions

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 Security Context

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 Exceptions

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.

View full list of exceptions

Continue to 1.4 Testing the User Class

Clone this wiki locally