2121use Symfony \Component \Filesystem \Filesystem ;
2222
2323/**
24- * Command to check and create bootstrap symlink into MopaBootstrapBundle
24+ * Command to check and create bootstrap symlink into MopaBootstrapBundle.
2525 *
2626 * @author phiamo <[email protected] > 2727 */
2828abstract class BaseBootstrapSymlinkCommand extends ContainerAwareCommand
2929{
30- public static $ mopaBootstrapBundleName = " mopa/bootstrap-bundle " ;
30+ public static $ mopaBootstrapBundleName = ' mopa/bootstrap-bundle ' ;
3131 public static $ targetSuffix = '' ;
3232 public static $ pathName = 'TwitterBootstrap ' ;
3333 /**
@@ -42,19 +42,19 @@ abstract class BaseBootstrapSymlinkCommand extends ContainerAwareCommand
4242 /**
4343 * Checks symlink's existence.
4444 *
45- * @param string $symlinkTarget The Target
46- * @param string $symlinkName The Name
47- * @param boolean $forceSymlink Force to be a link or throw exception
45+ * @param string $symlinkTarget The Target
46+ * @param string $symlinkName The Name
47+ * @param bool $forceSymlink Force to be a link or throw exception
4848 *
49- * @return boolean
49+ * @return bool
5050 *
5151 * @throws \Exception
5252 */
5353 public static function checkSymlink ($ symlinkTarget , $ symlinkName , $ forceSymlink = false )
5454 {
5555 if ($ forceSymlink && file_exists ($ symlinkName ) && !is_link ($ symlinkName )) {
56- if (" link " != filetype ($ symlinkName )) {
57- throw new \Exception ($ symlinkName ." exists and is no link! " );
56+ if (' link ' != filetype ($ symlinkName )) {
57+ throw new \Exception ($ symlinkName .' exists and is no link! ' );
5858 }
5959 } elseif (is_link ($ symlinkName )) {
6060 $ linkTarget = readlink ($ symlinkName );
@@ -88,7 +88,7 @@ public static function checkSymlink($symlinkTarget, $symlinkName, $forceSymlink
8888 public static function createSymlink ($ symlinkTarget , $ symlinkName )
8989 {
9090 if (false === @symlink ($ symlinkTarget , $ symlinkName )) {
91- throw new \Exception (" An error occurred while creating symlink " .$ symlinkName );
91+ throw new \Exception (' An error occurred while creating symlink ' .$ symlinkName );
9292 }
9393 if (false === $ target = readlink ($ symlinkName )) {
9494 throw new \Exception ("Symlink $ symlinkName points to target $ target " );
@@ -106,18 +106,18 @@ public static function createSymlink($symlinkTarget, $symlinkName)
106106 public static function createMirror ($ symlinkTarget , $ symlinkName )
107107 {
108108 if (strlen ($ symlinkTarget ) == 0 || empty ($ symlinkTarget )) {
109- throw new \Exception (" symlinkTarget empty! " .var_export ($ symlinkTarget , true ));
109+ throw new \Exception (' symlinkTarget empty! ' .var_export ($ symlinkTarget , true ));
110110 }
111111 if (strlen ($ symlinkName ) == 0 || empty ($ symlinkName )) {
112- throw new \Exception (" symlinkName empty! " .var_export ($ symlinkName , true ));
112+ throw new \Exception (' symlinkName empty! ' .var_export ($ symlinkName , true ));
113113 }
114114 $ filesystem = new Filesystem ();
115115 $ filesystem ->mkdir ($ symlinkName );
116116 $ filesystem ->mirror (
117117 $ symlinkName .DIRECTORY_SEPARATOR .'.. ' .DIRECTORY_SEPARATOR .$ symlinkTarget ,
118118 $ symlinkName ,
119119 null ,
120- array ( 'copy_on_windows ' => true , 'delete ' => true , 'override ' => true )
120+ [ 'copy_on_windows ' => true , 'delete ' => true , 'override ' => true ]
121121 );
122122 }
123123
@@ -127,7 +127,7 @@ public static function createMirror($symlinkTarget, $symlinkName)
127127 protected function configure ()
128128 {
129129 $ this
130- ->setDescription (" Check and if possible install symlink to " .static ::$ targetSuffix )
130+ ->setDescription (' Check and if possible install symlink to ' .static ::$ targetSuffix )
131131 ->addArgument ('pathTo ' .static ::$ pathName , InputArgument::OPTIONAL , 'Where is twitters/bootstrap located? ' )
132132 ->addArgument ('pathToMopaBootstrapBundle ' , InputArgument::OPTIONAL , 'Where is MopaBootstrapBundle located? ' )
133133 ->addOption ('force ' , 'f ' , InputOption::VALUE_NONE , 'Force rewrite of existing symlink if possible! ' )
@@ -137,7 +137,7 @@ protected function configure()
137137 }
138138
139139 /**
140- * Get Package involved
140+ * Get Package involved.
141141 *
142142 * @return string Name of twbs package
143143 */
@@ -154,46 +154,46 @@ protected function execute(InputInterface $input, OutputInterface $output)
154154 if ($ input ->getOption ('manual ' )) {
155155 list ($ symlinkTarget , $ symlinkName ) = $ this ->getBootstrapPathsFromUser ();
156156 } elseif (false !== $ composer = ComposerAdapter::getComposer ($ input , $ output )) {
157- $ targetPath = $ this ->getContainer ()->getParameter (" mopa_bootstrap.bootstrap.install_path " );
157+ $ targetPath = $ this ->getContainer ()->getParameter (' mopa_bootstrap.bootstrap.install_path ' );
158158 $ cmanager = new ComposerPathFinder ($ composer );
159- $ options = array (
159+ $ options = [
160160 'targetSuffix ' => DIRECTORY_SEPARATOR .$ targetPath .static ::$ targetSuffix ,
161161 'sourcePrefix ' => '.. ' .DIRECTORY_SEPARATOR .'.. ' .DIRECTORY_SEPARATOR ,
162- ) ;
162+ ] ;
163163 list ($ symlinkTarget , $ symlinkName ) = $ cmanager ->getSymlinkFromComposer (
164164 self ::$ mopaBootstrapBundleName ,
165165 $ this ->getTwitterBootstrapName (),
166166 $ options
167167 );
168168 } else {
169- $ this ->output ->writeln (" <error>Could not find composer and manual option not specified!</error> " );
169+ $ this ->output ->writeln (' <error>Could not find composer and manual option not specified!</error> ' );
170170
171171 return ;
172172 }
173173
174174 // Automatically detect if on Win XP where symlink will allways fail
175- if ($ input ->getOption ('no-symlink ' ) || PHP_OS == " WINNT " ) {
176- $ this ->output ->write (" Checking destination " );
175+ if ($ input ->getOption ('no-symlink ' ) || PHP_OS == ' WINNT ' ) {
176+ $ this ->output ->write (' Checking destination ' );
177177
178178 if (true === self ::checkSymlink ($ symlinkTarget , $ symlinkName )) {
179- $ this ->output ->writeln (" ... <comment>symlink already exists</comment> " );
179+ $ this ->output ->writeln (' ... <comment>symlink already exists</comment> ' );
180180 } else {
181- $ this ->output ->writeln (" ... <comment>not existing</comment> " );
182- $ this ->output ->writeln (sprintf (" Mirroring to: %s " , $ symlinkName ));
183- $ this ->output ->write (sprintf (" from target: %s " , realpath ($ symlinkName .DIRECTORY_SEPARATOR .'.. ' .DIRECTORY_SEPARATOR .$ symlinkTarget )));
181+ $ this ->output ->writeln (' ... <comment>not existing</comment> ' );
182+ $ this ->output ->writeln (sprintf (' Mirroring to: %s ' , $ symlinkName ));
183+ $ this ->output ->write (sprintf (' from target: %s ' , realpath ($ symlinkName .DIRECTORY_SEPARATOR .'.. ' .DIRECTORY_SEPARATOR .$ symlinkTarget )));
184184 self ::createMirror ($ symlinkTarget , $ symlinkName );
185185 }
186186 } else {
187- $ this ->output ->write (" Checking symlink " );
187+ $ this ->output ->write (' Checking symlink ' );
188188 if (false === self ::checkSymlink ($ symlinkTarget , $ symlinkName , true )) {
189- $ this ->output ->writeln (" ... <comment>not existing</comment> " );
190- $ this ->output ->writeln (" Creating symlink: " .$ symlinkName );
191- $ this ->output ->write (" for target: " .$ symlinkTarget );
189+ $ this ->output ->writeln (' ... <comment>not existing</comment> ' );
190+ $ this ->output ->writeln (' Creating symlink: ' .$ symlinkName );
191+ $ this ->output ->write (' for target: ' .$ symlinkTarget );
192192 self ::createSymlink ($ symlinkTarget , $ symlinkName );
193193 }
194194 }
195195
196- $ this ->output ->writeln (" ... <info>OK</info> " );
196+ $ this ->output ->writeln (' ... <info>OK</info> ' );
197197 }
198198
199199 protected function getBootstrapPathsFromUser ()
@@ -202,28 +202,28 @@ protected function getBootstrapPathsFromUser()
202202 $ symlinkName = $ this ->input ->getArgument ('pathToMopaBootstrapBundle ' );
203203
204204 if (empty ($ symlinkName )) {
205- throw new \Exception (" pathToMopaBootstrapBundle not specified " );
205+ throw new \Exception (' pathToMopaBootstrapBundle not specified ' );
206206 }
207207
208208 if (!is_dir (dirname ($ symlinkName ))) {
209- throw new \Exception (" pathToMopaBootstrapBundle: " .dirname ($ symlinkName )." does not exist " );
209+ throw new \Exception (' pathToMopaBootstrapBundle: ' .dirname ($ symlinkName ).' does not exist ' );
210210 }
211211
212212 if (empty ($ symlinkTarget )) {
213- throw new \Exception (static ::$ pathName ." not specified " );
213+ throw new \Exception (static ::$ pathName .' not specified ' );
214214 }
215215
216- if (substr ($ symlinkTarget , 0 , 1 ) == " / " ) {
217- $ this ->output ->writeln (" <comment>Try avoiding absolute paths, for portability!</comment> " );
216+ if (substr ($ symlinkTarget , 0 , 1 ) == ' / ' ) {
217+ $ this ->output ->writeln (' <comment>Try avoiding absolute paths, for portability!</comment> ' );
218218 if (!is_dir ($ symlinkTarget )) {
219- throw new \Exception (" Target path " .$ symlinkTarget ." is not a directory! " );
219+ throw new \Exception (' Target path ' .$ symlinkTarget .' is not a directory! ' );
220220 }
221221 } else {
222- $ symlinkTarget = $ symlinkName .DIRECTORY_SEPARATOR ." .. " .DIRECTORY_SEPARATOR .$ symlinkTarget ;
222+ $ symlinkTarget = $ symlinkName .DIRECTORY_SEPARATOR .' .. ' .DIRECTORY_SEPARATOR .$ symlinkTarget ;
223223 }
224224
225225 if (!is_dir ($ symlinkTarget )) {
226- throw new \Exception (static ::$ pathName ." would resolve to: " .$ symlinkTarget ."\n and this is not reachable from \npathToMopaBootstrapBundle: " .dirname ($ symlinkName ));
226+ throw new \Exception (static ::$ pathName .' would resolve to: ' .$ symlinkTarget ."\n and this is not reachable from \npathToMopaBootstrapBundle: " .dirname ($ symlinkName ));
227227 }
228228
229229 $ dialog = $ this ->getHelperSet ()->get ('dialog ' );
@@ -232,16 +232,16 @@ protected function getBootstrapPathsFromUser()
232232Pointing to: $ symlinkTarget
233233EOF
234234 ;
235- $ this ->output ->writeln (array (
235+ $ this ->output ->writeln ([
236236 '' ,
237237 $ this ->getHelperSet ()->get ('formatter ' )->formatBlock ($ text , 'bg=blue;fg=white ' , true ),
238238 '' ,
239- ) );
239+ ] );
240240
241241 if ($ this ->input ->isInteractive () && !$ dialog ->askConfirmation ($ this ->output , '<question>Should this link be created? (y/n)</question> ' , false )) {
242- throw new \Exception (" Aborting due to User not cofirming! " );
242+ throw new \Exception (' Aborting due to User not cofirming! ' );
243243 }
244244
245- return array ( $ symlinkTarget , $ symlinkName) ;
245+ return [ $ symlinkTarget , $ symlinkName] ;
246246 }
247247}
0 commit comments