source: trunk/prototype/api/controller.php @ 6132

Revision 6132, 23.3 KB checked in by marcosw, 12 years ago (diff)

Ticket #2697 - Inserir informações de copyright em cabeçalho de arquivos

Line 
1<?php
2/**
3 *
4 * Copyright (C) 2012 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
5 *
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by
8 * the Free Software Foundation with the addition of the following permission
9 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
10 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
11 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program; if not, see www.gnu.org/licenses or write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301 USA.
22 *
23 * This code is based on the OpenXchange Connector and on the Prognus pSync
24 * Connector both developed by the community and licensed under the GPL
25 * version 2 or above as published by the Free Software Foundation.
26 *
27 * You can contact Prognus Software Livre headquarters at Av. Tancredo Neves,
28 * 6731, PTI, Edifício do Saber, 3º floor, room 306, Foz do Iguaçu - PR - Brasil or at
29 * e-mail address prognus@prognus.com.br.
30 *
31 * Classe de controle que faz manipulações de fluxo de informações para toda
32 * a API a partir de vários métodos.
33 *
34 * @package    Prototype
35 * @license    http://www.gnu.org/copyleft/gpl.html GPL
36 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
37 * @version    2.4
38 * @sponsor    Caixa Econômica Federal
39 * @since      Arquivo disponibilizado na versão 2.4
40 */
41
42if( !defined( 'ROOTPATH' ) )
43    define( 'ROOTPATH', dirname(__FILE__).'/..' );
44
45require_once(ROOTPATH.'/api/config.php');
46
47/**
48TODO list:
49
50  * definir de forma centralizada os caminhos e as constantes necessárias;
51  * criar um User Agent detect e um OS server detect para customizações espeçíficas de cada browser / servidor;
52  * criar um registrador para fallback handlers;
53  * criar um dependency manager na configuração dos serviços, para poder gerenciar os imports corretamente
54  * criar um login e a recuperação da sessão;
55
56*/
57
58/**
59 *
60 * @package    Prototype
61 * @license    http://www.gnu.org/copyleft/gpl.html GPL
62 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
63 * @version    2.4
64 * @sponsor    Caixa Econômica Federal
65 * @since      Classe disponibilizada na versão 2.4
66 */
67class Controller {
68
69        static $cache;
70        static $services = array();
71        static $interceptors = array();
72        static $config = array();
73        static $includes = array();
74        static $tx = array();
75        static $isConcept = array();
76        static $hasOne = array();
77        static $fallbackHandlers = array();
78        static $txID = 0;
79        static $wallet;
80
81        public function __destruct()
82        {
83//          if( $this->service )
84//              $this->service->close();
85//          else
86            self::closeAll();
87        }
88
89        public static function closeAll()
90        {
91            if( self::$services )
92                foreach( self::$services as $serviceName => $service )
93                    if( self::$config[ $serviceName ]['type'] === 'service' )
94                      $service->close();
95        }
96
97        public static function clearAll()
98            {
99            return self::$cache->clearAll();
100            }
101
102        public static function clear( $id )
103        {
104            return self::$cache->clear( $id );
105        }
106
107        public static function check( $id )
108        {
109            return self::$cache->get( $id );
110        }
111
112        public static function store( $id, $data, $expires, $compressed )
113        {
114            return self::$cache->put( $id, $data, $expires, $compressed );
115        }
116
117        public static function find( $URI, $params = false, $criteria = false )
118        {
119            if( isset($URI['id']) && $URI['id'] )
120                return self::read( $URI, $params, $criteria );
121           
122            return self::call( 'find', $URI, $params, $criteria );
123        }
124
125        public static function read( $URI, $params = false, $criteria = false )
126        {
127            if( !isset($URI['id']) || !$URI['id'] )
128                return self::find( $URI, $params, $criteria );
129
130            return self::call( 'read', $URI, $params, $criteria );
131        }
132
133        public static function deleteAll( $URI, $params = false, $criteria = false )
134        {
135            if( isset($URI['id']) && $URI['id'] )
136                return self::delete( $URI, $params, $criteria );
137
138            return self::call( 'deleteAll', $URI, $params, $criteria );
139        }
140
141        public static function delete( $URI, $params = false, $criteria = false )
142        {
143            if( !isset($URI['id']) || !$URI['id'] )
144                return self::deleteAll( $URI, $params, $criteria );
145
146            return self::call( 'delete', $URI, $params, $criteria );
147        }
148
149        public static function replace( $URI, $params, $criteria = false )
150        {
151            if( isset($URI['id']) && $URI['id'] )
152                return self::update( $URI, $params, $criteria );
153
154            return self::call( 'replace', $URI, $params, $criteria );
155        }
156
157        public static function update( $URI, $params, $criteria = false )
158        {
159            if( !isset($URI['id']) || !$URI['id'] )
160                return self::replace( $URI, $params, $criteria );
161
162            return self::call( 'update', $URI, $params, $criteria );
163        }
164
165        public static function create( $URI, $params, $criteria = false )
166        {
167            return self::call( 'create', $URI, $params, $criteria );
168        }
169
170        public static function begin( $URI, $params = false, $criteria = false )
171        {
172            return self::call( 'begin', $URI, $params, $criteria );
173        }
174
175        public static function commit( $URI, $criteria = false )
176            {
177            return self::call( 'commit', $URI, false, $criteria );
178        }
179
180        public static function rollback( $URI, $criteria = false )
181        {
182            return self::call( 'rollback', $URI, false, $criteria );
183        }
184
185        public static function format( $URI, $params, $criteria = false )
186        {
187            return self::call( 'format', $URI, $params, $criteria );
188        }
189
190        public static function parse( $URI, $data, $criteria = false )
191        {
192            return self::call( 'parse', $URI, $data, $criteria );
193            }
194
195        public static function URI( $className, $id = false, $service = false )
196        {
197            return array( 'concept' => $className,
198                          'service' => $service ? $service : false,
199                          'id' => $id ? $id : '' );
200        }
201
202        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
203        public static function links( $concept = false, $linkage = false )
204        {
205           
206
207            if( !isset(self::$config[ $concept ]) )
208              self::$config[ $concept ] = self::loadConfig( $concept );
209
210            $links = array();
211            self::$isConcept[ $concept ] = array();
212            self::$hasOne[ $concept ] = array();
213
214            if( isset(self::$config[ $concept ][ 'model.hasOne' ]) )
215                foreach( self::$config[ $concept ][ 'model.hasOne' ] as $linkName => $linkTarget )
216                {
217                    list( $target, $link ) = explode( '.', $linkTarget );
218
219                    if( $linkage === $linkName )
220                        $return = $link;
221
222                    $links[$linkName] = $target;
223                    self::$hasOne[ $concept ][ $linkName ] = true;
224                }
225            if( isset(self::$config[ $concept ][ 'model.depends' ]) )
226                foreach( self::$config[ $concept ][ 'model.depends' ] as $linkName => $linkTarget )
227                {
228                    list( $target, $link ) = explode( '.', $linkTarget );
229
230                     if( $linkage === $linkName )
231                        $return = $link;
232
233                    $links[$linkName] = $target;
234                    self::$hasOne[ $concept ][ $linkName ] = true;
235                    self::$isConcept[ $concept ][ $linkName ] = true;
236                }
237            if( isset(self::$config[ $concept ][ 'model.hasMany' ]) )
238                foreach( self::$config[ $concept ][ 'model.hasMany' ] as $linkName => $linkTarget )
239                {
240                    list( $target, $link ) = explode( '.', $linkTarget );
241
242                     if( $linkage === $linkName )
243                        $return = $link;
244
245                    $links[$linkName] = $target;
246                }
247
248            return( isset($return) ? $return : $links );
249        }
250
251        public static function isConcept( $concept, $linkName )
252        {
253            if( !isset( self::$isConcept[ $concept ] ) )
254                self::links( $concept );
255
256            return( isset(self::$isConcept[ $concept ][ $linkName ]) );
257        }
258
259        public static function hasOne( $concept, $linkName )
260        {
261            if( !isset( self::$hasOne[ $concept ] ) )
262                self::links( $concept );
263
264            return( isset(self::$hasOne[ $concept ][ $linkName ]) );
265        }
266
267        public static function getConcept( $concept, $moduleName = false )
268        {
269            if( isset( self::$config[ $concept ] ) )
270                return( self::$config[ $concept ] );
271
272            return( self::$config[ $concept ] = self::loadConfig( $concept, $moduleName ) );
273        }
274
275        public static function loadCache( $cacheType = 'Memory' )
276        {
277            include_once( "cache/MemoryCache.php" );
278            return new MemoryCache();
279        }
280
281        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
282        public static function loadConfig( $className, $isService = false)
283        {
284            $fileName = $className.'.'.($isService ? 'srv' : 'ini');
285
286            $config = self::$cache->get( $fileName );
287       
288            if( !$config )
289            {
290                $config = parse_ini_file( ROOTPATH.'/config/'.$fileName, true );
291
292                self::$cache->put( $fileName, $config );
293            }
294
295            return( $config );
296        }
297
298        public static function import( $path, $ext = ".php" )
299        {
300            if( !isset(self::$includes[$path]) )
301        {
302                require_once( ROOTPATH.'/'.$path.$ext );
303                self::$includes[$path] = false;
304            }
305
306            return( self::$includes[$path] );
307        }
308
309        public static function load( $path, $class = false )
310            {
311            if( $return = self::import( $path, "" ) )
312                return( $return );
313
314            if( !$class ){
315                preg_match( '/^\/?.*\/([^\/]+).php$/', $path, $class );
316                $class = $class[1];
317            }
318
319            $object =  self::$cache->get( $class );
320
321            if( !$object )
322            {
323                $object = new $class();
324                 self::$cache->put( $class, $object );
325            }
326
327            self::$includes[$path] = $object;
328
329            return( $object );
330        }
331
332        public static function wallet( $serviceName )
333        {
334            if( !isset( self::$wallet ) )
335            {
336                //// Hack //// TODO: passar o init da sessão no login do expresso
337                Config::init();
338
339                if(isset($_SESSION['wallet']))
340                    self::$wallet = $_SESSION['wallet'];
341                /////////////
342            }
343
344            return isset( self::$wallet[ $serviceName ] )? self::$wallet[ $serviceName ] : false;
345        }
346               
347        public static function connect( $service, $config )
348            {
349            $result = $service->open( $config );
350
351            if( is_string( $result ) )
352                throw new Exception( $result );
353
354            return( true );
355        }
356
357        public static function configure( $config, $newConfig )
358        {
359            foreach( $newConfig as $key => $value )
360                $config[$key] = $value;
361
362            return( $config );
363            }
364
365        public static function dispatch( $dispatcher, $data, $optionsMap = false )
366        {
367//          if( $mappedTo )
368//              $data = array( $mappedTo => $data );
369//
370//          foreach( $data as $method => $params )
371//          {
372// //           foreach( $data[ $method ] as $name => $value )
373//          }
374//
375//          self::import( "$dispatcher.php" );
376        }
377
378        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
379        public static function service( $serviceName, $concept = false )
380        {
381            if( isset( self::$services[ $serviceName ] ) )
382                return self::$services[ $serviceName ];
383
384            if( !isset(self::$config[ $serviceName ]) )
385                 self::$config[ $serviceName ] = self::loadConfig( $serviceName, true );
386
387            if( !isset(self::$config[ $serviceName ]) )
388                return( false );
389
390            if( !isset(self::$config[ $serviceName ]['type']) )
391                self::$config[ $serviceName ]['type'] = 'service';
392
393            self::import( 'api/'.self::$config[ $serviceName ]['type'] );   //TODO: Item 4
394
395            $service = self::load( self::$config[ $serviceName ]['path'],
396                                   self::$config[ $serviceName ]['class'] );
397
398              $srvConfig = array();
399
400            if( isset(self::$config[ $serviceName ][ 'config' ]) )
401                $srvConfig = self::configure( $srvConfig, self::$config[ $serviceName ][ 'config' ] );
402            if( $wallet = self::wallet( $serviceName ) )
403                $srvConfig = self::configure( $srvConfig, $wallet );
404            if( $concept && isset(self::$config[ $concept ]['service.config']) )
405                $srvConfig = self::configure( $srvConfig, self::$config[ $concept ]['service.config'] );
406
407            if( empty( $srvConfig ) )
408                $srvConfig = false;
409
410            if( $service && self::$config[ $serviceName ]['type'] === 'service' )
411                self::connect( $service, $srvConfig );
412
413            return( self::$services[ $serviceName ] = $service );
414        }
415
416        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
417        public static function interceptor( $method, $concept = false, $serviceName = false, $isService = false )
418        {
419            if( $concept && !isset(self::$config[ $concept ]) )
420              self::$config[ $concept ] = self::loadConfig( $concept );
421
422            if( !$concept ) $concept = 'global';
423            if( !$isService || !$serviceName ) $serviceName = 'global';
424
425            if( !isset( self::$interceptors[ $concept ] ) )
426                self::$interceptors[ $concept ] = array();
427
428            if( !isset( self::$interceptors[ $concept ][ $serviceName ] ) )
429                self::$interceptors[ $concept ][ $serviceName ] = array();
430
431            if( !isset( self::$interceptors[ $concept ][ $serviceName ][ $method ] ) )
432            {
433                $events = array( 'before', 'after' );
434                $interceptors = array();
435
436                $prefix = ( $isService )? "$serviceName." : "";
437
438                foreach( $events as $i => $event )
439                {
440                    $interceptors[$event] = array();
441
442                    if( !isset(self::$config[$concept]["$prefix$event.$method"]) )
443                      continue;
444
445                    foreach( self::$config[$concept]["$prefix$event.$method"] as $intercept => $interceptor )
446                            $interceptors[$event][$intercept] = self::load( $interceptor );
447                }
448
449                self::$interceptors[ $concept ][ $serviceName ][ $method ] = $interceptors;
450            }
451
452            return( self::$interceptors[ $concept ][ $serviceName ][ $method ] );
453        }
454
455        public static function interceptorCommit( $eventType, $commitList, $isService = false )
456        {
457            $result = array( $eventType => array() );
458       
459            if( is_array( $commitList ) )
460                foreach( $commitList as $i => $tx )
461                {
462                    $interceptors = self::interceptor( 'commit', $tx['concept'], $tx['service'], $isService );
463     
464                    $result[$eventType] = array_merge( $result[$eventType], $interceptors[$eventType] );
465                }
466
467            return( $result );
468        }
469
470        public static function fire( $eventType, $method, &$params, $original, $isService = false )
471        {
472            if( $method === 'commit' )
473                $interceptors = self::interceptorCommit( $eventType, $params['criteria'], $isService );
474
475            else
476                $interceptors = self::interceptor( $method,
477                                                   isset($original['URI']['concept']) ? $original['URI']['concept'] : false,
478                                                   isset($params['URI']['service']) ? $params['URI']['service'] : false, $isService );
479
480            if( $interceptors && isset($interceptors[ $eventType ]) )
481                foreach( $interceptors[ $eventType ] as $intercept => $interceptor )
482                {
483                    $return = $interceptor->$intercept( $params['URI'], $params['properties'], $params['criteria'], $original /*, $params['service'] */);
484
485                    if( $return === false )
486                return( false );
487
488                    if( isset($return) )
489                        $params['properties'] = $return;
490                }
491
492              return( $params );
493        }
494
495        /*
496          * ex: array
497          *             (
498          *                     [0] array( 'OR', array( array( '=', 'campo', 'valor' ),
499                                                          array( 'OR', array( array( '=', 'campo', 'valor' ) ) ) )
500          *                     [1] array( '=', 'campo' , 'valor' )
501          *                     [2] array( 'OR' , array( array( '=' , campo', 'valor' ) ) )
502          *                     [3] array( 'IN', 'campo', array( '1' , '2' , '3' ) )
503          *             )
504          * OR
505          *         array( '=' , 'campo' , 'valor' )
506        */
507
508        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
509        public static function serviceName( $URI, $original = false )
510        {
511             $concept = "";
512
513            if( $original && isset($original['concept']) && $original['concept'] )
514                $concept = $original['concept'];
515            elseif( isset($URI['concept']) && $URI['concept'] )
516                $concept = $URI['concept'];
517
518            if( ( !isset($URI['service']) || !$URI['service'] ) && $concept )
519            {
520                if( !isset(self::$config[ $concept ]) )
521                    self::$config[ $concept ] = self::loadConfig( $concept );
522
523                $URI['service'] = self::$config[ $concept ][ 'service' ];
524            }
525
526            if( !isset($URI['service']) )
527                throw new Exception( "CONFIGURATION ERROR: service name from concept '$concept' not found" );
528
529            return( $URI );
530        }
531
532        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmos nas options passadas
533        public static function call( $method, $URI, $properties = false, $options = false, $service = false )
534        {
535            try
536            {
537                if( !isset($URI['concept']) ) $URI['concept'] = false;
538
539                $original = $params = array( 'properties' => $properties,
540                                             'criteria' => $options,
541                                             'URI' => $URI,
542                                             'service' => $service );
543
544                if( isset($params['URI']['concept'])  && !self::fire( 'before', $method, $params, $original ) )
545                    return( empty($params['properties']) ? false : $params['properties'] );
546
547               
548
549                if( $params && !$params['service'] )
550                {
551                    $params['URI'] = self::serviceName( $params['URI'], $original['URI'] );
552
553                    $params['service'] = self::service( $params['URI']['service'], $params['URI']['concept'] );
554                }
555
556                if( isset($params['URI']['service']) )
557                {
558                    if( $method === 'create' || $method === 'update' || $method === 'delete' )
559                    {
560                        if( $commit = !isset(self::$tx[ $params['URI']['service'] ])  )
561                        {
562                            self::call( 'begin', $params['URI'] );
563                        }
564
565                        $TX = array();
566                    }
567
568                    if( !self::fire( 'before', $method, $params, $original, true ) )
569                        return( empty($params['properties']) ? false : $params['properties'] );
570                }
571
572                if( $params['service'] )
573                    switch( $method )
574                    {
575                        case 'find': $return = $params['service']->find( $params['URI'], $params['properties'], $params['criteria'] ); break;
576
577                        case 'read': $return = $params['service']->read( $params['URI'], $params['properties'] , $params['criteria'] ); break;
578
579                        case 'create': $return = $params['service']->create( $params['URI'], $params['properties']/*, $criteria*/ ); break;
580
581                        case 'delete': $return = $params['service']->delete( $params['URI'], $params['properties'], $params['criteria'] ); break;
582
583                        case 'deleteAll': $return = $params['service']->deleteAll( $params['URI'], $params['properties'], $params['criteria'] ); break;
584
585                        case 'update': $return = $params['service']->update( $params['URI'], $params['properties'], $params['criteria'] ); break;
586
587                        case 'replace': $return = $params['service']->replace( $params['URI'], $params['properties'], $params['criteria'] ); break;
588
589                        case 'begin': $return = $params['service']->begin( $params['URI'] ); break;
590
591                        case 'commit': $return = $params['service']->commit( $params['URI'], $params['criteria'] ); break;
592
593                        case 'rollback': $return = $params['service']->rollback( $params['URI'], $params['criteria'] ); break;
594
595                        case 'parse': $return = $params['service']->parse( $params['properties'], $params['criteria'] ); break;
596
597                        case 'analize': $return = $params['service']->analize( $params['properties'], $params['criteria'] ); break;
598
599                        case 'format': $return = $params['service']->format( $params['properties'], $params['criteria'] ); break;
600
601                        default : $return = $params['service']->$method( $params['properties'], $params['criteria'] );
602                    }
603
604                if( isset($return) && $return !== false )
605                    $params['properties'] = $return;
606
607                if( isset($params['URI']['service']) )
608                    if( !self::fire( 'after', $method, $params, $original, true ) )
609                        return( empty($params['properties']) ? false : $params['properties'] );
610
611                if( isset($URI['concept']) )
612                    self::fire( 'after', $method, $params, $original );
613
614                if( empty($params['properties']) )
615                    $params['properties'] = false;
616
617                if( isset( $TX ) )
618                {
619                    $TX['rollback'] = !!!$params['properties'];
620
621                    if( $params['properties'] && is_array($params['properties']) && isset($params['properties']['id']) )
622                        $TX['id'] = $params['properties']['id'];
623
624                    self::$tx[ $params['URI']['service'] ][] = array_merge( $TX, $original['URI'], array( 'service' => $params['URI']['service'], 'method' => $method ) );
625
626                    if( isset($commit) && $commit )
627                    {
628                        if( !self::call( 'commit', $params['URI'], false, self::$tx[ $params['URI']['service'] ] ) )
629                            self::call( 'rollback', $params['URI'] , false, self::$tx[ $params['URI']['service'] ] );
630
631                        unset( self::$tx[ $params['URI']['service'] ] );
632                    }
633                }
634            }
635            catch( Exception $e )
636            {
637                if( !self::fallback( $e ) )
638                    self::closeAll();
639
640                return( false );
641            }
642
643            return( $params['properties'] );
644        }
645
646        public static function fallback( $exception )
647        {
648            $code = $exception->getCode();
649
650            if( isset( self::$fallbackHandlers[ $code ] ) )
651                {
652                        $fn = self::$fallbackHandlers[ $code ];
653                        return $fn( $exception );
654                }
655
656            error_log( $exception->getMessage() );
657            return( true );
658        }
659
660        public static function addFallbackHandler( $code, $function )
661        {
662            self::$fallbackHandlers[ $code ] = $function;
663        }
664        /*
665         *NULL evita erros caso não seja passado nenhuma variavel por referência
666        */
667        public static function put( $URI, $data, &$txIds = NULL )
668        {
669            try
670            {
671                $URI = self::serviceName( $URI );
672
673                if( $commit = !$txIds )
674                    $txIds = array();
675
676                if( !isset( self::$tx[ $URI['service'] ] ) )
677                {
678                    self::call( 'begin', $URI );
679                    self::$tx[ $txIds[] = $URI['service'] ] = array();
680                }
681
682                $method = $data ? isset( $data['id'] ) ?
683                          'update' : 'create' : 'delete';
684
685                $links = self::links( $URI['concept'] );
686
687                $order = self::$txID++;
688
689                $postpone = array();
690                $linkNames = array();
691
692                if( $data )
693                {
694                    $URI['id'] = isset( $data['id'] ) ? $data['id'] : false;
695
696                    foreach( $links as $linkName => $linkTarget )
697                    {
698                        if( isset( $data[$linkName] ) && is_array( $data[$linkName] ) )
699                        {
700                                if( self::isConcept( $URI['concept'], $linkName ) )
701                                    $data[$linkName] = self::put( array( 'concept' => $linkTarget ), $data[$linkName], $txIds );
702                            else
703                            {
704                                    $postpone[ $linkTarget ] =  $data[$linkName];
705                                    $linkNames[ $linkTarget ] = $linkName;
706                            }
707                        }
708                    }
709                }
710                else
711                  $URI['id'] = isset( $data['id'] ) ? $data['id'] : $URI['id'];
712
713                $result = Controller::call( $method, $URI, $data, false, false, true );
714
715                if( is_array( $result ) && isset( $result['id'] ) )
716                      $URI['id'] = $result['id'];
717
718                self::$tx[ $URI['service'] ][ count(self::$tx[ $URI['service'] ]) - 1 ]['order'] = $order;
719                self::$tx[ $URI['service'] ][ count(self::$tx[ $URI['service'] ]) - 1 ]['id'] = $URI['id'];
720
721                foreach( $postpone as $linkTarget => $dt )
722                {
723                      if( Controller::hasOne( $URI['concept'], $linkNames[ $linkTarget ] ) )
724                          $dt = array( $dt );
725
726                      foreach( $dt as $ii => $value )
727                      {
728                          if( !is_array( $value ) )
729                            $value = array( 'id' => $value );
730
731                          $value[ self::links( $URI['concept'], $linkNames[ $linkTarget ] ) ] = $URI['id'];
732 
733                          self::put( array( 'concept' => $linkTarget ), $value, $txIds );
734                      }
735                }
736                if( $commit )
737                {
738                      $result = array();
739
740                      for( $i = count( $txIds ) - 1; $i >= 0; $i-- )
741                      {
742                              $currentTx = self::$tx[ $txIds[$i] ];
743                              unset( self::$tx[ $txIds[$i] ] );
744
745                              if( !self::commit( array( 'service' => $txIds[$i] ), $currentTx ) )
746                              {
747                                  self::rollback( array( 'service' => $txIds[$i] ), $currentTx );
748
749                                  foreach( $currentTx as $i => $st )
750                                      $currentTx[$i][ 'rollback' ] = true;
751                              }
752
753                              $result = array_merge( $result, $currentTx );
754                      }
755
756                      self::$txID = 0;
757
758                      return( $result );
759                }
760
761            }
762            catch( Exception $e )
763            {
764                if( !self::fallback( $e ) )
765                    self::closeAll();
766
767                return( false );
768            }
769       
770            return( $URI['id'] );
771        }
772       
773        public static function get()
774        {
775       
776        }
777}
778
779Controller::$cache = Controller::loadCache();
780// ?>
Note: See TracBrowser for help on using the repository browser.