예제 #1
0
 protected function _createFunctionGetOrError(array $options)
 {
     $name = $options['name'];
     $lcFirstName = lcfirst($name);
     $function = $this->createFunction('_get' . $name . 'OrError');
     $function->setPhpDoc(array('', '@return array'));
     $primaryKeyId = $options['primary_key_id'];
     $camelCasePrimaryKeyId = ThemeHouse_Reflection_Helper_Template::snakeCaseToCamelCase($primaryKeyId);
     $lcFirstPrimaryKeyId = lcfirst($camelCasePrimaryKeyId);
     $function->setSignature(array('$' . $lcFirstPrimaryKeyId));
     $snakeCase = ThemeHouse_Reflection_Helper_Template::camelCaseToSnakeCase($options['name']);
     $addOnId = $options['addon_id'];
     $notFoundPhrase = ThemeHouse_Reflection_Helper_Phrase::getPhraseName($snakeCase . '_not_found', $addOnId);
     $model = XenForo_Model::create($options['model']);
     $modelReflectionClass = new ThemeHouse_Controllers_Reflection_Class_Model(get_class($model));
     if ($modelReflectionClass->hasMethod('prepare' . $name)) {
         $body = array('$' . $lcFirstName . 'Model = $this->_get' . $options['name'] . 'Model();', '', 'return $' . $lcFirstName . 'Model->prepare' . $options['name'] . '(', "\t" . '$this->getRecordOrError($' . $lcFirstPrimaryKeyId . ', $' . $lcFirstName . 'Model, \'get' . $options['name'] . 'ById\',', "\t\t" . '\'' . $notFoundPhrase . '\'));');
     } else {
         $body = array('return $this->getRecordOrError($' . $lcFirstPrimaryKeyId . ', $this->_get' . $options['name'] . 'Model(), \'get' . $options['name'] . 'ById\',', "\t" . '\'' . $notFoundPhrase . '\');');
     }
     $function->setBody($body);
 }