11<?php
2+ /*
3+ The InstallerInterface class defines the following methods (please see the source for the exact signature):
24
3- namespace detain \Composer ;
5+ supports(), here you test whether the passed type matches the name that you declared for this installer (see the example).
6+ isInstalled(), determines whether a supported package is installed or not.
7+ install(), here you can determine the actions that need to be executed upon installation.
8+ update(), here you define the behavior that is required when Composer is invoked with the update argument.
9+ uninstall(), here you can determine the actions that need to be executed when the package needs to be removed.
10+ getInstallPath(), this method should return the location where the package is to be installed, relative from the location of composer.json.
11+ */
12+
13+ namespace MyAdmin \Composer ;
414
515use Composer \Package \PackageInterface ;
616use Composer \Installer \LibraryInstaller ;
@@ -12,16 +22,12 @@ class TemplateInstaller extends LibraryInstaller
1222 */
1323 public function getInstallPath (PackageInterface $ package )
1424 {
15- $ prefix = substr ($ package ->getPrettyName (), 0 , 23 );
16- if ('myadmin/template- ' !== $ prefix ) {
17- throw new \InvalidArgumentException (
18- 'Unable to install template, myadmin templates '
19- .'should always start their package name with '
20- .'"myadmin/template-" '
21- );
22- }
23-
24- return 'data/templates/ ' .substr ($ package ->getPrettyName (), 23 );
25+ $ strip = 'myadmin/template- ' ;
26+ $ cut = strlen ($ strip ) - 1 ;
27+ $ prefix = substr ($ package ->getPrettyName (), 0 , $ cut );
28+ if ($ strip !== $ prefix )
29+ throw new \InvalidArgumentException ("Unable to install template, myadmin templates should always start their package name with ' {$ strip }' " );
30+ return 'public_html/templates/ ' .substr ($ package ->getPrettyName (), $ cut );
2531 }
2632
2733 /**
0 commit comments