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

Exceptions

  • AmbiguousReferenceKeyException
  • MissingReferenceException
  • 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:      * Create conventional structure.
37:      * @param  string %s stands for table name
38:      * @param  string %1$s stands for key used after ->, %2$s for table name
39:      * @param  string %1$s stands for key used after ->, %2$s for table name
40:      */
41:     public function __construct($primary = 'id', $foreign = '%s_id', $table = '%s')
42:     {
43:         $this->primary = $primary;
44:         $this->foreign = $foreign;
45:         $this->table = $table;
46:     }
47: 
48: 
49:     public function getPrimary($table)
50:     {
51:         return sprintf($this->primary, $this->getColumnFromTable($table));
52:     }
53: 
54: 
55:     public function getHasManyReference($table, $key)
56:     {
57:         $table = $this->getColumnFromTable($table);
58:         return array(
59:             sprintf($this->table, $key, $table),
60:             sprintf($this->foreign, $table, $key),
61:         );
62:     }
63: 
64: 
65:     public function getBelongsToReference($table, $key)
66:     {
67:         $table = $this->getColumnFromTable($table);
68:         return array(
69:             sprintf($this->table, $key, $table),
70:             sprintf($this->foreign, $key, $table),
71:         );
72:     }
73: 
74: 
75:     public function setConnection(Connection $connection)
76:     {}
77: 
78: 
79:     protected function getColumnFromTable($name)
80:     {
81:         if ($this->table !== '%s' && preg_match('(^' . str_replace('%s', '(.*)', preg_quote($this->table)) . '\z)', $name, $match)) {
82:             return $match[1];
83:         }
84: 
85:         return $name;
86:     }
87: 
88: }
89: 
Nette Framework 2.0.12 (for PHP 5.2, un-prefixed) API API documentation generated by ApiGen 2.8.0