2023-03-27 12:31:42 +00:00
< ? php
namespace App\Models ;
2026-03-28 11:28:59 +00:00
use App\Support\ValidationPatterns ;
2023-03-27 12:31:42 +00:00
class SwarmDocker extends BaseModel
{
2023-11-28 14:49:24 +00:00
protected $guarded = [];
2026-03-28 11:28:59 +00:00
public function setNetworkAttribute ( string $value ) : void
{
if ( ! ValidationPatterns :: isValidDockerNetwork ( $value )) {
throw new \InvalidArgumentException ( 'Invalid Docker network name. Must start with alphanumeric and contain only alphanumeric characters, dots, hyphens, and underscores.' );
}
$this -> attributes [ 'network' ] = $value ;
}
2023-03-27 12:31:42 +00:00
public function applications ()
{
return $this -> morphMany ( Application :: class , 'destination' );
}
2023-08-08 09:51:36 +00:00
2023-11-28 14:49:24 +00:00
public function postgresqls ()
{
return $this -> morphMany ( StandalonePostgresql :: class , 'destination' );
}
public function redis ()
{
return $this -> morphMany ( StandaloneRedis :: class , 'destination' );
}
2024-06-10 20:43:34 +00:00
2024-04-10 13:00:46 +00:00
public function keydbs ()
{
return $this -> morphMany ( StandaloneKeydb :: class , 'destination' );
}
2024-06-10 20:43:34 +00:00
2024-04-10 13:00:46 +00:00
public function dragonflies ()
{
return $this -> morphMany ( StandaloneDragonfly :: class , 'destination' );
}
2024-06-10 20:43:34 +00:00
2024-04-10 13:00:46 +00:00
public function clickhouses ()
{
return $this -> morphMany ( StandaloneClickhouse :: class , 'destination' );
}
2024-06-10 20:43:34 +00:00
2023-11-28 14:49:24 +00:00
public function mongodbs ()
{
return $this -> morphMany ( StandaloneMongodb :: class , 'destination' );
}
2024-06-10 20:43:34 +00:00
2023-11-28 14:49:24 +00:00
public function mysqls ()
{
return $this -> morphMany ( StandaloneMysql :: class , 'destination' );
}
2024-06-10 20:43:34 +00:00
2023-11-28 14:49:24 +00:00
public function mariadbs ()
{
return $this -> morphMany ( StandaloneMariadb :: class , 'destination' );
}
2023-05-02 10:47:52 +00:00
public function server ()
{
return $this -> belongsTo ( Server :: class );
}
2023-11-28 14:49:24 +00:00
2026-01-16 10:51:26 +00:00
/**
* Get the server attribute using identity map caching .
* This intercepts lazy - loading to use cached Server lookups .
*/
public function getServerAttribute () : ? Server
{
// Use eager loaded data if available
if ( $this -> relationLoaded ( 'server' )) {
return $this -> getRelation ( 'server' );
}
// Use identity map for lazy loading
$server = Server :: findCached ( $this -> server_id );
// Cache in relation for future access on this instance
if ( $server ) {
$this -> setRelation ( 'server' , $server );
}
return $server ;
}
2023-11-28 14:49:24 +00:00
public function services ()
{
return $this -> morphMany ( Service :: class , 'destination' );
}
public function databases ()
{
$postgresqls = $this -> postgresqls ;
$redis = $this -> redis ;
$mongodbs = $this -> mongodbs ;
$mysqls = $this -> mysqls ;
$mariadbs = $this -> mariadbs ;
2024-04-10 13:00:46 +00:00
$keydbs = $this -> keydbs ;
$dragonflies = $this -> dragonflies ;
$clickhouses = $this -> clickhouses ;
2024-06-10 20:43:34 +00:00
2024-04-10 13:00:46 +00:00
return $postgresqls -> concat ( $redis ) -> concat ( $mongodbs ) -> concat ( $mysqls ) -> concat ( $mariadbs ) -> concat ( $keydbs ) -> concat ( $dragonflies ) -> concat ( $clickhouses );
2023-11-28 14:49:24 +00:00
}
public function attachedTo ()
{
return $this -> applications ? -> count () > 0 || $this -> databases () -> count () > 0 ;
}
2023-03-27 12:31:42 +00:00
}