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

Classes

Exceptions

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