Nooku Framework is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

nooku-framework

Commit 2194

User picture
  • Author: johanjanssens
  • 2010-06-12 17:33 (almost 4 years ago)

re #3 : Added KDatabaseTable::getBehavior function. Re-worked addBehaviors function to store behavior instances in the table metadata object. Both getBehavior and getBehaviors will return an behavior instance and not an identifier.

Files Affected

 
21932194
406
        if(!isset($this->_mixed_methods[$method])) 
406
        if(!isset($this->_mixed_methods[$method])) 
407
        {
407
        {
408
            foreach(KFactory::get($this->getTable())->getBehaviors() as $behavior) {
408
            foreach(KFactory::get($this->getTable())->getBehaviors() as $behavior) {
409
                $this->mixin(KFactory::get($behavior));
409
                $this->mixin($behavior);
410
            }
410
            }
411
        }
411
        }
412
 
412
 
21932194
353
        if(!isset($this->_mixed_methods[$method]))
353
        if(!isset($this->_mixed_methods[$method]))
354
        {
354
        {
355
            foreach(KFactory::get($this->getTable())->getBehaviors() as $behavior) {
355
            foreach(KFactory::get($this->getTable())->getBehaviors() as $behavior) {
356
                $this->mixin(KFactory::get($behavior));
356
                $this->mixin($behavior);
357
            }
357
            }
358
        }
358
        }
359
 
359
 
21932194
250
     */
250
     */
251
     public function addBehaviors(array $behaviors)
251
     public function addBehaviors(array $behaviors)
252
     {
252
     {
253
         $result = array();
 
 
254
         foreach($behaviors as $behavior)
253
         foreach($behaviors as $behavior)
255
        {
254
        {
256
            if(!($behavior instanceof KDatabaseBehaviorInterface)) {
255
            if(!($behavior instanceof KDatabaseBehaviorInterface)) 
257
                $behavior = KDatabaseBehavior::factory($behavior);
256
            {
 
 
257
                $identifier = (string) $behavior;
 
 
258
                $behavior   = KDatabaseBehavior::factory($behavior);
258
            }
259
            }
 
 
260
            else $identifier = (string) $behavior->getIdentifier();
259
 
261
 
260
            //Get the identifier
262
            //Set the behaviors in the database schema
261
            $identifier = $behavior->getIdentifier();
263
            $this->getInfo()->behaviors[$identifier] = $behavior;
262
 
264
                        
263
            $name = (string) $identifier;
 
 
264
            $result[$name] = $identifier; 
 
 
265
                    
 
 
266
            //Enqueue the behavior in the command chain
265
            //Enqueue the behavior in the command chain
267
            $this->getCommandChain()->enqueue($behavior, $behavior->getPriority());
266
            $this->getCommandChain()->enqueue($behavior, $behavior->getPriority());
268
        }
267
        }
269
 
268
 
270
        //Set the behaviors in the database schema
 
 
271
        $this->getInfo()->behaviors = array_merge($this->getInfo()->behaviors, $result);
 
 
272
 
269
 
 
 
270
 
273
        return $this;
271
        return $this;
274
     }
272
     }
275
 
273
 
...
 
...
 
282
    {
280
    {
283
        return $this->getInfo()->behaviors;
281
        return $this->getInfo()->behaviors;
284
     }
282
     }
 
 
283
 
 
 
284
    /**
 
 
285
     * Get a filter by identifier
 
 
286
     *
 
 
287
     * @return array    An asscociate array of filters keys are the filter identifiers
 
 
288
     */
 
 
289
     public function getBehavior($identifier)
 
 
290
     {
 
 
291
         return isset($this->getInfo()->behaviors[$identifier]) ? $this->getInfo()->behaviors[$identifier] : null;
 
 
292
     }
285
 
293
 
286
    /**
294
    /**
287
     * Gets the schema of the table
295
     * Gets the schema of the table