Author: ts
Date: Thu Sep 20 13:24:54 2007
New Revision: 6218
Log:
- Finished refactoring of PathFactory.
Modified:
trunk/Webdav/src/options/transport.php
trunk/Webdav/src/path_factory.php
trunk/Webdav/src/transport.php
trunk/Webdav/tests/client_test.php
trunk/Webdav/tests/client_test_cadaver.php
trunk/Webdav/tests/client_test_rfc.php
trunk/Webdav/tests/transport_options_test.php
Modified: trunk/Webdav/src/options/transport.php
==============================================================================
--- trunk/Webdav/src/options/transport.php [iso-8859-1] (original)
+++ trunk/Webdav/src/options/transport.php [iso-8859-1] Thu Sep 20 13:24:54 2007
@@ -12,7 +12,8 @@
* Class containing the options for basic webdav server.
*
* @property ezcWebdavPathFactory $pathFactory
- * Class used to transform real paths into request paths.
+ * Class used to transform real paths into request paths. Standard is
+ * ezcWebdavAutomaticPathFactory.
*
* @package Webdav
* @version //autogen//
@@ -30,7 +31,7 @@
*/
public function __construct( array $options = array() )
{
- $this->properties['pathFactory'] = new ezcWebdavPathFactory();
+ $this->properties['pathFactory'] = new ezcWebdavAutomaticPathFactory();
parent::__construct( $options );
}
Modified: trunk/Webdav/src/path_factory.php
==============================================================================
--- trunk/Webdav/src/path_factory.php [iso-8859-1] (original)
+++ trunk/Webdav/src/path_factory.php [iso-8859-1] Thu Sep 20 13:24:54 2007
@@ -33,6 +33,15 @@
*/
protected $baseUriParts;
+ /**
+ * Creates a new path factory.
+ * Creates a new object to parse URIs to local pathes. The URL given as a
+ * parameter is used to strip URL/path parts from incoming URIs and add the
+ * specific parts to outgoin ones.
+ *
+ * @param string $baseUri
+ * @return void
+ */
public function __construct( $baseUri = '' )
{
$this->baseUriParts = parse_url( $baseUri );
@@ -51,8 +60,11 @@
public function parseUriToPath( $uri )
{
$requestPath = parse_url( $uri, PHP_URL_PATH );
-
- return substr( $requestPath, strlen( $this->baseUriParts['path'] ) );
+ if ( substr( $requestPath, -1, 1 ) === '/' )
+ {
+ $requestPath = substr( $requestPath, 0, -1 );
+ }
+ return substr( $requestPath, isset( $this->baseUriParts['path'] ) ?
strlen( $this->baseUriParts['path'] ) : 0 );
}
/**
Modified: trunk/Webdav/src/transport.php
==============================================================================
--- trunk/Webdav/src/transport.php [iso-8859-1] (original)
+++ trunk/Webdav/src/transport.php [iso-8859-1] Thu Sep 20 13:24:54 2007
@@ -64,24 +64,26 @@
public function parseRequest( $uri )
{
$body = $this->retreiveBody();
+ $path = $this->options->pathFactory->parseUriToPath( $uri );
+
switch ( $_SERVER['REQUEST_METHOD'] )
{
case 'PROPFIND':
- return $this->parsePropFindRequest( $uri, $body );
+ return $this->parsePropFindRequest( $path, $body );
case 'PROPPATCH':
- return $this->parsePropPatchRequest( $uri, $body );
+ return $this->parsePropPatchRequest( $path, $body );
case 'COPY':
- return $this->parseCopyRequest( $uri, $body );
+ return $this->parseCopyRequest( $path, $body );
case 'MOVE':
- return $this->parseMoveRequest( $uri, $body );
+ return $this->parseMoveRequest( $path, $body );
case 'DELETE':
- return $this->parseDeleteRequest( $uri, $body );
+ return $this->parseDeleteRequest( $path, $body );
case 'LOCK':
- return $this->parseLockRequest( $uri, $body );
+ return $this->parseLockRequest( $path, $body );
case 'UNLOCK':
- return $this->parseUnlockRequest( $uri, $body );
+ return $this->parseUnlockRequest( $path, $body );
case 'MKCOL':
- return $this->parseMakeCollectionRequest( $uri, $body );
+ return $this->parseMakeCollectionRequest( $path, $body );
default:
throw new ezcWebdavInvalidRequestMethodException(
$_SERVER['REQUEST_METHOD']
@@ -195,21 +197,21 @@
/**
* Parses the COPY request and returns a request object.
* This method is responsible for parsing the COPY request. It
- * retrieves the current request URI in $uri and the request body as $body.
+ * retrieves the current request URI in $path and the request body as
$body.
* The return value, if no exception is thrown, is a valid [EMAIL
PROTECTED]
* ezcWebdavCopyRequest} object.
*
- * @param string $uri
+ * @param string $path
* @param string $body
* @return ezcWebdavCopyRequest
*/
- protected function parseCopyRequest( $uri, $body )
+ protected function parseCopyRequest( $path, $body )
{
$headers = $this->parseHeaders(
array( 'Destination', 'Depth', 'Overwrite' )
);
- $request = new ezcWebdavCopyRequest( $uri, $headers['Destination'] );
+ $request = new ezcWebdavCopyRequest( $path, $headers['Destination'] );
$request->setHeaders( $headers );
@@ -243,21 +245,21 @@
/**
* Parses the MOVE request and returns a request object.
* This method is responsible for parsing the MOVE request. It
- * retrieves the current request URI in $uri and the request body as $body.
+ * retrieves the current request URI in $path and the request body as
$body.
* The return value, if no exception is thrown, is a valid [EMAIL
PROTECTED]
* ezcWebdavMoveRequest} object.
*
- * @param string $uri
+ * @param string $path
* @param string $body
* @return ezcWebdavMoveRequest
*/
- protected function parseMoveRequest( $uri, $body )
+ protected function parseMoveRequest( $path, $body )
{
$headers = $this->parseHeaders(
array( 'Destination', 'Depth', 'Overwrite' )
);
- $request = new ezcWebdavMoveRequest( $uri, $headers['Destination'] );
+ $request = new ezcWebdavMoveRequest( $path, $headers['Destination'] );
$request->setHeaders( $headers );
@@ -329,17 +331,17 @@
/**
* Parses the DELETE request and returns a request object.
* This method is responsible for parsing the DELETE request. It
- * retrieves the current request URI in $uri and the request body as $body.
+ * retrieves the current request URI in $path and the request body as
$body.
* The return value, if no exception is thrown, is a valid [EMAIL
PROTECTED]
* ezcWebdavDeleteRequest} object.
*
- * @param string $uri
+ * @param string $path
* @param string $body
* @return ezcWebdavDeleteRequest
*/
- protected function parseDeleteRequest( $uri, $body )
- {
- return new ezcWebdavDeleteRequest( $uri );
+ protected function parseDeleteRequest( $path, $body )
+ {
+ return new ezcWebdavDeleteRequest( $path );
}
// LOCK
@@ -347,17 +349,17 @@
/**
* Parses the LOCK request and returns a request object.
* This method is responsible for parsing the LOCK request. It
- * retrieves the current request URI in $uri and the request body as $body.
+ * retrieves the current request URI in $path and the request body as
$body.
* The return value, if no exception is thrown, is a valid [EMAIL
PROTECTED]
* ezcWebdavLockRequest} object.
*
- * @param string $uri
+ * @param string $path
* @param string $body
* @return ezcWebdavLockRequest
*/
- protected function parseLockRequest( $uri, $body )
- {
- $request = new ezcWebdavLockRequest( $uri );
+ protected function parseLockRequest( $path, $body )
+ {
+ $request = new ezcWebdavLockRequest( $path );
$request->setHeaders(
$this->parseHeaders(
@@ -426,17 +428,17 @@
/**
* Parses the UNLOCK request and returns a request object.
* This method is responsible for parsing the UNLOCK request. It
- * retrieves the current request URI in $uri and the request body as $body.
+ * retrieves the current request URI in $path and the request body as
$body.
* The return value, if no exception is thrown, is a valid [EMAIL
PROTECTED]
* ezcWebdavUnlockRequest} object.
*
- * @param string $uri
+ * @param string $path
* @param string $body
* @return ezcWebdavUnlockRequest
*/
- protected function parseUnlockRequest( $uri, $body )
- {
- $request = new ezcWebdavUnlockRequest( $uri );
+ protected function parseUnlockRequest( $path, $body )
+ {
+ $request = new ezcWebdavUnlockRequest( $path );
$request->setHeaders(
$this->parseHeaders(
@@ -452,17 +454,17 @@
/**
* Parses the MKCOL request and returns a request object.
* This method is responsible for parsing the MKCOL request. It
- * retrieves the current request URI in $uri and the request body as $body.
+ * retrieves the current request URI in $path and the request body as
$body.
* The return value, if no exception is thrown, is a valid [EMAIL
PROTECTED]
* ezcWebdavMakeCollectionRequest} object.
*
- * @param string $uri
+ * @param string $path
* @param string $body
* @return ezcWebdavMakeCollectionRequest
*/
- protected function parseMakeCollectionRequest( $uri, $body )
- {
- return new ezcWebdavMakeCollectionRequest( $uri, ( trim( $body ) ===
'' ? null : $body ) );
+ protected function parseMakeCollectionRequest( $path, $body )
+ {
+ return new ezcWebdavMakeCollectionRequest( $path, ( trim( $body ) ===
'' ? null : $body ) );
}
// PROPFIND
@@ -470,17 +472,17 @@
/**
* Parses the PROPFIND request and returns a request object.
* This method is responsible for parsing the PROPFIND request. It
- * retrieves the current request URI in $uri and the request body as $body.
+ * retrieves the current request URI in $path and the request body as
$body.
* The return value, if no exception is thrown, is a valid [EMAIL
PROTECTED]
* ezcWebdavPropFindRequest} object.
*
- * @param string $uri
+ * @param string $path
* @param string $body
* @return ezcWebdavPropFindRequest
*/
- protected function parsePropFindRequest( $uri, $body )
- {
- $request = new ezcWebdavPropFindRequest( $uri );
+ protected function parsePropFindRequest( $path, $body )
+ {
+ $request = new ezcWebdavPropFindRequest( $path );
$request->setHeaders(
$this->parseHeaders(
@@ -752,17 +754,17 @@
/**
* Parses the PROPPATCH request and returns a request object.
* This method is responsible for parsing the PROPPATCH request. It
- * retrieves the current request URI in $uri and the request body as $body.
+ * retrieves the current request URI in $path and the request body as
$body.
* The return value, if no exception is thrown, is a valid [EMAIL
PROTECTED]
* ezcWebdavPropPatchRequest} object.
*
- * @param string $uri
+ * @param string $path
* @param string $body
* @return ezcWebdavPropPatchRequest
*/
- protected function parsePropPatchRequest( $uri, $body )
- {
- $request = new ezcWebdavPropPatchRequest( $uri );
+ protected function parsePropPatchRequest( $path, $body )
+ {
+ $request = new ezcWebdavPropPatchRequest( $path );
if ( ( $dom = $this->loadDom( $body ) ) === false )
{
@@ -843,12 +845,13 @@
}
/**
- * Offer access to some of the server properties.
- *
+ * Property read access.
+ *
+ * @param string $propertyName Name of the property.
+ * @return mixed Value of the property or null.
+ *
* @throws ezcBasePropertyNotFoundException
- * If the property $propertyName is not defined
- * @param string $propertyName
- * @return mixed
+ * If the the desired property is not found.
* @ignore
*/
public function __get( $propertyName )
@@ -862,14 +865,15 @@
}
/**
- * Sets the option $propertyName to $propertyValue.
+ * Property write access.
+ *
+ * @param string $propertyName Name of the property.
+ * @param mixed $propertyValue The value for the property.
*
* @throws ezcBasePropertyNotFoundException
- * if the property $propertyName is not defined
+ * If a the value for the property options is not an instance of
* @throws ezcBaseValueException
- * if $propertyValue is not correct for the property $propertyName
- * @param string $propertyName
- * @param mixed $propertyValue
+ * If a the value for a property is out of range.
* @ignore
*/
public function __set( $propertyName, $propertyValue )
@@ -889,6 +893,13 @@
$this->properties[$propertyName] = $propertyValue;
}
+ /**
+ * Property isset access.
+ *
+ * @param string $propertyName Name of the property.
+ * @return bool True is the property is set, otherwise false.
+ * @ignore
+ */
public function __isset( $propertyName )
{
return array_key_exists( $propertyName, $this->properties );
Modified: trunk/Webdav/tests/client_test.php
==============================================================================
--- trunk/Webdav/tests/client_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/client_test.php [iso-8859-1] Thu Sep 20 13:24:54 2007
@@ -5,7 +5,7 @@
protected $dataDir;
- protected $transportClass;
+ protected $transport;
protected $setupClass;
@@ -19,7 +19,7 @@
* Needs to set different options.
* [EMAIL PROTECTED] $this->dataDir} needs to be set to the base path of
* Webdav/tests/clients/<clientname>
- * [EMAIL PROTECTED] $this->transportClass} needs to be set to the
transport class to
+ * [EMAIL PROTECTED] $this->transport} needs to be set to the transport to
* use, e.g. [EMAIL PROTECTED] ezcWebdavTransportTestMock} for a RFC
compliant test.
*
* @return void
@@ -78,7 +78,6 @@
$request['uri'] = $this->getFileContent( $requestDir, 'uri' );
$requestObject = $this->runRequestTest( $request );
-
}
// Response test
@@ -135,17 +134,10 @@
$_SERVER = ( $request['server'] !== false ? $request['server'] :
$_SERVER );
// Optionally set an URI different from 'http://localhost/webdav.php'
- $uri = ( $request['uri'] !== false
- ? call_user_func( array( $this->pathFactory, 'parsePath' ),
$request['uri'] )
- : '/webdav.php'
- );
-
- // Setup test environment
- $transportClass = $this->transportClass;
- $transport = new $transportClass();
-
+ $uri = ( $request['uri'] !== false ? $request['uri'] : '/webdav.php' );
+
// Begin request test
- $result = $transport->parseRequest( $uri );
+ $result = $this->transport->parseRequest( $uri );
if ( $request['result'] === false )
{
Modified: trunk/Webdav/tests/client_test_cadaver.php
==============================================================================
--- trunk/Webdav/tests/client_test_cadaver.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/client_test_cadaver.php [iso-8859-1] Thu Sep 20 13:24:54
2007
@@ -9,7 +9,10 @@
{
protected function setupTestEnvironment()
{
- $this->transportClass = 'ezcWebdavTransportTestMock';
+ $this->transport = new ezcWebdavTransportTestMock();
+ $this->transport->options->pathFactory = new ezcWebdavPathFactory(
+ 'http://foo.bar'
+ );
$this->dataDir = dirname( __FILE__ ) . '/clients/cadaver';
}
Modified: trunk/Webdav/tests/client_test_rfc.php
==============================================================================
--- trunk/Webdav/tests/client_test_rfc.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/client_test_rfc.php [iso-8859-1] Thu Sep 20 13:24:54 2007
@@ -11,10 +11,12 @@
{
protected function setupTestEnvironment()
{
- $this->transportClass = 'ezcWebdavTransportTestMock';
- $this->dataDir = dirname( __FILE__ ) . '/clients/rfc';
- $this->setupClass = 'ezcWebdavClientRfcTestBackend';
- $this->pathFactory = 'ezcWebdavRfcPathFactory';
+ $this->transport = new ezcWebdavTransportTestMock();
+ $this->transport->options->pathFactory = new ezcWebdavPathFactory(
+ 'http://foo.bar'
+ );
+ $this->dataDir = dirname( __FILE__ ) . '/clients/rfc';
+ $this->setupClass = 'ezcWebdavClientRfcTestBackend';
}
public static function suite()
Modified: trunk/Webdav/tests/transport_options_test.php
==============================================================================
--- trunk/Webdav/tests/transport_options_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/transport_options_test.php [iso-8859-1] Thu Sep 20
13:24:54 2007
@@ -15,7 +15,7 @@
require_once 'test_case.php';
/**
- * Tests for ezcWebdavPathFactory class.
+ * Tests for ezcWebdavAutomaticPathFactory class.
*
* @package Webdav
* @subpackage Tests
@@ -54,7 +54,7 @@
$this->assertEquals(
$transport->options->pathFactory,
- new ezcWebdavPathFactory()
+ new ezcWebdavAutomaticPathFactory()
);
$transport->options->pathFactory = new ezcWebdavAutomaticPathFactory();
@@ -105,11 +105,11 @@
$options = new ezcWebdavTransportOptions();
$this->assertEquals(
- new ezcWebdavPathFactory(),
+ new ezcWebdavAutomaticPathFactory(),
$options->pathFactory
);
- $mockedPathFactory = $this->getMock( 'ezcWebdavPathFactory' );
+ $mockedPathFactory = $this->getMock( 'ezcWebdavAutomaticPathFactory' );
$options->pathFactory = $mockedPathFactory;
$this->assertSame(
--
svn-components mailing list
[EMAIL PROTECTED]
http://lists.ez.no/mailman/listinfo/svn-components