Map-based autoloader across php and phar resources

⌈⌋ branch:  Canonic Autoloader


Hex Artifact Content

Artifact 7e8b9b024b298f742df5ddfea04bb1c94181f7a9:

  • Executable file mk — part of check-in [18e74838b1] at 2015-01-22 21:58:36 on branch trunk — Build in trigger script for DPKG and RPM (untested). (user: mario size: 1523)

0000: 23 21 2f 62 69 6e 2f 73 68 0a 0a 0a 23 2d 2d 20  #!/bin/sh...#-- 
0010: 62 75 6d 70 20 76 65 72 73 69 6f 6e 0a 56 45 52  bump version.VER
0020: 53 49 4f 4e 3d 24 28 76 65 72 73 69 6f 6e 20 20  SION=$(version  
0030: 72 65 61 64 20 73 74 75 62 2e 70 68 70 20 20 62  read stub.php  b
0040: 75 6d 70 20 73 68 6f 77 20 20 77 72 69 74 65 3a  ump show  write:
0050: 3a 32 20 73 74 75 62 2e 70 68 70 29 0a 0a 23 2d  :2 stub.php)..#-
0060: 2d 20 63 72 65 61 74 65 20 70 6c 61 69 6e 20 70  - create plain p
0070: 68 61 72 0a 78 70 6d 20 2d 73 20 73 72 63 20 2d  har.xpm -s src -
0080: 74 20 70 68 61 72 20 2d 2d 70 68 61 72 2d 66 6f  t phar --phar-fo
0090: 72 6d 61 74 20 7a 69 70 2d 67 7a 20 2d 2d 70 68  rmat zip-gz --ph
00a0: 61 72 2d 73 74 75 62 20 73 74 75 62 2e 70 68 70  ar-stub stub.php
00b0: 20 2d 2d 70 68 61 72 2d 78 20 2d 66 20 73 74 75   --phar-x -f stu
00c0: 62 2e 70 68 70 0a 0a 23 20 74 65 73 74 20 75 70  b.php..# test up
00d0: 64 61 74 65 20 63 6c 61 73 73 6d 61 70 0a 6c 6e  date classmap.ln
00e0: 20 2d 66 20 73 68 61 72 65 64 2e 70 68 61 72 20   -f shared.phar 
00f0: 73 69 6e 67 6c 65 2f 0a 70 68 70 20 73 69 6e 67  single/.php sing
0100: 6c 65 2f 73 68 61 72 65 64 2e 70 68 61 72 0a 0a  le/shared.phar..
0110: 23 2d 2d 20 64 65 62 20 2b 20 72 70 6d 0a 78 70  #-- deb + rpm.xp
0120: 6d 20 2d 73 20 64 69 72 20 2d 75 20 6d 61 6e 20  m -s dir -u man 
0130: 2d 74 20 64 65 62 2c 72 70 6d 20 2d 66 20 2d 76  -t deb,rpm -f -v
0140: 20 24 56 45 52 53 49 4f 4e 20 2d 6e 20 70 68 70   $VERSION -n php
0150: 2d 73 68 61 72 65 64 2d 61 75 74 6f 6c 6f 61 64  -shared-autoload
0160: 65 72 20 2d 61 20 61 6c 6c 20 5c 0a 2d 2d 64 65  er -a all \.--de
0170: 73 63 72 69 70 74 69 6f 6e 20 22 43 61 6e 6f 6e  scription "Canon
0180: 69 63 20 41 75 74 6f 6c 6f 61 64 65 72 20 2f 20  ic Autoloader / 
0190: 73 68 61 72 65 64 2e 70 68 61 72 0a 50 72 6f 76  shared.phar.Prov
01a0: 69 64 65 73 20 61 20 75 6e 69 66 69 65 64 20 61  ides a unified a
01b0: 75 74 6f 6c 6f 61 64 65 72 20 66 6f 72 20 2f 75  utoloader for /u
01c0: 73 72 2f 73 68 61 72 65 2f 70 68 70 2e 20 49 74  sr/share/php. It
01d0: 20 73 63 61 6e 73 20 69 64 65 6e 74 69 66 69 65   scans identifie
01e0: 72 73 0a 69 6e 20 70 68 70 20 73 63 72 69 70 74  rs.in php script
01f0: 73 2c 20 62 75 74 20 61 6c 73 6f 20 6d 61 6b 65  s, but also make
0200: 73 20 70 68 61 72 20 63 6f 6c 6c 65 63 74 69 6f  s phar collectio
0210: 6e 73 20 66 69 72 73 74 20 63 6c 61 73 73 20 63  ns first class c
0220: 69 74 69 7a 65 6e 73 2e 0a 49 74 27 73 20 65 61  itizens..It's ea
0230: 73 69 6c 79 20 75 73 65 64 20 66 72 6f 6d 20 50  sily used from P
0240: 48 50 3a 0a 0a 20 20 20 69 6e 63 6c 75 64 65 5f  HP:..   include_
0250: 6f 6e 63 65 28 27 73 68 61 72 65 64 2e 70 68 61  once('shared.pha
0260: 72 27 29 3b 0a 0a 49 74 20 63 6f 6d 65 73 20 77  r');..It comes w
0270: 69 74 68 20 61 20 63 75 73 74 6f 6d 20 74 72 69  ith a custom tri
0280: 67 67 65 72 20 66 6f 72 20 61 75 74 6f 75 70 64  gger for autoupd
0290: 61 74 69 6e 67 20 74 68 65 20 63 6c 61 73 73 6d  ating the classm
02a0: 61 70 20 6f 6e 20 64 70 6b 67 0a 69 6e 73 74 61  ap on dpkg.insta
02b0: 6c 6c 61 74 69 6f 6e 2c 20 61 6e 64 20 66 61 6c  llation, and fal
02c0: 6c 73 20 62 61 63 6b 20 6f 6e 20 27 70 68 70 61  ls back on 'phpa
02d0: 62 27 20 67 65 6e 65 72 61 74 69 6f 6e 20 69 66  b' generation if
02e0: 20 61 76 61 69 6c 61 62 6c 65 2e 20 43 6c 61 73   available. Clas
02f0: 73 0a 69 64 65 6e 74 69 66 69 65 72 73 20 61 72  s.identifiers ar
0300: 65 20 6d 61 74 63 68 65 64 20 63 61 73 65 2d 69  e matched case-i
0310: 6e 73 65 6e 73 69 74 69 76 65 6c 79 20 28 61 73  nsensitively (as
0320: 20 50 48 50 20 65 78 70 65 63 74 73 20 69 74 29   PHP expects it)
0330: 2e 0a 41 6c 73 6f 20 69 74 27 73 20 70 72 65 70  ..Also it's prep
0340: 61 72 69 6e 67 20 66 6f 72 20 68 74 74 70 73 3a  aring for https:
0350: 2f 2f 77 69 6b 69 2e 70 68 70 2e 6e 65 74 2f 72  //wiki.php.net/r
0360: 66 63 2f 66 75 6e 63 74 69 6f 6e 5f 61 75 74 6f  fc/function_auto
0370: 6c 6f 61 64 69 6e 67 0a 69 6e 20 61 6e 79 20 66  loading.in any f
0380: 75 74 75 72 65 20 50 48 50 20 76 65 72 73 69 6f  uture PHP versio
0390: 6e 2e 0a 0a 54 68 65 20 73 68 61 72 65 64 20 61  n...The shared a
03a0: 75 74 6f 6c 6f 61 64 65 72 20 69 73 20 73 65 6c  utoloader is sel
03b0: 66 2d 63 6f 6e 74 61 69 6e 65 64 20 69 6e 20 61  f-contained in a
03c0: 20 70 68 61 72 20 66 69 6c 65 2c 20 77 68 69 63   phar file, whic
03d0: 68 20 65 61 73 65 73 0a 63 6f 70 79 69 6e 67 20  h eases.copying 
03e0: 69 74 20 6f 6e 74 6f 20 61 6e 64 20 75 73 65 64  it onto and used
03f0: 20 69 6e 20 6c 6f 63 61 6c 20 70 72 6f 6a 65 63   in local projec
0400: 74 20 64 69 72 65 63 74 6f 72 69 65 73 20 61 73  t directories as
0410: 20 77 65 6c 6c 2e 20 43 61 6e 20 62 65 0a 73 70   well. Can be.sp
0420: 6c 69 74 20 75 70 20 69 6e 74 6f 20 69 74 73 20  lit up into its 
0430: 69 6e 64 69 76 69 64 75 61 6c 20 73 63 72 69 70  individual scrip
0440: 74 73 20 28 61 75 74 6f 6c 6f 61 64 65 72 2c 20  ts (autoloader, 
0450: 75 70 64 61 74 65 72 2c 20 63 6c 61 73 73 6d 61  updater, classma
0460: 70 29 0a 74 68 6f 75 67 68 2e 22 20 5c 0a 2d 2d  p).though." \.--
0470: 75 72 6c 20 27 68 74 74 70 3a 2f 2f 66 6f 73 73  url 'http://foss
0480: 69 6c 2e 69 6e 63 6c 75 64 65 2d 6f 6e 63 65 2e  il.include-once.
0490: 6f 72 67 2f 63 61 6e 6f 6e 69 63 27 20 2d 2d 63  org/canonic' --c
04a0: 61 74 65 67 6f 72 79 20 27 70 68 70 27 20 2d 2d  ategory 'php' --
04b0: 76 65 6e 64 6f 72 20 27 69 6f 27 20 2d 2d 6d 61  vendor 'io' --ma
04c0: 69 6e 74 61 69 6e 65 72 20 27 6d 61 72 69 6f 23  intainer 'mario#
04d0: 69 6e 63 6c 75 64 65 2d 6f 6e 63 65 3a 6f 72 67  include-once:org
04e0: 27 20 5c 0a 2d 2d 64 65 70 65 6e 64 73 20 70 68  ' \.--depends ph
04f0: 70 35 2d 63 6f 6d 6d 6f 6e 20 2d 2d 64 65 62 2d  p5-common --deb-
0500: 73 75 67 67 65 73 74 73 20 70 68 70 61 62 20 5c  suggests phpab \
0510: 0a 2d 2d 64 65 62 2d 69 6e 74 65 72 65 73 74 20  .--deb-interest 
0520: 2f 75 73 72 2f 73 68 61 72 65 2f 70 68 70 2f 20  /usr/share/php/ 
0530: 2d 2d 61 66 74 65 72 2d 69 6e 73 74 61 6c 6c 3d  --after-install=
0540: 64 65 62 5f 72 70 6d 5f 74 72 69 67 67 65 72 20  deb_rpm_trigger 
0550: 5c 0a 2d 2d 72 70 6d 2d 74 72 69 67 67 65 72 2d  \.--rpm-trigger-
0560: 61 66 74 65 72 2d 69 6e 73 74 61 6c 6c 20 27 5b  after-install '[
0570: 2d 66 20 5e 2e 2f 75 73 72 2f 73 68 61 72 65 2f  -f ^./usr/share/
0580: 70 68 70 2f 5d 3a 20 64 65 62 5f 72 70 6d 5f 74  php/]: deb_rpm_t
0590: 72 69 67 67 65 72 27 20 5c 0a 73 68 61 72 65 64  rigger' \.shared
05a0: 2e 70 68 61 72 3d 2f 75 73 72 2f 73 68 61 72 65  .phar=/usr/share
05b0: 2f 70 68 70 2f 73 68 61 72 65 64 2e 70 68 61 72  /php/shared.phar
05c0: 20 5c 0a 6d 61 6e 70 61 67 65 2e 31 3d 2f 75 73   \.manpage.1=/us
05d0: 72 2f 73 68 61 72 65 2f 6d 61 6e 2f 6d 61 6e 31  r/share/man/man1
05e0: 2f 73 68 61 72 65 64 2e 70 68 61 72 2e 31 20 5c  /shared.phar.1 \
05f0: 0a 0a 0a                                         ...