Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Small corerctions in the String property

  • Loading branch information...
commit 16dabcb45ba034a857b4a8e4f82674a299fa06b4 1 parent 25a4a2e
@kkamkou kkamkou authored
Showing with 40 additions and 24 deletions.
  1. +1 −0  .gitignore
  2. +19 −16 src/morph/Storage.php
  3. +20 −8 src/morph/property/String.php
View
1  .gitignore
@@ -7,3 +7,4 @@ doc/api
doc/test_report
doc/integration_report
doc/manual/build/*
+/.idea/
View
35 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);
@@ -222,7 +222,7 @@ 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.