44
55use League \Container \ContainerAwareInterface ;
66use League \Container \ContainerAwareTrait ;
7+ use Pantheon \Terminus \Exceptions \TerminusException ;
8+ use Pantheon \Terminus \Exceptions \TerminusNotFoundException ;
79use Pantheon \Terminus \Helpers \Composer \ComposerFile ;
810use Pantheon \Terminus \Exceptions \ComposerInstallException ;
911use Pantheon \Terminus \Helpers \Traits \CommandExecutorTrait ;
@@ -30,6 +32,9 @@ class Directory implements ContainerAwareInterface, IOAwareInterface, SiteAwareI
3032 use IO ;
3133 use SiteAwareTrait;
3234
35+ /**
36+ * @var
37+ */
3338 protected $ site ;
3439
3540 /**
@@ -51,10 +56,7 @@ class Directory implements ContainerAwareInterface, IOAwareInterface, SiteAwareI
5156 */
5257 public function __construct ($ site )
5358 {
54- if (is_string ($ site )) {
55- $ site = $ this ->getSite ($ site );
56- }
57- $ this ->site = $ site ;
59+ $ this ->setSource ($ site );
5860 }
5961
6062 /**
@@ -77,9 +79,9 @@ public static function delTree($dir): bool
7779 /**
7880 * @throws \Exception
7981 */
80- public function ensure (bool $ create = false )
82+ public function ensureLocalCopyOfRepo (bool $ create = false )
8183 {
82- $ valid = $ this ->getSource ()->valid ();
84+ $ valid = $ this ->getSource ()->valid () ?? false ;
8385 if ($ valid === false ) {
8486 // if site doesn't exist
8587 if ($ create === true ) {
@@ -91,11 +93,11 @@ public function ensure(bool $create = false)
9193 }
9294 $ this ->clonePath = new \SplFileInfo (
9395 $ this ->getDefaultClonePathBase () .
94- DIRECTORY_SEPARATOR . $ this ->getSource ()->getSiteInfo ()-> getName ()
96+ DIRECTORY_SEPARATOR . $ this ->getSource ()->getName ()
9597 );
9698 if (!$ this ->clonePath ->isDir ()) {
9799 // -oStrictHostKeyChecking=no
98- $ this ->getSource ()->cloneFiles ( $ this -> getOutput () );
100+ $ this ->getSource ()->cloneLocalCopy ( );
99101 }
100102
101103 $ this ->setComposerFile ();
@@ -184,12 +186,12 @@ public function install()
184186 {
185187 is_file ($ this ->clonePath . "/composer.lock " ) ?
186188 unlink ($ this ->clonePath . "/composer.lock " ) : [];
187- $ this ->execute ("rm -Rf %s && cd %s && composer upgrade --with-dependencies " , [
189+ $ result = $ this ->execute ("rm -Rf %s && cd %s && composer upgrade --with-dependencies " , [
188190 $ this ->clonePath . "/vendor " ,
189191 $ this ->clonePath
190192 ]);
191193 if ($ this ->execResult [0 ] !== 0 ) {
192- throw new ComposerInstallException ($ result , $ output );
194+ throw new ComposerInstallException ($ result , $ this -> output () );
193195 }
194196 return $ result ;
195197 }
@@ -239,10 +241,13 @@ public function ensureCustomCodeFoldersExist(InputInterface $input, OutputInterf
239241 }
240242 }
241243
244+ /**
245+ * @return string
246+ */
242247 public function getDefaultClonePathBase ()
243248 {
244249 // Get path resoltion from default composer file directory
245- return dirname (\ Composer \Factory:: getComposerFile ()) . "/local-copies " ;
250+ return $ _SERVER [ ' HOME ' ] . "/pantheon- local-copies " ;
246251 }
247252
248253 /**
@@ -271,8 +276,38 @@ public function ensurePantheonYamlValues(InputInterface $input, OutputInterface
271276 yaml_emit_file ($ yamlFile , $ pantheonYaml );
272277 }
273278
274- public function getInfo () : Site
279+ /**
280+ * @return \Pantheon\Terminus\Models\Site|null
281+ */
282+ public function getSource (): ? Site
283+ {
284+ return $ this ->site ?? null ;
285+ }
286+
287+
288+ /**
289+ * @param string|Site $site
290+ */
291+ public function setSource ($ site )
275292 {
276- return $ this ->getSite ($ this ->siteID );
293+ if (is_string ($ site )) {
294+ $ this ->site = $ this ->getSite ($ site );
295+ }
296+ if ($ site instanceof Site) {
297+ $ this ->site = $ site ;
298+ }
299+ if (is_object ($ site )) {
300+ $ site = (array )$ site ;
301+ }
302+ if (is_array ($ site ) && isset ($ site ['id ' ])) {
303+ $ this ->site = $ this ->getSite ($ site ['id ' ]);
304+ }
305+ if (is_array ($ site ) && isset ($ site ['site ' ])) {
306+ $ this ->site = $ site ['site ' ];
307+ }
308+ if (!$ this ->site instanceof Site) {
309+ \Kint::dump ($ site );
310+ throw new TerminusNotFoundException ("Site not found: " );
311+ }
277312 }
278313}
0 commit comments