Skip to content

Commit

Permalink
[AMF] Migrated AMF to namespaces
Browse files Browse the repository at this point in the history
- Two tests failing, likely due to name changes; will need to consult with Wade
  • Loading branch information
weierophinney committed Apr 20, 2010
1 parent b9d201a commit 1e24493
Show file tree
Hide file tree
Showing 154 changed files with 2,706 additions and 6,354 deletions.
2 changes: 1 addition & 1 deletion README-DEV.txt
Expand Up @@ -60,7 +60,7 @@ THE FOLLOWING IN ANY ORDER (except where indicated):
[ ] Zend_Soap
[X] Zend_Tag
[ ] Zend_Service_*
[X] Zend_Session -> [X] Zend_Auth -> [ ] Zend_Amf -> [ ] Zend_Serializer
[X] Zend_Session -> [X] Zend_Auth -> [X] Zend_Amf -> [ ] Zend_Serializer

Fifth pass:
All together:
Expand Down
58 changes: 35 additions & 23 deletions library/Zend/Amf/Adobe/Auth.php → library/Zend/AMF/Adobe/Authentication.php 100755 → 100644
Expand Up @@ -19,25 +19,32 @@
* @version $Id$
*/

/**
* @namespace
*/
namespace Zend\AMF\Adobe;

use Zend\Authentication;

/**
* This class implements authentication against XML file with roles for Flex Builder.
*
* @uses Zend_Acl
* @uses Zend_Amf_Auth_Abstract
* @uses Zend_Auth_Result
* @uses Zend_Auth_Adapter_Exception
* @uses \Zend\Acl\Acl
* @uses \Zend\AMF\Authentication\AbstractAuthentication
* @uses \Zend\Authentication\Result
* @uses \Zend\Authentication\Adapter\Exception
* @package Zend_Amf
* @subpackage Adobe
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Adobe_Auth extends Zend_Amf_Auth_Abstract
class Authentication extends \Zend\AMF\Authentication\AbstractAuthentication
{

/**
* ACL for authorization
*
* @var Zend_Acl
* @var \Zend\Acl\Acl
*/
protected $_acl;

Expand All @@ -55,7 +62,7 @@ class Zend_Amf_Adobe_Auth extends Zend_Amf_Auth_Abstract
*/
public function __construct($rolefile)
{
$this->_acl = new Zend_Acl();
$this->_acl = new \Zend\Acl\Acl();
$xml = simplexml_load_file($rolefile);
/*
Roles file format:
Expand All @@ -69,18 +76,20 @@ public function __construct($rolefile)
</roles>
*/
foreach($xml->role as $role) {
$this->_acl->addRole(new Zend_Acl_Role((string)$role["id"]));
$this->_acl->addRole(new \Zend\Acl\Role\GenericRole((string)$role["id"]));
foreach($role->user as $user) {
$this->_users[(string)$user["name"]] = array("password" => (string)$user["password"],
"role" => (string)$role["id"]);
$this->_users[(string)$user['name']] = array(
'password' => (string)$user['password'],
'role' => (string)$role['id']
);
}
}
}

/**
* Get ACL with roles from XML file
*
* @return Zend_Acl
* @return \Zend\Acl\Acl
*/
public function getAcl()
{
Expand All @@ -90,35 +99,38 @@ public function getAcl()
/**
* Perform authentication
*
* @throws Zend_Auth_Adapter_Exception
* @return Zend_Auth_Result
* @see Zend_Auth_Adapter_Interface#authenticate()
* @return Zend\Authentication\Result
* @throws Zend\Authentication\Adapter\Exception
*/
public function authenticate()
{
if (empty($this->_username) ||
empty($this->_password)) {
throw new Zend_Auth_Adapter_Exception('Username/password should be set');
if (empty($this->_username)
|| empty($this->_password)
) {
throw new Authentication\Adapter\Exception('Username/password should be set');
}

if(!isset($this->_users[$this->_username])) {
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND,
if (!isset($this->_users[$this->_username])) {
return new Authentication\Result(
Authentication\Result::FAILURE_IDENTITY_NOT_FOUND,
null,
array('Username not found')
);
);
}

$user = $this->_users[$this->_username];
if($user["password"] != $this->_password) {
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
return new Authentication\Result(
Authentication\Result::FAILURE_CREDENTIAL_INVALID,
null,
array('Authentication failed')
);
);
}

$id = new stdClass();
$id = new \stdClass();
$id->role = $user["role"];
$id->name = $this->_username;
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $id);
return new Authentication\Result(Authentication\Result::SUCCESS, $id);
}
}
38 changes: 21 additions & 17 deletions library/Zend/Amf/Adobe/DbInspector.php → library/Zend/AMF/Adobe/DbInspector.php 100755 → 100644
Expand Up @@ -19,6 +19,11 @@
* @version $Id$
*/

