Permalink
Browse files

Merge remote-tracking branch 'matuszemi/camelcase'

  • Loading branch information...
2 parents b33c029 + 7a1213a commit 55b7aa5388c8c7e5a2f0e579029e07e83840e149 @EvanDotPro committed Apr 19, 2012
@@ -6,7 +6,8 @@
Zend\Db\ResultSet\RowObjectInterface,
DateTime,
InvalidArgumentException,
- ArrayAccess;
+ ArrayAccess,
+ ZfcBase\Util\String;
abstract class ModelAbstract implements ArrayAccess, RowObjectInterface
{
@@ -154,21 +155,12 @@ public function offsetUnset($key) {
public static function fieldToSetterMethod($name)
{
- return 'set' . static::toCamelCase($name);
+ return 'set' . String::toCamelCase($name);
}
public static function fieldToGetterMethod($name)
{
- return 'get' . static::toCamelCase($name);
+ return 'get' . String::toCamelCase($name);
}
- public static function toCamelCase($name)
- {
- return implode('',array_map('ucfirst', explode('_',$name)));
- }
-
- public static function fromCamelCase($name)
- {
- return trim(preg_replace_callback('/([A-Z])/', function($c){ return '_'.strtolower($c[1]); }, $name),'_');
- }
}
@@ -59,12 +59,12 @@ public function setMergedConfig($mergedConfig) {
$this->mergedConfig = $mergedConfig;
}
- public function getOptions() {
+ public function getOptions($namespace = 'options') {
$config = $this->getMergedConfig();
- if(empty($config[$this->getNamespace()]['options'])) {
+ if(empty($config[$this->getNamespace()][$namespace])) {
return array();
}
- return $config[$this->getNamespace()]['options'];
+ return $config[$this->getNamespace()][$namespace]->toArray();
}
/**
@@ -96,8 +96,8 @@ public function getOptions() {
* @param mixed $default
* @return mixed
*/
- public function getOption($option, $default = null) {
- $options = $this->getOptions();
+ public function getOption($option, $default = null, $namespace = 'options') {
+ $options = $this->getOptions($namespace);
$optionArr = explode('.', $option);
$option = $this->getOptionFromArray($options, $optionArr, $default, $option);
@@ -0,0 +1,9 @@
+<?php
+
+namespace ZfcBase\Service\Exception;
+
+use InvalidArgumentException;
+
+class ModelNotFoundException extends InvalidArgumentException {
+
+}
@@ -10,7 +10,7 @@
ZfcBase\Model\ModelAbstract,
ZfcBase\Mapper\ModelMapper,
ZfcBase\Mapper\Transactional,
- InvalidArgumentException as NoModelFoundException;
+ ZfcBase\Service\Exception\ModelNotFoundException;
class ModelServiceAbstract extends ServiceAbstract {
protected $mapper;
@@ -62,7 +62,7 @@ public function get(array $filter, $exts = array()) {
});
$model = $result->last();
if(!$model instanceof $modelClass) {
- throw new NoModelFoundException("No model found filter: " . print_r($filter, true));
+ throw new ModelNotFoundException("No model found filter: " . print_r($filter, true));
}
if($exts === true) {
@@ -95,15 +95,14 @@ public function remove($id) {
$mapper = $this->getMapper();
$model = $mapper->findByPriKey($id);
if(!$model) {
- throw new NoModelFoundException("Model does not exist #$id");
+ throw new ModelNotFoundException("Model does not exist #$id");
}
try {
if($mapper instanceof Transactional) {
$mapper->beginTransaction();
}
$params = $this->triggerParamsMergeEvent('remove.pre', array(
- //'id' => $id,
'model' => $model
));
@@ -39,4 +39,14 @@ public static function getRandomBytes($byteLength)
}
return $data;
}
+
+ public static function toCamelCase($name)
+ {
+ return implode('',array_map('ucfirst', explode('_',$name)));
+ }
+
+ public static function fromCamelCase($name)
+ {
+ return trim(preg_replace_callback('/([A-Z])/', function($c){ return '_'.strtolower($c[1]); }, $name),'_');
+ }
}

0 comments on commit 55b7aa5

Please sign in to comment.