mirror of
https://github.com/bckelley/avogadrio.git
synced 2026-08-24 10:14:10 -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);
|
$encoded = rawurlencode($name);
|
||||||
|
|
||||||
// Check if we've got the name cached already.
|
// Check if we've got the name cached already.
|
||||||
$cached = $this->getIfCachedAndValid($encoded);
|
$cached = $this->getIfCached($encoded);
|
||||||
if ($cached !== null) {
|
if ($cached !== null) {
|
||||||
return $cached;
|
return $cached;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-15
@@ -47,17 +47,6 @@ abstract class SmilesConverter
|
|||||||
return $this->db !== null;
|
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.
|
* Returns true if a given SMILES string is valid, otherwise returns false.
|
||||||
*
|
*
|
||||||
@@ -69,19 +58,27 @@ abstract class SmilesConverter
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* Returns a cached SMILES string from its corresponding compound name, if present.
|
||||||
* @return string
|
*
|
||||||
|
* @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()) {
|
if ($this->isCacheEnabled()) {
|
||||||
$cachedSmiles = $this->db->get('smiles', 'name', $name);
|
$cachedSmiles = $this->db->get('smiles', 'name', $name);
|
||||||
if ($cachedSmiles !== null && self::isValidSmiles($cachedSmiles)) {
|
if ($cachedSmiles !== null) {
|
||||||
return $cachedSmiles;
|
return $cachedSmiles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
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) {
|
protected function cache($name, $smiles) {
|
||||||
if ($this->isCacheEnabled()) {
|
if ($this->isCacheEnabled()) {
|
||||||
$this->db->insert(['name' => $name, 'smiles' => $smiles]); // Cache name for future.
|
$this->db->insert(['name' => $name, 'smiles' => $smiles]); // Cache name for future.
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class WikipediaSmilesConverter extends SmilesConverter
|
|||||||
$encoded = str_replace(' ', '_', $name);
|
$encoded = str_replace(' ', '_', $name);
|
||||||
|
|
||||||
// Check if we've got the name cached already.
|
// Check if we've got the name cached already.
|
||||||
$cached = $this->getIfCachedAndValid($encoded);
|
$cached = $this->getIfCached($encoded);
|
||||||
if ($cached !== null) {
|
if ($cached !== null) {
|
||||||
return $cached;
|
return $cached;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user