Simple ejemlo seria:
Código PHP:
<?php
final class DB
{
/**
* @var array $config
*/
public $config = array();
/**
* void __construct ( array $config )
*
* @param array $config ______
* @return void
* @throw Exception
*/
public function __construct ( $config )
{
if( is_array($config) ) throw new Exception( "\$config must be array" );
// TO DO
}
public function query ( $query = null )
{
// TO DO
}
}
class users
{
/**
* @var object $db
*/
public $db = NULL;
/**
* void __construct ( array $config )
*
* @param array $config ______
* @return void
* @throw Exception
*/
public function __construct ( $config )
{
if( is_array($config) ) throw new Exception( "\$config must be array" );
$db = new DB ( $config );
}
public function isUser ( $username )
{
if ( $this->db == NULL ) throw new Exception ( "NO DB" );
if ( $this->db->query("SELECT username FROM users WHERE username = '" . $username . "' LIMIT 1") )
{
return true;
}
else
{
return false;
}
}
}
?>