/**
* @namespace
*/
namespace Zend\AMF\Adobe;

/**
* This class implements authentication against XML file with roles for Flex Builder.
*
Expand All @@ -27,23 +32,22 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Adobe_DbInspector
class DbInspector
{

/**
* Connect to the database
*
* @param string $dbType Database adapter type for Zend_Db
* @param array|object $dbDescription Adapter-specific connection settings
* @see Zend_Db::factory()
* @param string $dbType Database adapter type for Zend_Db
* @param array|object $dbDescription Adapter-specific connection settings
* @return Zend_Db_Adapter_Abstract
* @see Zend_Db::factory()
*/
protected function _connect($dbType, $dbDescription)
{
if(is_object($dbDescription)) {
if (is_object($dbDescription)) {
$dbDescription = get_object_vars($dbDescription);
}
return Zend_Db::factory($dbType, $dbDescription);
return \Zend_Db::factory($dbType, $dbDescription);
}

/**
Expand All @@ -60,12 +64,12 @@ protected function _connect($dbType, $dbDescription)
* 'mytable'
* );
*
* @param string $dbType Database adapter type for Zend_Db
* @param array|object $dbDescription Adapter-specific connection settings
* @param string $tableName Table name
* @see Zend_Db::describeTable()
* @see Zend_Db::factory()
* @param string $dbType Database adapter type for Zend_Db
* @param array|object $dbDescription Adapter-specific connection settings
* @param string $tableName Table name
* @return array Table description
* @see Zend_Db::describeTable()
* @see Zend_Db::factory()
*/
public function describeTable($dbType, $dbDescription, $tableName)
{
Expand All @@ -76,10 +80,10 @@ public function describeTable($dbType, $dbDescription, $tableName)
/**
* Test database connection
*
* @param string $dbType Database adapter type for Zend_Db
* @param array|object $dbDescription Adapter-specific connection settings
* @see Zend_Db::factory()
* @param string $dbType Database adapter type for Zend_Db
* @param array|object $dbDescription Adapter-specific connection settings
* @return bool
* @see Zend_Db::factory()
*/
public function connect($dbType, $dbDescription)
{
Expand All @@ -91,8 +95,8 @@ public function connect($dbType, $dbDescription)
/**
* Get the list of database tables
*
* @param string $dbType Database adapter type for Zend_Db
* @param array|object $dbDescription Adapter-specific connection settings
* @param string $dbType Database adapter type for Zend_Db
* @param array|object $dbDescription Adapter-specific connection settings
* @return array List of the tables
*/
public function getTables($dbType, $dbDescription)
Expand Down
43 changes: 24 additions & 19 deletions library/Zend/Amf/Adobe/Introspector.php → library/Zend/AMF/Adobe/Introspector.php 100755 → 100644
Expand Up @@ -19,19 +19,24 @@
* @version $Id$
*/

/**
* @namespace
*/
namespace Zend\AMF\Adobe;

/**
* This class implements a service for generating AMF service descriptions as XML.
*
* @uses Zend_Amf_Parse_TypeLoader
* @uses Zend_Loader
* @uses Zend_Reflection_Class
* @uses Zend_Server_Reflection
* @uses Zend\AMF\Parser\TypeLoader
* @uses Zend\Loader
* @uses Zend\Reflection\ReflectionClass
* @uses Zend\Server\Reflection\Reflection
* @package Zend_Amf
* @subpackage Adobe
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Adobe_Introspector
class Introspector
{
/**
* Options used:
Expand Down Expand Up @@ -64,7 +69,7 @@ class Zend_Amf_Adobe_Introspector
*/
public function __construct()
{
$this->_xml = new DOMDocument('1.0', 'utf-8');
$this->_xml = new \DOMDocument('1.0', 'utf-8');
}

/**
Expand All @@ -82,12 +87,12 @@ public function introspect($serviceClass, $options = array())
return $this->_returnError('Invalid service name');
}

// Transform com.foo.Bar into com_foo_Bar
$serviceClass = str_replace('.' , '_', $serviceClass);
// Transform com.foo.Bar into com\foo\Bar
$serviceClass = str_replace('.' , '\\', $serviceClass);

// Introspect!
if (!class_exists($serviceClass)) {
Zend_Loader::loadClass($serviceClass, $this->_getServicePath());
\Zend\Loader::loadClass($serviceClass, $this->_getServicePath());
}

$serv = $this->_xml->createElement('service-description');
Expand All @@ -96,7 +101,7 @@ public function introspect($serviceClass, $options = array())
$this->_types = $this->_xml->createElement('types');
$this->_ops = $this->_xml->createElement('operations');

$r = Zend_Server_Reflection::reflectClass($serviceClass);
$r = \Zend\Server\Reflection\Reflection::reflectClass($serviceClass);
$this->_addService($r, $this->_ops);

$serv->appendChild($this->_types);
Expand All @@ -109,10 +114,10 @@ public function introspect($serviceClass, $options = array())
/**
* Authentication handler
*
* @param Zend_Acl $acl
* @param \Zend\Acl\Acl $acl
* @return unknown_type
*/
public function initAcl(Zend_Acl $acl)
public function initAcl(\Zend\Acl\Acl $acl)
{
return false; // we do not need auth for this class
}
Expand All @@ -124,15 +129,15 @@ public function initAcl(Zend_Acl $acl)
* @param DOMElement $typexml target XML element
* @return void
*/
protected function _addClassAttributes($typename, DOMElement $typexml)
protected function _addClassAttributes($typename, \DOMElement $typexml)
{
// Do not try to autoload here because _phpTypeToAS should
// have already attempted to load this class
if (!class_exists($typename, false)) {
return;
}

$rc = new Zend_Reflection_Class($typename);
$rc = new \Zend\Reflection\ReflectionClass($typename);
foreach ($rc->getProperties() as $prop) {
if (!$prop->isPublic()) {
continue;
Expand All @@ -151,11 +156,11 @@ protected function _addClassAttributes($typename, DOMElement $typexml)
/**
* Build XML service description from reflection class
*
* @param Zend_Server_Reflection_Class $refclass
* @param \Zend\Server\Reflection\ReflectionClass $refclass
* @param DOMElement $target target XML element
* @return void
*/
protected function _addService(Zend_Server_Reflection_Class $refclass, DOMElement $target)
protected function _addService(\Zend\Server\Reflection\ReflectionClass $refclass, \DOMElement $target)
{
foreach ($refclass->getMethods() as $method) {
if (!$method->isPublic()
Expand Down Expand Up @@ -199,10 +204,10 @@ protected function _addService(Zend_Server_Reflection_Class $refclass, DOMElemen
/**
* Extract type of the property from DocBlock
*
* @param Zend_Reflection_Property $prop reflection property object
* @param \Zend\Reflection\ReflectionProperty $prop reflection property object
* @return string Property type
*/
protected function _getPropertyType(Zend_Reflection_Property $prop)
protected function _getPropertyType(\Zend\Reflection\ReflectionProperty $prop)
{
$docBlock = $prop->getDocComment();

Expand Down Expand Up @@ -252,7 +257,7 @@ protected function _phpTypeToAS($typename)
}
}

if (false !== ($asname = Zend_Amf_Parse_TypeLoader::getMappedClassName($typename))) {
if (false !== ($asname = \Zend\AMF\Parser\TypeLoader::getMappedClassName($typename))) {
return $asname;
}

Expand Down
12 changes: 9 additions & 3 deletions library/Zend/Amf/Auth/Abstract.php → ...Authentication/AbstractAuthentication.php 100755 → 100644
Expand Up @@ -19,21 +19,27 @@
* @version $Id$
*/

/**
* @namespace
*/
namespace Zend\AMF\Authentication;

/**
* Base abstract class for AMF authentication implementation
*
* @uses Zend_Auth_Adapter_Interface
* @uses \Zend\Authentication\Adapter
* @package Zend_Amf
* @subpackage Auth
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Amf_Auth_Abstract implements Zend_Auth_Adapter_Interface
abstract class AbstractAuthentication implements \Zend\Authentication\Adapter
{
protected $_username;
protected $_password;

public function setCredentials($username, $password) {
public function setCredentials($username, $password)
{
$this->_username = $username;
$this->_password = $password;
}
Expand Down

0 comments on commit 1e24493

Please sign in to comment.