mirror of
https://github.com/bckelley/avogadrio.git
synced 2026-08-24 02:04:11 -05:00
Add docs and remove validity check on cache access
This commit is contained in:
@@ -33,7 +33,7 @@ class CactusSmilesConverter extends SmilesConverter
|
||||
$encoded = rawurlencode($name);
|
||||
|
||||
// Check if we've got the name cached already.
|
||||
$cached = $this->getIfCachedAndValid($encoded);
|
||||
$cached = $this->getIfCached($encoded);
|
||||
if ($cached !== null) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
+12
-15
@@ -47,17 +47,6 @@ abstract class SmilesConverter
|
||||
return $this->db !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to fix any errors in a SMILES string and returns the result.
|
||||
*
|
||||
* @param string $smiles the SMILES string to fix
|
||||
* @return string the fixed SMILES string
|
||||
*/
|
||||
protected static function fixSmiles($smiles) {
|
||||
$output = str_replace('|', '', $smiles); // Zap vertical bars.
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a given SMILES string is valid, otherwise returns false.
|
||||
*
|
||||
@@ -69,19 +58,27 @@ abstract class SmilesConverter
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return string
|
||||
* Returns a cached SMILES string from its corresponding compound name, if present.
|
||||
*
|
||||
* @param string $name the name of the compound to return
|
||||
* @return string the SMILES structure of the compound, or null if not found
|
||||
*/
|
||||
protected function getIfCachedAndValid($name) {
|
||||
protected function getIfCached($name) {
|
||||
if ($this->isCacheEnabled()) {
|
||||
$cachedSmiles = $this->db->get('smiles', 'name', $name);
|
||||
if ($cachedSmiles !== null && self::isValidSmiles($cachedSmiles)) {
|
||||
if ($cachedSmiles !== null) {
|
||||
return $cachedSmiles;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches a compound name against its corresponding SMILES string.
|
||||
*
|
||||
* @param string $name the compound name
|
||||
* @param string $smiles the corresponding SMILES string
|
||||
*/
|
||||
protected function cache($name, $smiles) {
|
||||
if ($this->isCacheEnabled()) {
|
||||
$this->db->insert(['name' => $name, 'smiles' => $smiles]); // Cache name for future.
|
||||
|
||||
@@ -34,7 +34,7 @@ class WikipediaSmilesConverter extends SmilesConverter
|
||||
$encoded = str_replace(' ', '_', $name);
|
||||
|
||||
// Check if we've got the name cached already.
|
||||
$cached = $this->getIfCachedAndValid($encoded);
|
||||
$cached = $this->getIfCached($encoded);
|
||||
if ($cached !== null) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user