Packages

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • None
  • PHP

Classes

  • ConventionalReflection
  • DiscoveredReflection
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (http://nette.org)
 5:  *
 6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 7:  *
 8:  * For the full copyright and license information, please view
 9:  * the file license.txt that was distributed with this source code.
10:  * @package Nette\Database\Reflection
11:  */
12: 
13: 
14: 
15: /**
16:  * Reflection metadata class for a database.
17:  *
18:  * @author     Jakub Vrana
19:  * @author     Jan Skrasek
20:  * @property-write Connection $connection
21:  * @package Nette\Database\Reflection
22:  */
23: class ConventionalReflection extends Object implements IReflection
24: {
25:     /** @var string */
26:     protected $primary;
27: 
28:     /** @var string */
29:     protected $foreign;
30: 
31:     /** @var string */
32:     protected $table;
33: 
34: 
35: 
36:     /**
37:      * Create conventional structure.
38:      * @param  string %s stands for table name
39:      * @param  string %1$s stands for key used after ->, %2$s for table name
40:      * @param  string %1$s stands for key used after ->, %2$s for table name
41:      */
42:     public function __construct($primary = 'id', $foreign = '%s_id', $table = '%s')
43:     {
44:         $this->primary = $primary;
45:         $this->foreign = $foreign;
46:         $this->table = $table;
47:     }
48: 
49: 
50: 
51:     public function getPrimary($table)
52:     {
53:         return sprintf($this->primary, $this->getColumnFromTable($table));
54:     }
55: 
56: 
57: 
58:     public function getHasManyReference($table, $key)
59:     {
60:         $table = $this->getColumnFromTable($table);
61:         return array(
62:             sprintf($this->table, $key, $table),
63:             sprintf($this->foreign, $table, $key),
64:         );
65:     }
66: 
67: 
68: 
69:     public function getBelongsToReference($table, $key)
70:     {
71:         $table = $this->getColumnFromTable($table);
72:         return array(
73:             sprintf($this->table, $key, $table),
74:             sprintf($this->foreign, $key, $table),
75:         );
76:     }
77: 
78: 
79: 
80:     public function setConnection(Connection $connection)
81:     {}
82: 
83: 
84: 
85:     protected function getColumnFromTable($name)
86:     {
87:         if ($this->table !== '%s' && preg_match('(^' . str_replace('%s', '(.*)', preg_quote($this->table)) . '\z)', $name, $match)) {
88:             return $match[1];
89:         }
90: 
91:         return $name;
92:     }
93: 
94: }
95: 
Nette Framework 2.0.7 (for PHP 5.2, un-prefixed) API API documentation generated by ApiGen 2.8.0