04/07/2012 4:42pm

PHP | Problem - exception msg vs plain msg


1st method - 


//JsonHandler.php

function cloneJson($url) {
$this->url = $url ;

try{
$config = Factory::createConfig();
$repo = new VcsRepository(array('url' => $url,''), new NullIO(), $config);
if(!isset($repo)) {
throw new Exception('unable to create vsc repoistory ');
}
$driver = $repo->getDriver();
if(!isset($driver)) {
throw new InvalidArgumentException('Unable to get driver for this type of repoistory');
}
$data = $driver->getComposerInformation($driver->getRootIdentifier());
return array(
'Data' => $data,
);

} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}

//ModuleHolder.php

$json = new JsonHandler();
$jsonData = $json->cloneJson($url);

if($jsonData['Data']) {
if($this->isNewExtension($url)) {
$saveJson = $json->saveJson($url,$jsonData['Data']);
if($saveJson) {
$form->sessionMessage(_t('ExtensionHolder.THANKSFORSUBMITTING','Thank you for your submission'),'good');
return $this->redirectBack();
} else {
$form->sessionMessage(_t('ExtensionHolder.PROBLEMINSAVING','We are unable to save module info, Please Re-check format of you composer.json file. '),'bad');
return $this->redirectBack();
}
} else {
$updateJson = $json->updateJson($url, $jsonData['Data']);
if($updateJson) {
$form->sessionMessage(_t('ExtensionHolder.THANKSFORUPDATING','Thank you for Updating Your Module'),'good');
return $this->redirectBack();
} else {
$form->sessionMessage(_t('ExtensionHolder.PROBLEMINUPDATING','We are unable to UPDATE module info, Please Re-check format of you composer.json file. '),'bad');
return $this->redirectBack();
}
}
}


2nd method -

//JsonHandler.php

function cloneJson($url) {
$this->url = $url ;

try{
$config = Factory::createConfig();
$repo = new VcsRepository(array('url' => $url,''), new NullIO(), $config);
$driver = $repo->getDriver();
if(!isset($driver)) {
return false;
}
$data = $driver->getComposerInformation($driver->getRootIdentifier());
return array(
'Data' => $data,
);

} catch (Exception $e) {
return false;
}
}

//ExtensionHolder.php


Post Comment