Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExpressionConverter.php
Go to the documentation of this file.
1 <?php
8 namespace Magento\Framework\DB;
9 
11 {
16 
22  protected static $_translateMap = [
23  'address' => 'addr',
24  'admin' => 'adm',
25  'attribute' => 'attr',
26  'enterprise' => 'ent',
27  'catalog' => 'cat',
28  'category' => 'ctgr',
29  'customer' => 'cstr',
30  'notification' => 'ntfc',
31  'product' => 'prd',
32  'session' => 'sess',
33  'user' => 'usr',
34  'entity' => 'entt',
35  'datetime' => 'dtime',
36  'decimal' => 'dec',
37  'varchar' => 'vchr',
38  'index' => 'idx',
39  'compare' => 'cmp',
40  'bundle' => 'bndl',
41  'option' => 'opt',
42  'gallery' => 'glr',
43  'media' => 'mda',
44  'value' => 'val',
45  'link' => 'lnk',
46  'title' => 'ttl',
47  'super' => 'spr',
48  'label' => 'lbl',
49  'website' => 'ws',
50  'aggregat' => 'aggr',
51  'minimal' => 'min',
52  'inventory' => 'inv',
53  'status' => 'sts',
54  'agreement' => 'agrt',
55  'layout' => 'lyt',
56  'resource' => 'res',
57  'directory' => 'dir',
58  'downloadable' => 'dl',
59  'element' => 'elm',
60  'fieldset' => 'fset',
61  'checkout' => 'chkt',
62  'newsletter' => 'nlttr',
63  'shipping' => 'shpp',
64  'calculation' => 'calc',
65  'search' => 'srch',
66  'query' => 'qr',
67  ];
68 
75  public static function shortName($name)
76  {
77  return strtr($name, self::$_translateMap);
78  }
79 
87  public static function addTranslate($from, $to)
88  {
89  self::$_translateMap[$from] = $to;
90  }
91 
100  public static function shortenEntityName($entityName, $prefix)
101  {
102  if (strlen($entityName) > self::MYSQL_IDENTIFIER_LEN) {
103  $shortName = ExpressionConverter::shortName($entityName);
104  if (strlen($shortName) > self::MYSQL_IDENTIFIER_LEN) {
105  $hash = md5($entityName);
106  if (strlen($prefix . $hash) > self::MYSQL_IDENTIFIER_LEN) {
107  $entityName = self::trimHash($hash, $prefix, self::MYSQL_IDENTIFIER_LEN);
108  } else {
109  $entityName = $prefix . $hash;
110  }
111  } else {
112  $entityName = $shortName;
113  }
114  }
115  return $entityName;
116  }
117 
126  private static function trimHash($hash, $prefix, $maxCharacters)
127  {
128  $diff = strlen($hash) + strlen($prefix) - $maxCharacters;
129  $superfluous = $diff / 2;
130  $odd = $diff % 2;
131  $hash = substr($hash, $superfluous, - ($superfluous + $odd));
132  return $hash;
133  }
134 }
static shortenEntityName($entityName, $prefix)
$prefix
Definition: name.phtml:25
if(!isset($_GET['name'])) $name
Definition: log.php:14