Namespaces

  • 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

Exceptions

  • AmbiguousReferenceKeyException
  • MissingReferenceException
  • Overview
  • Namespace
  • 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:  */
11: 
12: namespace Nette\Database\Reflection;
13: 
14: use Nette;
15: 
16: 
17: /**
18:  * Reflection metadata class for a database.
19:  *
20:  * @author     Jakub Vrana
21:  * @author     Jan Skrasek
22:  * @property-write Nette\Database\Connection $connection
23:  */
24: class ConventionalReflection extends Nette\Object implements Nette\Database\IReflection
25: {
26:     /** @var string */
27:     protected $primary;
28: 
29:     /** @var string */
30:     protected $foreign;
31: 
32:     /** @var string */
33:     protected $table;
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:     public function getPrimary($table)
51:     {
52:         return sprintf($this->primary, $this->getColumnFromTable($table));
53:     }
54: 
55: 
56:     public function getHasManyReference($table, $key)
57:     {
58:         $table = $this->getColumnFromTable($table);
59:         return array(
60:             sprintf($this->table, $key, $table),
61:             sprintf($this->foreign, $table, $key),
62:         );
63:     }
64: 
65: 
66:     public function getBelongsToReference($table, $key)
67:     {
68:         $table = $this->getColumnFromTable($table);
69:         return array(
70:             sprintf($this->table, $key, $table),
71:             sprintf($this->foreign, $key, $table),
72:         );
73:     }
74: 
75: 
76:     public function setConnection(Nette\Database\Connection $connection)
77:     {}
78: 
79: 
80:     protected function getColumnFromTable($name)
81:     {
82:         if ($this->table !== '%s' && preg_match('(^' . str_replace('%s', '(.*)', preg_quote($this->table)) . '\z)', $name, $match)) {
83:             return $match[1];
84:         }
85: 
86:         return $name;
87:     }
88: 
89: }
90: 
Nette Framework 2.0.11 API API documentation generated by ApiGen 2.8.0