├── classes.php ├── classes └── NextMovie.php ├── consts.php ├── demo.php ├── functions.php ├── index.php └── templates ├── head.php ├── main.php └── styles.php /classes.php: -------------------------------------------------------------------------------- 1 | PHP 8 8 | public function __construct( 9 | private string $name, 10 | public array $powers, 11 | public string $planet 12 | ) { 13 | } 14 | 15 | public function attack() 16 | { 17 | return "¡$this->name ataca con sus poderes!"; 18 | } 19 | 20 | public function show_all() 21 | { 22 | return get_object_vars($this); 23 | } 24 | 25 | public function description() 26 | { 27 | $powers = implode(", ", $this->powers); 28 | 29 | return "$this->name es un superhéroe que viene de $this->planet y tiene los siguientes poderes: $powers"; 30 | } 31 | 32 | public static function random() 33 | { 34 | $names = ["Thor", "Spiderman", "Wolverine", "Ironman", "Hulk"]; 35 | $powers = [ 36 | ["Superfuerza", "Volar", "Rayos láser"], 37 | ["Superfuerza", "Super agilidad", "Telarañas"], 38 | ["Regeneración", "Superfuerza", "Garras de adamantium"], 39 | ["Superfuerza", "Volar", "Rayos láser"], 40 | ["Superfuerza", "Super agilidad", "Cambio de tamaño"], 41 | ]; 42 | $planets = ["Asgard", "HulkWorld", "Krypton", "Tierra"]; 43 | 44 | $name = $names[array_rand($names)]; 45 | $power = $powers[array_rand($powers)]; 46 | $planet = $planets[array_rand($planets)]; 47 | 48 | return new self($name, $power, $planet); 49 | } 50 | } 51 | 52 | // estático 53 | $hero = SuperHero::random(); // método estático 54 | echo $hero->description(); 55 | -------------------------------------------------------------------------------- /classes/NextMovie.php: -------------------------------------------------------------------------------- 1 | days_until; 20 | 21 | return match (true) { 22 | $days === 0 => "¡Hoy se estrena! 🥳", 23 | $days === 1 => "Mañana se estrena 🚀", 24 | $days < 7 => "Esta semana se estrena 🫢", 25 | $days < 30 => "Este mes se estrena... 🗓️", 26 | default => "$days días hasta el estreno 🗓️", 27 | }; 28 | } 29 | 30 | public static function fetch_and_create_movie(string $api_url): NextMovie 31 | { 32 | $result = file_get_contents($api_url); // si solo quieres hacer un GET de una API 33 | $data = json_decode($result, true); 34 | 35 | return new self( 36 | $data["title"], 37 | $data["days_until"], 38 | $data["following_production"]['title'] ?? "Desconocido", 39 | $data["release_date"], 40 | $data["poster_url"], 41 | $data["overview"], 42 | ); 43 | } 44 | 45 | public function get_data() 46 | { 47 | return get_object_vars($this); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /consts.php: -------------------------------------------------------------------------------- 1 | "Eres un bebé, $name 👶", 12 | $age < 10 => "Eres un niño, $name 👦", 13 | $age < 18 => "Eres un adolescente, $name 👨‍🎓", 14 | $age === 18 => "Eres mayor de edad, $name 🍺", 15 | $age < 40 => "Eres un adulto joven, $name 👨‍💼", 16 | $age < 60 => "Eres un adulto viejo, $name 👴", 17 | default => "Hueles más a madera que a fruta, $name 👴", 18 | }; 19 | 20 | $bestLanguages = ["PHP", "JavaScript", "Python"]; 21 | $bestLanguages[] = "Java"; 22 | $bestLanguages[] = "TypeScript"; 23 | 24 | $person = [ 25 | "name" => "Miguel", 26 | "age" => 78, 27 | "isDev" => true, 28 | "languages" => ["PHP", "JavaScript", "Python"], 29 | ]; 30 | $person["name"] = "pheralb"; 31 | $person["languages"][] = "Java"; 32 | ?> 33 | 34 | 39 | 40 |

41 | 42 | PHP Logo 43 |

44 | 45 |

46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /functions.php: -------------------------------------------------------------------------------- 1 | "¡Hoy se estrena! 🥳", 22 | $days === 1 => "Mañana se estrena 🚀", 23 | $days < 7 => "Esta semana se estrena 🫢", 24 | $days < 30 => "Este mes se estrena... 🗓️", 25 | default => "$days días hasta el estreno 🗓️", 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | get_data(); 9 | ?> 10 | 11 | $next_movie_data["title"]]); ?> 12 | $next_movie->get_until_message()] 15 | )); ?> 16 | 17 | -------------------------------------------------------------------------------- /templates/head.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | La próxima película de Marvel: <?= $title; ?> 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /templates/main.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | Poster de <?= $title ?> 4 |
5 | 6 |
7 |

-

8 |

Fecha de estreno:

9 |

La siguiente es:

10 |
11 |
-------------------------------------------------------------------------------- /templates/styles.php: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------