Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #29 from kkamkou/collection-name-issue

Small corerctions in the String property - Thanks kkamkou
  • Loading branch information...
commit abd1e052ac1ac8070ac1be313b86f25d6fda13c3 2 parents 6a730ef + 4e7b205
Jonathan Moss authored
View
1  .gitignore
@@ -7,3 +7,4 @@ doc/api
doc/test_report
doc/integration_report
doc/manual/build/*
+/.idea/
View
67 src/morph/Object.php
@@ -37,8 +37,7 @@ class Object
protected $validators;
/**
- * @param string $id If supplied this will be the id used to reference this object
- * @return Morph_Object
+ * @param string $id If supplied this will be the id used to reference this object
*/
public function __construct($id = null)
{
@@ -92,8 +91,8 @@ public function state()
/**
* Adds a new property to this object
*
- * @param Morph_Property_Generic $property
- * @param string $alias
+ * @param \morph\property\Generic $property
+ * @param string $alias (Default: null)
* @return \morph\Object
*/
protected function addProperty(\morph\property\Generic $property, $alias = null)
@@ -108,9 +107,9 @@ protected function addProperty(\morph\property\Generic $property, $alias = null)
/**
* Sets the property data for this object
*
- * @param $data
- * @param $state
- * @return Morph_Object
+ * @param array $data
+ * @param string $state (Default: Enum::STATE_DIRTY)
+ * @return \morph\Object
*/
public function __setData(array $data, $state = Enum::STATE_DIRTY)
{
@@ -145,7 +144,7 @@ public function __getData()
}
return $data;
}
-
+
/**
* @return \morph\PropertSet
*/
@@ -159,7 +158,6 @@ public function __getPropertySet()
// ********************** //
/**
- *
* @param $propertyName
* @return mixed
*/
@@ -175,10 +173,9 @@ public function __get($propertyName)
}
/**
- *
- * @param $propertyName
- * @param $propertyValue
- * @return Morph_Object
+ * @param string $propertyName
+ * @param string $propertyValue
+ * @return \morph\Object
*/
public function __set($propertyName, $propertyValue)
{
@@ -191,6 +188,14 @@ public function __set($propertyName, $propertyValue)
return $this;
}
+ /**
+ * Clones the current object
+ */
+ public function __clone()
+ {
+ $this->id = null;
+ }
+
// ********************* //
// PERSISTANCE FUNCTIONS //
// ********************* //
@@ -198,8 +203,8 @@ public function __set($propertyName, $propertyValue)
/**
* Saves this object
*
- * @param array $options Support the same options as MongoCollection::save()
- * @return Morph_Object
+ * @param array $options Support the same options as MongoCollection::save()
+ * @return \morph\Object
*/
public function save(array $options = array())
{
@@ -222,7 +227,7 @@ public function loadById($id)
/**
* Fetch multiple objects by their ids
- *
+ *
* By default Morph sets the id to be an instance of MongoId(). When searching you need
* to ensure you do the same by wrapping your id string in a MongoId object
*
@@ -233,12 +238,12 @@ public function findByIds(array $ids)
{
return Storage::instance()->fetchByIds($this, $ids);
}
-
+
/**
* Find objects by query
*
- * @param Morph_IQuery $query
- * @return Morph_Iterator
+ * @param IQuery $query
+ * @return \morph\Iterator
*/
public function findByQuery(IQuery $query)
{
@@ -248,8 +253,8 @@ public function findByQuery(IQuery $query)
/**
* Finds one object by query
*
- * @param Morph_Query $query
- * @return Morph_Object
+ * @param IQuery $query
+ * @return Object
*/
public function findOneByQuery(IQuery $query)
{
@@ -257,8 +262,18 @@ public function findOneByQuery(IQuery $query)
}
/**
+ * Returns all entries for the current document
+ *
+ * @return \morph\Iterator
+ */
+ public function fetchAll()
+ {
+ return Storage::instance()->findByQuery($this);
+ }
+
+ /**
* Deletes this object from the database
- *
+ *
* @return boolean
*/
public function delete()
@@ -279,17 +294,17 @@ public function delete()
*/
public function __toString()
{
- // create the array that we will be encoding and returning
- // also put inside the array the mongodb ID and the 'state'
+ // create the array that we will be encoding and returning
+ // also put inside the array the mongodb ID and the 'state'
$data = array(
'Id' => $this->id(),
'State' => $this->state()
);
- // iterate through all the properties this object has and print them out
+ // iterate through all the properties this object has and print them out
foreach ($this->propertySet as $name => $property) {
$data[$name] = (string)$property;
- }
+ }
return \json_encode($data);
}
View
43 src/morph/Storage.php
@@ -23,7 +23,7 @@ class Storage
* @var MongoDB
*/
private $db;
-
+
private $useSafe = false;
/**
@@ -69,10 +69,10 @@ private function __construct(\MongoDB $db)
{
$this->db = $db;
}
-
+
/**
* If set to true then the 'safe' option for saves is used
- *
+ *
* @param boolean $useSafe
*/
public function useSafe($useSafe)
@@ -94,7 +94,7 @@ public function getDatabase()
/**
* Retrieves the contents of the specified $id
* and assigns them into $object
- *
+ *
* By default Morph sets the id to be an instance of MongoId(). When searching you need
* to ensure you do the same by wrapping your id string in a MongoId object
*
@@ -111,7 +111,7 @@ public function fetchById(Object $object, $id)
/**
* Returns all objects with an _id in $ids
- *
+ *
* By default Morph sets the id to be an instance of MongoId(). When searching you need
* to ensure you do the same by wrapping your id string in a MongoId object
*
@@ -129,7 +129,7 @@ public function fetchByIds(Object $object, array $ids)
/**
* Retrieves the contents of the specified $dbRef
* and assigns them into $object
- *
+ *
* @param Morph_Object $object
* @param array $dbRef
* @return Morph_Object
@@ -161,7 +161,7 @@ public function save(Object $object)
* Inserts a new object into the database
*
* @param \morph\Object $object
- * @param array $options
+ * @param array $options
* @return \morph\Object
*/
private function insert(Object $object, array $options = array())
@@ -175,9 +175,9 @@ private function insert(Object $object, array $options = array())
);
$data = \array_merge($id, $data);
}
-
+
$options = array_merge(array('safe'=>$this->useSafe), $options);
-
+
$savedOk = $this->db->selectCollection($object->collection())->save($data, $options);
if($savedOk){
$object->__setData($data, Enum::STATE_CLEAN);
@@ -211,18 +211,18 @@ public function delete(Object $object)
/**
* Runs query against the database
*
- * The results come packages up in a Morph_Iterator object
+ * The results come packages up in a \morph\Iterator object
*
- * @param \morph\Object $object Required to determine the correct collection query against
- * @param Morph_IQuery $query
- * @return Morph_Iterator
+ * @param Object $object Required to determine the correct collection query against
+ * @param IQuery $query
+ * @return \morph\Iterator
*/
public function findByQuery(Object $object, IQuery $query = null)
{
$class = get_class($object);
$query = (is_null($query)) ? new Query() : $query;
-
+
$rawQuery = $this->getRawQuery($object, $query);
$cursor = $this->db->selectCollection($object->collection())->find($rawQuery);
@@ -263,10 +263,10 @@ public function findOneByQuery(Object $object, IQuery $query = null)
$data = $this->db->selectCollection($object->collection())->findOne($rawQuery);
return $this->setData($object, $data);
}
-
+
/**
* Ensures that aliased properties are correctly converted in query
- *
+ *
* @param Object $object
* @param IQuery $query
*/
@@ -314,9 +314,12 @@ public function saveFile($filePath, $oldReference = null)
}
/**
- * @param Morph_Object $object
- * @param array $data
- * @return Morph_Object
+ * Sets data to the morph object
+ *
+ * @param Object $object
+ * @param mixed $data
+ * @return Object
+ * @throw ObjectNotFound if data is empty
*/
private function setData(Object $object, $data)
{
@@ -326,4 +329,4 @@ private function setData(Object $object, $data)
$object->__setData($data, Enum::STATE_CLEAN);
return $object;
}
-}
+}
View
28 src/morph/property/String.php
@@ -22,11 +22,12 @@ class String extends Generic
protected $maximumLength;
/**
- * @param string $Name
- * @param string $Default
- * @param integer $MaximumLength
+ * @param string $name
+ * @param string $default
+ * @param integer $maximumLength
*/
- public function __construct($name, $default = null, $maximumLength = null){
+ public function __construct($name, $default = null, $maximumLength = null)
+ {
parent::__construct($name, $default);
$this->maximumLength = (is_null($maximumLength)) ? null : (int)$maximumLength;
}
@@ -34,11 +35,13 @@ public function __construct($name, $default = null, $maximumLength = null){
/**
* Sets the value of this attribute
*
- * @param integer $Value
+ * @param mixed $value
+ * @return void
*/
- public function setValue($value){
+ public function setValue($value)
+ {
if (null === $value) {
- return parent::setValue($value);
+ return parent::setValue(null);
}
$cleanValue = (string)$value;
@@ -48,6 +51,7 @@ public function setValue($value){
'substr', array($cleanValue, 0, $this->maximumLength)
);
}
+
parent::setValue($cleanValue);
}
@@ -56,7 +60,8 @@ public function setValue($value){
*
* @return string
*/
- public function getValue(){
+ public function getValue()
+ {
return (null === parent::getValue()) ? null : (string)parent::getValue();
}
@@ -69,10 +74,17 @@ public function getValue(){
*/
protected function _getUnicodeValue($fncName, $value)
{
+ // PHP 5.4 has native support of unicode chars
+ if (version_compare(PHP_VERSION, '5.4', '>=')) {
+ return call_user_func_array($fncName, (array)$value);
+ }
+
+ // iconv or mbstring
$prefix = 'iconv';
if (extension_loaded('mbstring')) {
$prefix = 'mb';
}
+
return call_user_func_array($prefix . '_' . $fncName, (array)$value);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.