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

Revision 6115, 23.0 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
58class Controller {
59
60        static $cache;
61        static $services = array();
62        static $interceptors = array();
63        static $config = array();
64        static $includes = array();
65        static $tx = array();
66        static $isConcept = array();
67        static $hasOne = array();
68        static $fallbackHandlers = array();
69        static $txID = 0;
70        static $wallet;
71
72        public function __destruct()
73        {
74//          if( $this->service )
75//              $this->service->close();
76//          else
77            self::closeAll();
78        }
79
80        public static function closeAll()
81        {
82            if( self::$services )
83                foreach( self::$services as $serviceName => $service )
84                    if( self::$config[ $serviceName ]['type'] === 'service' )
85                      $service->close();
86        }
87
88        public static function clearAll()
89            {
90            return self::$cache->clearAll();
91            }
92
93        public static function clear( $id )
94        {
95            return self::$cache->clear( $id );
96        }
97
98        public static function check( $id )
99        {
100            return self::$cache->get( $id );
101        }
102
103        public static function store( $id, $data, $expires, $compressed )
104        {
105            return self::$cache->put( $id, $data, $expires, $compressed );
106        }
107
108        public static function find( $URI, $params = false, $criteria = false )
109        {
110            if( isset($URI['id']) && $URI['id'] )
111                return self::read( $URI, $params, $criteria );
112           
113            return self::call( 'find', $URI, $params, $criteria );
114        }
115
116        public static function read( $URI, $params = false, $criteria = false )
117        {
118            if( !isset($URI['id']) || !$URI['id'] )
119                return self::find( $URI, $params, $criteria );
120
121            return self::call( 'read', $URI, $params, $criteria );
122        }
123
124        public static function deleteAll( $URI, $params = false, $criteria = false )
125        {
126            if( isset($URI['id']) && $URI['id'] )
127                return self::delete( $URI, $params, $criteria );
128
129            return self::call( 'deleteAll', $URI, $params, $criteria );
130        }
131
132        public static function delete( $URI, $params = false, $criteria = false )
133        {
134            if( !isset($URI['id']) || !$URI['id'] )
135                return self::deleteAll( $URI, $params, $criteria );
136
137            return self::call( 'delete', $URI, $params, $criteria );
138        }
139
140        public static function replace( $URI, $params, $criteria = false )
141        {
142            if( isset($URI['id']) && $URI['id'] )
143                return self::update( $URI, $params, $criteria );
144
145            return self::call( 'replace', $URI, $params, $criteria );
146        }
147
148        public static function update( $URI, $params, $criteria = false )
149        {
150            if( !isset($URI['id']) || !$URI['id'] )
151                return self::replace( $URI, $params, $criteria );
152
153            return self::call( 'update', $URI, $params, $criteria );
154        }
155
156        public static function create( $URI, $params, $criteria = false )
157        {
158            return self::call( 'create', $URI, $params, $criteria );
159        }
160
161        public static function begin( $URI, $params = false, $criteria = false )
162        {
163            return self::call( 'begin', $URI, $params, $criteria );
164        }
165
166        public static function commit( $URI, $criteria = false )
167            {
168            return self::call( 'commit', $URI, false, $criteria );
169        }
170
171        public static function rollback( $URI, $criteria = false )
172        {
173            return self::call( 'rollback', $URI, false, $criteria );
174        }
175
176        public static function format( $URI, $params, $criteria = false )
177        {
178            return self::call( 'format', $URI, $params, $criteria );
179        }
180
181        public static function parse( $URI, $data, $criteria = false )
182        {
183            return self::call( 'parse', $URI, $data, $criteria );
184            }
185
186        public static function URI( $className, $id = false, $service = false )
187        {
188            return array( 'concept' => $className,
189                          'service' => $service ? $service : false,
190                          'id' => $id ? $id : '' );
191        }
192
193        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
194        public static function links( $concept = false, $linkage = false )
195        {
196           
197
198            if( !isset(self::$config[ $concept ]) )
199              self::$config[ $concept ] = self::loadConfig( $concept );
200
201            $links = array();
202            self::$isConcept[ $concept ] = array();
203            self::$hasOne[ $concept ] = array();
204
205            if( isset(self::$config[ $concept ][ 'model.hasOne' ]) )
206                foreach( self::$config[ $concept ][ 'model.hasOne' ] as $linkName => $linkTarget )
207                {
208                    list( $target, $link ) = explode( '.', $linkTarget );
209
210                    if( $linkage === $linkName )
211                        $return = $link;
212
213                    $links[$linkName] = $target;
214                    self::$hasOne[ $concept ][ $linkName ] = true;
215                }
216            if( isset(self::$config[ $concept ][ 'model.depends' ]) )
217                foreach( self::$config[ $concept ][ 'model.depends' ] as $linkName => $linkTarget )
218                {
219                    list( $target, $link ) = explode( '.', $linkTarget );
220
221                     if( $linkage === $linkName )
222                        $return = $link;
223
224                    $links[$linkName] = $target;
225                    self::$hasOne[ $concept ][ $linkName ] = true;
226                    self::$isConcept[ $concept ][ $linkName ] = true;
227                }
228            if( isset(self::$config[ $concept ][ 'model.hasMany' ]) )
229                foreach( self::$config[ $concept ][ 'model.hasMany' ] as $linkName => $linkTarget )
230                {
231                    list( $target, $link ) = explode( '.', $linkTarget );
232
233                     if( $linkage === $linkName )
234                        $return = $link;
235
236                    $links[$linkName] = $target;
237                }
238
239            return( isset($return) ? $return : $links );
240        }
241
242        public static function isConcept( $concept, $linkName )
243        {
244            if( !isset( self::$isConcept[ $concept ] ) )
245                self::links( $concept );
246
247            return( isset(self::$isConcept[ $concept ][ $linkName ]) );
248        }
249
250        public static function hasOne( $concept, $linkName )
251        {
252            if( !isset( self::$hasOne[ $concept ] ) )
253                self::links( $concept );
254
255            return( isset(self::$hasOne[ $concept ][ $linkName ]) );
256        }
257
258        public static function getConcept( $concept, $moduleName = false )
259        {
260            if( isset( self::$config[ $concept ] ) )
261                return( self::$config[ $concept ] );
262
263            return( self::$config[ $concept ] = self::loadConfig( $concept, $moduleName ) );
264        }
265
266        public static function loadCache( $cacheType = 'Memory' )
267        {
268            include_once( "cache/MemoryCache.php" );
269            return new MemoryCache();
270        }
271
272        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
273        public static function loadConfig( $className, $isService = false)
274        {
275            $fileName = $className.'.'.($isService ? 'srv' : 'ini');
276
277            $config = self::$cache->get( $fileName );
278       
279            if( !$config )
280            {
281                $config = parse_ini_file( ROOTPATH.'/config/'.$fileName, true );
282
283                self::$cache->put( $fileName, $config );
284            }
285
286            return( $config );
287        }
288
289        public static function import( $path, $ext = ".php" )
290        {
291            if( !isset(self::$includes[$path]) )
292        {
293                require_once( ROOTPATH.'/'.$path.$ext );
294                self::$includes[$path] = false;
295            }
296
297            return( self::$includes[$path] );
298        }
299
300        public static function load( $path, $class = false )
301            {
302            if( $return = self::import( $path, "" ) )
303                return( $return );
304
305            if( !$class ){
306                preg_match( '/^\/?.*\/([^\/]+).php$/', $path, $class );
307                $class = $class[1];
308            }
309
310            $object =  self::$cache->get( $class );
311
312            if( !$object )
313            {
314                $object = new $class();
315                 self::$cache->put( $class, $object );
316            }
317
318            self::$includes[$path] = $object;
319
320            return( $object );
321        }
322
323        public static function wallet( $serviceName )
324        {
325            if( !isset( self::$wallet ) )
326            {
327                //// Hack //// TODO: passar o init da sessão no login do expresso
328                Config::init();
329
330                if(isset($_SESSION['wallet']))
331                    self::$wallet = $_SESSION['wallet'];
332                /////////////
333            }
334
335            return isset( self::$wallet[ $serviceName ] )? self::$wallet[ $serviceName ] : false;
336        }
337               
338        public static function connect( $service, $config )
339            {
340            $result = $service->open( $config );
341
342            if( is_string( $result ) )
343                throw new Exception( $result );
344
345            return( true );
346        }
347
348        public static function configure( $config, $newConfig )
349        {
350            foreach( $newConfig as $key => $value )
351                $config[$key] = $value;
352
353            return( $config );
354            }
355
356        public static function dispatch( $dispatcher, $data, $optionsMap = false )
357        {
358//          if( $mappedTo )
359//              $data = array( $mappedTo => $data );
360//
361//          foreach( $data as $method => $params )
362//          {
363// //           foreach( $data[ $method ] as $name => $value )
364//          }
365//
366//          self::import( "$dispatcher.php" );
367        }
368
369        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
370        public static function service( $serviceName, $concept = false )
371        {
372            if( isset( self::$services[ $serviceName ] ) )
373                return self::$services[ $serviceName ];
374
375            if( !isset(self::$config[ $serviceName ]) )
376                 self::$config[ $serviceName ] = self::loadConfig( $serviceName, true );
377
378            if( !isset(self::$config[ $serviceName ]) )
379                return( false );
380
381            if( !isset(self::$config[ $serviceName ]['type']) )
382                self::$config[ $serviceName ]['type'] = 'service';
383
384            self::import( 'api/'.self::$config[ $serviceName ]['type'] );   //TODO: Item 4
385
386            $service = self::load( self::$config[ $serviceName ]['path'],
387                                   self::$config[ $serviceName ]['class'] );
388
389              $srvConfig = array();
390
391            if( isset(self::$config[ $serviceName ][ 'config' ]) )
392                $srvConfig = self::configure( $srvConfig, self::$config[ $serviceName ][ 'config' ] );
393            if( $wallet = self::wallet( $serviceName ) )
394                $srvConfig = self::configure( $srvConfig, $wallet );
395            if( $concept && isset(self::$config[ $concept ]['service.config']) )
396                $srvConfig = self::configure( $srvConfig, self::$config[ $concept ]['service.config'] );
397
398            if( empty( $srvConfig ) )
399                $srvConfig = false;
400
401            if( $service && self::$config[ $serviceName ]['type'] === 'service' )
402                self::connect( $service, $srvConfig );
403
404            return( self::$services[ $serviceName ] = $service );
405        }
406
407        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
408        public static function interceptor( $method, $concept = false, $serviceName = false, $isService = false )
409        {
410            if( $concept && !isset(self::$config[ $concept ]) )
411              self::$config[ $concept ] = self::loadConfig( $concept );
412
413            if( !$concept ) $concept = 'global';
414            if( !$isService || !$serviceName ) $serviceName = 'global';
415
416            if( !isset( self::$interceptors[ $concept ] ) )
417                self::$interceptors[ $concept ] = array();
418
419            if( !isset( self::$interceptors[ $concept ][ $serviceName ] ) )
420                self::$interceptors[ $concept ][ $serviceName ] = array();
421
422            if( !isset( self::$interceptors[ $concept ][ $serviceName ][ $method ] ) )
423            {
424                $events = array( 'before', 'after' );
425                $interceptors = array();
426
427                $prefix = ( $isService )? "$serviceName." : "";
428
429                foreach( $events as $i => $event )
430                {
431                    $interceptors[$event] = array();
432
433                    if( !isset(self::$config[$concept]["$prefix$event.$method"]) )
434                      continue;
435
436                    foreach( self::$config[$concept]["$prefix$event.$method"] as $intercept => $interceptor )
437                            $interceptors[$event][$intercept] = self::load( $interceptor );
438                }
439
440                self::$interceptors[ $concept ][ $serviceName ][ $method ] = $interceptors;
441            }
442
443            return( self::$interceptors[ $concept ][ $serviceName ][ $method ] );
444        }
445
446        public static function interceptorCommit( $eventType, $commitList, $isService = false )
447        {
448            $result = array( $eventType => array() );
449       
450            if( is_array( $commitList ) )
451                foreach( $commitList as $i => $tx )
452                {
453                    $interceptors = self::interceptor( 'commit', $tx['concept'], $tx['service'], $isService );
454     
455                    $result[$eventType] = array_merge( $result[$eventType], $interceptors[$eventType] );
456                }
457
458            return( $result );
459        }
460
461        public static function fire( $eventType, $method, &$params, $original, $isService = false )
462        {
463            if( $method === 'commit' )
464                $interceptors = self::interceptorCommit( $eventType, $params['criteria'], $isService );
465
466            else
467                $interceptors = self::interceptor( $method,
468                                                   isset($original['URI']['concept']) ? $original['URI']['concept'] : false,
469                                                   isset($params['URI']['service']) ? $params['URI']['service'] : false, $isService );
470
471            if( $interceptors && isset($interceptors[ $eventType ]) )
472                foreach( $interceptors[ $eventType ] as $intercept => $interceptor )
473                {
474                    $return = $interceptor->$intercept( $params['URI'], $params['properties'], $params['criteria'], $original /*, $params['service'] */);
475
476                    if( $return === false )
477                return( false );
478
479                    if( isset($return) )
480                        $params['properties'] = $return;
481                }
482
483              return( $params );
484        }
485
486        /*
487          * ex: array
488          *             (
489          *                     [0] array( 'OR', array( array( '=', 'campo', 'valor' ),
490                                                          array( 'OR', array( array( '=', 'campo', 'valor' ) ) ) )
491          *                     [1] array( '=', 'campo' , 'valor' )
492          *                     [2] array( 'OR' , array( array( '=' , campo', 'valor' ) ) )
493          *                     [3] array( 'IN', 'campo', array( '1' , '2' , '3' ) )
494          *             )
495          * OR
496          *         array( '=' , 'campo' , 'valor' )
497        */
498
499        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
500        public static function serviceName( $URI, $original = false )
501        {
502             $concept = "";
503
504            if( $original && isset($original['concept']) && $original['concept'] )
505                $concept = $original['concept'];
506            elseif( isset($URI['concept']) && $URI['concept'] )
507                $concept = $URI['concept'];
508
509            if( ( !isset($URI['service']) || !$URI['service'] ) && $concept )
510            {
511                if( !isset(self::$config[ $concept ]) )
512                    self::$config[ $concept ] = self::loadConfig( $concept );
513
514                $URI['service'] = self::$config[ $concept ][ 'service' ];
515            }
516
517            if( !isset($URI['service']) )
518                throw new Exception( "CONFIGURATION ERROR: service name from concept '$concept' not found" );
519
520            return( $URI );
521        }
522
523        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmos nas options passadas
524        public static function call( $method, $URI, $properties = false, $options = false, $service = false )
525        {
526            try
527            {
528                if( !isset($URI['concept']) ) $URI['concept'] = false;
529
530                $original = $params = array( 'properties' => $properties,
531                                             'criteria' => $options,
532                                             'URI' => $URI,
533                                             'service' => $service );
534
535                if( isset($params['URI']['concept'])  && !self::fire( 'before', $method, $params, $original ) )
536                    return( empty($params['properties']) ? false : $params['properties'] );
537
538               
539
540                if( $params && !$params['service'] )
541                {
542                    $params['URI'] = self::serviceName( $params['URI'], $original['URI'] );
543
544                    $params['service'] = self::service( $params['URI']['service'], $params['URI']['concept'] );
545                }
546
547                if( isset($params['URI']['service']) )
548                {
549                    if( $method === 'create' || $method === 'update' || $method === 'delete' )
550                    {
551                        if( $commit = !isset(self::$tx[ $params['URI']['service'] ])  )
552                        {
553                            self::call( 'begin', $params['URI'] );
554                        }
555
556                        $TX = array();
557                    }
558
559                    if( !self::fire( 'before', $method, $params, $original, true ) )
560                        return( empty($params['properties']) ? false : $params['properties'] );
561                }
562
563                if( $params['service'] )
564                    switch( $method )
565                    {
566                        case 'find': $return = $params['service']->find( $params['URI'], $params['properties'], $params['criteria'] ); break;
567
568                        case 'read': $return = $params['service']->read( $params['URI'], $params['properties'] , $params['criteria'] ); break;
569
570                        case 'create': $return = $params['service']->create( $params['URI'], $params['properties']/*, $criteria*/ ); break;
571
572                        case 'delete': $return = $params['service']->delete( $params['URI'], $params['properties'], $params['criteria'] ); break;
573
574                        case 'deleteAll': $return = $params['service']->deleteAll( $params['URI'], $params['properties'], $params['criteria'] ); break;
575
576                        case 'update': $return = $params['service']->update( $params['URI'], $params['properties'], $params['criteria'] ); break;
577
578                        case 'replace': $return = $params['service']->replace( $params['URI'], $params['properties'], $params['criteria'] ); break;
579
580                        case 'begin': $return = $params['service']->begin( $params['URI'] ); break;
581
582                        case 'commit': $return = $params['service']->commit( $params['URI'], $params['criteria'] ); break;
583
584                        case 'rollback': $return = $params['service']->rollback( $params['URI'], $params['criteria'] ); break;
585
586                        case 'parse': $return = $params['service']->parse( $params['properties'], $params['criteria'] ); break;
587
588                        case 'analize': $return = $params['service']->analize( $params['properties'], $params['criteria'] ); break;
589
590                        case 'format': $return = $params['service']->format( $params['properties'], $params['criteria'] ); break;
591
592                        default : $return = $params['service']->$method( $params['properties'], $params['criteria'] );
593                    }
594
595                if( isset($return) && $return !== false )
596                    $params['properties'] = $return;
597
598                if( isset($params['URI']['service']) )
599                    if( !self::fire( 'after', $method, $params, $original, true ) )
600                        return( empty($params['properties']) ? false : $params['properties'] );
601
602                if( isset($URI['concept']) )
603                    self::fire( 'after', $method, $params, $original );
604
605                if( empty($params['properties']) )
606                    $params['properties'] = false;
607
608                if( isset( $TX ) )
609                {
610                    $TX['rollback'] = !!!$params['properties'];
611
612                    if( $params['properties'] && is_array($params['properties']) && isset($params['properties']['id']) )
613                        $TX['id'] = $params['properties']['id'];
614
615                    self::$tx[ $params['URI']['service'] ][] = array_merge( $TX, $original['URI'], array( 'service' => $params['URI']['service'], 'method' => $method ) );
616
617                    if( isset($commit) && $commit )
618                    {
619                        if( !self::call( 'commit', $params['URI'], false, self::$tx[ $params['URI']['service'] ] ) )
620                            self::call( 'rollback', $params['URI'] , false, self::$tx[ $params['URI']['service'] ] );
621
622                        unset( self::$tx[ $params['URI']['service'] ] );
623                    }
624                }
625            }
626            catch( Exception $e )
627            {
628                if( !self::fallback( $e ) )
629                    self::closeAll();
630
631                return( false );
632            }
633
634            return( $params['properties'] );
635        }
636
637        public static function fallback( $exception )
638        {
639            $code = $exception->getCode();
640
641            if( isset( self::$fallbackHandlers[ $code ] ) )
642                {
643                        $fn = self::$fallbackHandlers[ $code ];
644                        return $fn( $exception );
645                }
646
647            error_log( $exception->getMessage() );
648            return( true );
649        }
650
651        public static function addFallbackHandler( $code, $function )
652        {
653            self::$fallbackHandlers[ $code ] = $function;
654        }
655        /*
656         *NULL evita erros caso não seja passado nenhuma variavel por referência
657        */
658        public static function put( $URI, $data, &$txIds = NULL )
659        {
660            try
661            {
662                $URI = self::serviceName( $URI );
663
664                if( $commit = !$txIds )
665                    $txIds = array();
666
667                if( !isset( self::$tx[ $URI['service'] ] ) )
668                {
669                    self::call( 'begin', $URI );
670                    self::$tx[ $txIds[] = $URI['service'] ] = array();
671                }
672
673                $method = $data ? isset( $data['id'] ) ?
674                          'update' : 'create' : 'delete';
675
676                $links = self::links( $URI['concept'] );
677
678                $order = self::$txID++;
679
680                $postpone = array();
681                $linkNames = array();
682
683                if( $data )
684                {
685                    $URI['id'] = isset( $data['id'] ) ? $data['id'] : false;
686
687                    foreach( $links as $linkName => $linkTarget )
688                    {
689                        if( isset( $data[$linkName] ) && is_array( $data[$linkName] ) )
690                        {
691                                if( self::isConcept( $URI['concept'], $linkName ) )
692                                    $data[$linkName] = self::put( array( 'concept' => $linkTarget ), $data[$linkName], $txIds );
693                            else
694                            {
695                                    $postpone[ $linkTarget ] =  $data[$linkName];
696                                    $linkNames[ $linkTarget ] = $linkName;
697                            }
698                        }
699                    }
700                }
701                else
702                  $URI['id'] = isset( $data['id'] ) ? $data['id'] : $URI['id'];
703
704                $result = Controller::call( $method, $URI, $data, false, false, true );
705
706                if( is_array( $result ) && isset( $result['id'] ) )
707                      $URI['id'] = $result['id'];
708
709                self::$tx[ $URI['service'] ][ count(self::$tx[ $URI['service'] ]) - 1 ]['order'] = $order;
710                self::$tx[ $URI['service'] ][ count(self::$tx[ $URI['service'] ]) - 1 ]['id'] = $URI['id'];
711
712                foreach( $postpone as $linkTarget => $dt )
713                {
714                      if( Controller::hasOne( $URI['concept'], $linkNames[ $linkTarget ] ) )
715                          $dt = array( $dt );
716
717                      foreach( $dt as $ii => $value )
718                      {
719                          if( !is_array( $value ) )
720                            $value = array( 'id' => $value );
721
722                          $value[ self::links( $URI['concept'], $linkNames[ $linkTarget ] ) ] = $URI['id'];
723 
724                          self::put( array( 'concept' => $linkTarget ), $value, $txIds );
725                      }
726                }
727                if( $commit )
728                {
729                      $result = array();
730
731                      for( $i = count( $txIds ) - 1; $i >= 0; $i-- )
732                      {
733                              $currentTx = self::$tx[ $txIds[$i] ];
734                              unset( self::$tx[ $txIds[$i] ] );
735
736                              if( !self::commit( array( 'service' => $txIds[$i] ), $currentTx ) )
737                              {
738                                  self::rollback( array( 'service' => $txIds[$i] ), $currentTx );
739
740                                  foreach( $currentTx as $i => $st )
741                                      $currentTx[$i][ 'rollback' ] = true;
742                              }
743
744                              $result = array_merge( $result, $currentTx );
745                      }
746
747                      self::$txID = 0;
748
749                      return( $result );
750                }
751
752            }
753            catch( Exception $e )
754            {
755                if( !self::fallback( $e ) )
756                    self::closeAll();
757
758                return( false );
759            }
760       
761            return( $URI['id'] );
762        }
763       
764        public static function get()
765        {
766       
767        }
768}
769
770Controller::$cache = Controller::loadCache();
771// ?>
Note: See TracBrowser for help on using the repository browser.