Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Base class for Active Records
- *
- * @version 7.5
- * @package database
- * @author Pablo Dall'Oglio
- * @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
- * @license http://www.adianti.com.br/framework-license
- */
- class TRecordExpanded extends TRecord
- {
- /**
- * Executed whenever an unknown method is executed
- * @param $method Method name
- * @param $parameter Method parameters
- */
- public static function __callStatic($method, $parameters)
- {
- $class_name = get_called_class();
- if (substr($method,-13) == 'InTransaction')
- {
- $method = substr($method,0,-13);
- if (method_exists($class_name, $method))
- {
- // Interact wiht WHERE
- if ($method == 'where' && is_array($parameters[1])) {
- $database = array_shift($parameters);
- $where_field = $parameters[0][0];
- $where_operator = $parameters[0][1];
- $where_value = $parameters[0][2];
- $where_return = $parameters[0][3] ?? 0;
- $where_field_return = $parameters[0][4] ?? 0;
- TTransaction::open($database);
- if ($where_return) {
- switch ($where_return) {
- case 'load':
- $content = $class_name::where( $where_field, $where_operator, $where_value )->load();
- break;
- case 'count':
- $content = $class_name::where( $where_field, $where_operator, $where_value )->count();
- break;
- case 'first':
- $content = $class_name::where( $where_field, $where_operator, $where_value )->first();
- if ($content && $where_field_return) {
- $content = $content->$where_field_return;
- }
- break;
- default:
- $content = $class_name::where( $where_field, $where_operator, $where_value )->$where_return;
- break;
- }
- } else {
- $content = $class_name::where( $where_field, $where_operator, $where_value )->load();
- }
- TTransaction::close();
- return $content;
- } else {
- // Interact with FIND
- $database = array_shift($parameters);
- TTransaction::open($database);
- $content = forward_static_call_array( array($class_name, $method), $parameters);
- TTransaction::close();
- return $content;
- }
- }
- else
- {
- throw new Exception(AdiantiCoreTranslator::translate('Method ^1 not found', $class_name.'::'.$method.'()'));
- }
- }
- else if (method_exists('TRepository', $method))
- {
- $class = get_called_class(); // get the Active Record class name
- $repository = new TRepository( $class ); // create the repository
- return call_user_func_array( array($repository, $method), $parameters );
- }
- else
- {
- throw new Exception(AdiantiCoreTranslator::translate('Method ^1 not found', $class_name.'::'.$method.'()'));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment