Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jackalope/jackalope
Browse files Browse the repository at this point in the history
  • Loading branch information
rndstr committed Oct 18, 2010
2 parents 0b02af6 + e0a48d9 commit bc8f55a
Show file tree
Hide file tree
Showing 47 changed files with 867 additions and 702 deletions.
9 changes: 6 additions & 3 deletions api-test/bootstrap.php
Expand Up @@ -37,7 +37,7 @@ function getRepository($config) {
return false;
}
if ($config['transport'] != 'davex') throw new Exception("Don't know how to handle transport other than davex. (".$config['transport'].')');
return new jackalope_Repository($config['url'], null); //let jackalope factory create the transport
return new \jackalope\Repository($config['url'], null); //let jackalope factory create the transport
}

/**
Expand Down Expand Up @@ -66,9 +66,11 @@ function getJCRSession($config, $credentials = null) {
}
return $repository->login($credentials, $config['workspace']);
} elseif (isset($config['workspace'])) {
return $repository->login(null, $config['workspace']);
throw new PHPCR_RepositoryException(jackalope_baseCase::NOTSUPPORTEDLOGIN);
//return $repository->login(null, $config['workspace']);
} else {
return $repository->login(null, null);
throw new PHPCR_RepositoryException(jackalope_baseCase::NOTSUPPORTEDLOGIN);
//return $repository->login(null, null);
}
}
/** some constants */
Expand All @@ -88,3 +90,4 @@ function getJCRSession($config, $credentials = null) {
define('OPTION_QUERY_SQL_SUPPORTED', 'option.query.sql.supported');
define('QUERY_XPATH_POS_INDEX', 'query.xpath.pos.index');
define('QUERY_XPATH_DOC_ORDER', 'query.xpath.doc.order');

2 changes: 1 addition & 1 deletion api-test/suite
Submodule suite updated from bf62f9 to 7c25f9
15 changes: 10 additions & 5 deletions src/jackalope/Factory.php
@@ -1,13 +1,18 @@
<?php
namespace jackalope;

/**
* This factory is used to centralize the jackalope instantiations and make
* them easily replaceable with dummies for the unit and functional testing.
*
* It should be used in the commands like that:
* jackalope_Factory::get('Node', array(...));
* Factory::get('Node', array(...));
* Factory::get('NodeType\PropertyDefinition', array(...));
* //note the \ for sub namespaces. the name is relative to the jackalope namespace
*
* The result will be an object from jackalope with the given named params.
*/
class jackalope_Factory {
class Factory {
/**
* Factory
*
Expand All @@ -16,13 +21,13 @@ class jackalope_Factory {
* @return jackalope
*/
public static function get($name, $params = array()) {
if (class_exists('jackalope_' . $name)) {
$name = 'jackalope_' . $name;
if (class_exists('\jackalope\\' . $name)) {
$name = '\jackalope\\' . $name;
}
if (count($params) == 0) {
return new $name;
} else {
$class = new ReflectionClass($name);
$class = new \ReflectionClass($name);
return $class->newInstanceArgs($params);
}
}
Expand Down
20 changes: 15 additions & 5 deletions src/jackalope/Helper.php
@@ -1,13 +1,19 @@
<?php
namespace jackalope;

class jackalope_Helper {
use \DOMElement;

/** Implementation Class:
* static helper functions to do some commonly used dom and path operations
*/
class Helper {
/**
* Returns an attribute casted to boolean
* @param DOMElement node to fetch from
* @param string attribute to fetch
* @return bool the value converted to bool
*/
public static function getBoolAttribute($node, $attribute) {
public static function getBoolAttribute(DOMElement $node, $attribute) {
if ('false' === $node->getAttribute($attribute)) {
return false;
} else {
Expand All @@ -16,6 +22,8 @@ public static function getBoolAttribute($node, $attribute) {
}

/**
* Check if the path is an absolute path or not.
*
* @param string $path The path to check
* @return bool TRUE if path is absolute otherwise FALSE
*/
Expand All @@ -25,13 +33,15 @@ public static function isAbsolutePath($path) {

/**
* Whether the path conforms to the JCR Specs (see paragraph 3.2)
*
*
* TODO: only minimal check performed atm, not full specs
* TODO: what do we need this for in the frontend? i think the backend will
* check and scream if path is not well
*
* @param string $path THe path to validate
* @return bool TRUE if valid otherwise FALSE
*/
*/
public static function isValidPath($path) {
return (strpos($path, '//') === false && preg_match('/^[\w{}\/#:^+~*\[\]\.-]*$/i', $path));
}

}
31 changes: 19 additions & 12 deletions src/jackalope/Item.php
@@ -1,5 +1,12 @@
<?php
class jackalope_Item implements PHPCR_ItemInterface {
namespace jackalope;

/**
* The Item is the base interface of Node and Property.
* This class implements methods for both types.
* It should not be instantiated directly.
*/
class Item implements \PHPCR_ItemInterface {

/** session this node belongs to */
protected $session;
Expand All @@ -21,12 +28,12 @@ class jackalope_Item implements PHPCR_ItemInterface {
/**
* @param stdClass $rawData
* @param string $path The normalized and absolute path to this item
* @param jackalope_Session $session
* @param jackalope_ObjectManager $objectManager
* @param Session $session
* @param ObjectManager $objectManager
* @param boolean $new can be set to true to tell the object that it has been created locally
*/
public function __construct($rawData, $path, jackalope_Session $session,
jackalope_ObjectManager $objectManager, $new = false) {
public function __construct($rawData, $path, Session $session,
ObjectManager $objectManager, $new = false) {
$this->path = $path;
$this->session = $session;
$this->objectManager = $objectManager;
Expand Down Expand Up @@ -84,7 +91,7 @@ public function getName() {
*/
public function getAncestor($depth) {
if ($depth < 0 || $depth > $this->depth) {
throw new PHPCR_ItemNotFoundException('Depth must be between 0 and '.$this->depth.' for this Item');
throw new \PHPCR_ItemNotFoundException('Depth must be between 0 and '.$this->depth.' for this Item');
}
if ($depth == $this->depth) {
return $this;
Expand Down Expand Up @@ -213,19 +220,19 @@ public function isModified() {
* @throws PHPCR_RepositoryException if an error occurs.
* @api
*/
public function isSame(PHPCR_ItemInterface $otherItem) {
public function isSame(\PHPCR_ItemInterface $otherItem) {
if ($this === $otherItem) { // trivial case
return true;
}
if ($this->session->getRepository() === $otherItem->getSession()->getRepository() &&
$this->session->getWorkspace() === $otherItem->getSession()->getWorkspace() &&
get_class($this) == get_class($otherItem)) {

if ($this instanceof jackalope_Node) {
if ($this instanceof Node) {
if ($this->uuid == $otherItem->getIdentifier()) {
return true;
}
} else { // assert($this instanceof jackalope_Property)
} else { // assert($this instanceof Property)
if ($this->name == $otherItem->getName() &&
$this->getParent()->isSame($otherItem->getParent())) {
return true;
Expand All @@ -243,8 +250,8 @@ public function isSame(PHPCR_ItemInterface $otherItem) {
* @throws PHPCR_RepositoryException if an error occurs.
* @api
*/
public function accept(PHPCR_ItemVisitorInterface $visitor) {
throw new jackalope_NotImplementedException();
public function accept(\PHPCR_ItemVisitorInterface $visitor) {
throw new NotImplementedException();
}

/**
Expand All @@ -268,7 +275,7 @@ public function accept(PHPCR_ItemVisitorInterface $visitor) {
* @api
*/
public function refresh($keepChanges) {
throw new jackalope_NotImplementedException('Write');
throw new NotImplementedException('Write');
}

/**
Expand Down
20 changes: 11 additions & 9 deletions src/jackalope/NamespaceRegistry.php
@@ -1,8 +1,10 @@
<?php
namespace jackalope;

/**
* Mirrors namespaces with jackarabbit backend
*/
class jackalope_NamespaceRegistry implements PHPCR_NamespaceRegistryInterface {
class NamespaceRegistry implements \PHPCR_NamespaceRegistryInterface {
protected $transport;

protected $defaultNamespaces = array(
Expand All @@ -14,7 +16,7 @@ class jackalope_NamespaceRegistry implements PHPCR_NamespaceRegistryInterface {
);
protected $userNamespaces = array();

public function __construct(jackalope_TransportInterface $transport) {
public function __construct(TransportInterface $transport) {
$this->transport = $transport;
$namespaces = $transport->getNamespaces();
foreach($namespaces as $prefix => $uri) {
Expand Down Expand Up @@ -56,7 +58,7 @@ public function __construct(jackalope_TransportInterface $transport) {
*/
public function registerNamespace($prefix, $uri) {
$this->checkPrefix($prefix);
throw new jackalope_NotImplementedException('Write');
throw new NotImplementedException('Write');
//first try putting the stuff in backend, and only afterwards update lokal info
//validation happens on the server, see second request trace below
/*
Expand Down Expand Up @@ -121,9 +123,9 @@ public function unregisterNamespace($prefix) {
$this->checkPrefix($prefix);
if (! array_key_exists($prefix, $this->userNamespaces)) {
//defaultNamespaces would throw an exception in checkPrefix already
throw new PHPCR_NamespaceException("Prefix $prefix is not currently registered");
throw new \PHPCR_NamespaceException("Prefix $prefix is not currently registered");
}
throw new jackalope_NotImplementedException('Write');
throw new NotImplementedException('Write');
}

/**
Expand Down Expand Up @@ -165,7 +167,7 @@ public function getURI($prefix) {
} else if (isset($this->userNamespaces[$prefix])) {
return $this->userNamespaces[$prefix];
}
throw new PHPCR_NamespaceException("Mapping for '$prefix' is not defined");
throw new \PHPCR_NamespaceException("Mapping for '$prefix' is not defined");
}

/**
Expand All @@ -181,7 +183,7 @@ public function getPrefix($uri) {
if ($prefix === false) {
array_search($uri, $this->userNamespaces);
if ($prefix === false) {
throw new PHPCR_NamespaceException("URI '$uri' is not defined in registry");
throw new \PHPCR_NamespaceException("URI '$uri' is not defined in registry");
}
}
return $prefix;
Expand All @@ -196,10 +198,10 @@ public function getPrefix($uri) {
*/
protected function checkPrefix($prefix) {
if (! strncasecmp('xml', $prefix, 3)) {
throw new PHPCR_NamespaceException('Do not use xml in prefixes for namespace changes');
throw new \PHPCR_NamespaceException('Do not use xml in prefixes for namespace changes');
}
if (array_key_exists($prefix, $this->defaultNamespaces)) {
throw new PHPCR_NamespaceException('Do not change the predefined prefixes');
throw new \PHPCR_NamespaceException('Do not change the predefined prefixes');
}
}
}

0 comments on commit bc8f55a

Please sign in to comment.