JezK
Edit File: registry.php
<?php /** * Layout Component Registry * * @package Blockspare */ namespace Blockspare\Layouts; use \Exception; use \InvalidArgumentException; /** * Class Component_Registry * * @access private Not intended as a public API. * Use the helper functions to manage layouts. * This class will likely go away in the future. */ final class Component_Registry { /** * Supported component types. * * @var array */ private static $supported_component_types = [ 'layout', 'section','block','page','header','footer','templates' ]; /** * Required keys for components. * * @var array */ private static $required_data_keys = [ 'type', 'key', 'name', 'content', 'item' ]; /** * Holds the registered layouts. * * @var array */ private static $layouts = []; /** * Holds the registered sections. * * @var array */ private static $sections = []; /** * Holds the registered blocks. * * @var array */ private static $blocks = []; /** * Holds the registered pages. * * @var array */ private static $pages = []; /** * Holds the registered headers. * * @var array */ private static $headers = []; /** * Holds the registered footers. * * @var array */ private static $footers = []; /** * Holds the registered templates. * * @var array */ private static $templates = []; /** * The Component_Registry object. * * @var object Component_Registry */ private static $instance; /** * Creates the Component_Registry instance. * * @return Component_Registry */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Adds a component to the registry. * * @param array $data Component data. * @throws InvalidArgumentException If invalid data is provided or the component is already registered. */ public static function add( array $data ) { if ( empty( $data['type'] ) || ! in_array( $data['type'], self::$supported_component_types, true ) ) { throw new InvalidArgumentException( esc_html__( 'You must supply a valid component type.', 'blockspare' ) ); } if ( empty( $data ) ) { throw new InvalidArgumentException( __( 'You must supply valid layout data to register a layout.', 'blockspare' ) ); } foreach ( self::$required_data_keys as $required_key ) { if ( ! array_key_exists( $required_key, $data ) || empty( $data[ $required_key ] ) ) { /* translators: %s: The missing key that is required to register a component. */ throw new InvalidArgumentException( sprintf( esc_html__( 'You must supply a %s to register a layout.', 'blockspare' ), $required_key ) ); } } switch ( $data['type'] ) { case 'layout': if ( ! empty( self::$layouts[ $data['key'] ] ) ) { /* translators: %s: The component's unique key. */ throw new InvalidArgumentException( sprintf( esc_html__( 'The %s layout is already registered.', 'blockspare' ), $data['key'] ) ); } self::$layouts[ $data['key'] ] = $data; break; case 'section': if ( ! empty( self::$sections[ $data['key'] ] ) ) { /* translators: %s: The component's unique key. */ throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); } self::$sections[ $data['key'] ] = $data; break; case 'block': if ( ! empty( self::$blocks[ $data['key'] ] ) ) { /* translators: %s: The component's unique key. */ throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); } self::$blocks[ $data['key'] ] = $data; break; case 'page': if ( ! empty( self::$pages[ $data['key'] ] ) ) { /* translators: %s: The component's unique key. */ throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); } self::$pages[ $data['key'] ] = $data; break; case 'header': if ( ! empty( self::$headers[ $data['key'] ] ) ) { /* translators: %s: The component's unique key. */ throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); } self::$pages[ $data['key'] ] = $data; break; case 'footer': if ( ! empty( self::$footers[ $data['key'] ] ) ) { /* translators: %s: The component's unique key. */ throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); } self::$pages[ $data['key'] ] = $data; break; case 'templates': if ( ! empty( self::$templates[ $data['key'] ] ) ) { /* translators: %s: The component's unique key. */ throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); } self::$pages[ $data['key'] ] = $data; break; default: /* translators: %s: This functions name. Will always be Blockspare\Layouts\Component_Registry::add(). */ throw new InvalidArgumentException( sprintf( esc_html__( 'You must supply a valid component type in %s.', 'blockspare' ), __METHOD__ ) ); } } /** * Removes an existing component from the registry. * * @param string $type The component type to unregister. * @param string $key The unique layout key to be removed. * * @throws Exception If the required data is not provided or the specified component is not registered. * @throws InvalidArgumentException If an unsupported component type is provided. */ public static function remove( $type, $key ) { if ( empty( $type ) || ! in_array( $type, self::$supported_component_types, true ) ) { /* translators: %s: This functions name. Will always be Blockspare\Layouts\Component_Registry::remove(). */ throw new InvalidArgumentException( sprintf( esc_html__( 'You must supply a valid component type in %s.', 'blockspare' ), __METHOD__ ) ); } if ( empty( $key ) ) { /* translators: %s: This functions name. Will always be Blockspare\Layouts\Component_Registry::remove(). */ throw new InvalidArgumentException( sprintf( esc_html__( 'You must supply a valid component key in %s.', 'blockspare' ), __METHOD__ ) ); } $key = sanitize_key( $key ); switch ( $type ) { case 'layout': if ( empty( self::$layouts[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s layout is not registered.', 'blockspare' ), $key ) ); } unset( self::$layouts[ $key ] ); break; case 'section': if ( empty( self::$sections[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } unset( self::$sections[ $key ] ); break; case 'block': if ( empty( self::$blocks[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } unset( self::$blocks[ $key ] ); break; case 'page': if ( empty( self::$pages[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } unset( self::$pages[ $key ] ); break; case 'header': if ( empty( self::$headers[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } unset( self::$headers[ $key ] ); break; case 'footer': if ( empty( self::$footers[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } unset( self::$footers[ $key ] ); break; case 'templates': if ( empty( self::$templates[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } unset( self::$templates[ $key ] ); break; } } /** * Gets a component from the registry. * * @param string $type The component type. * @param string $key The component's unique key. * * @return mixed * @throws Exception If the required data is not provided or the specified component is not registered. * @throws InvalidArgumentException If an unsupported component type is provided. */ public static function get( $type, $key ) { if ( empty( $type ) || ! in_array( $type, self::$supported_component_types, true ) ) { /* translators: This function name. Will always be Blockspare\Layouts\Component_Registry::get(). */ throw new Exception( sprintf( esc_html__( 'You must supply a component type in %s.', 'blockspare' ), __METHOD__ ) ); } switch ( $type ) { case 'layout': if ( empty( self::$layouts[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s layout is not registered.', 'blockspare' ), $key ) ); } return self::$layouts[ $key ]; case 'section': if ( empty( self::$sections[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } return self::$sections[ $key ]; case 'block': if ( empty( self::$blocks[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } return self::$blocks[ $key ]; case 'page': if ( empty( self::$pages[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } return self::$pages[ $key ]; case 'header': if ( empty( self::$headers[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } return self::$headers[ $key ]; case 'footer': if ( empty( self::$footers[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } return self::$footers[ $key ]; case 'templates': if ( empty( self::$templates[ $key ] ) ) { /* translators: The requested components unique key. */ throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); } return self::$templates[ $key ]; default: /* translators: This function name. Will always be Blockspare\Layouts\Component_Registry::get(). */ throw new InvalidArgumentException( sprintf( esc_html__( 'You must supply a valid component type in %s.', 'blockspare' ), __METHOD__ ) ); } } /** * Returns the registered layouts. * * @return array */ public static function layouts() { return self::$layouts; } /** * Returns the registered sections. * * @return array */ public static function sections() { return self::$sections; } /** * Returns the registered sections. * * @return array */ public static function blocks() { return self::$blocks; } /** * Returns the registered pages. * * @return array */ public static function pages() { return self::$pages; } /** * Returns the registered headers. * * @return array */ public static function headers() { return self::$headers; } /** * Returns the registered footers. * * @return array */ public static function footers() { return self::$footers; } public static function templates() { return self::$templates; } }
BanaBridge News
https://validator.w3.org/feed/docs/rss2.html
Court Orders Ex-Weah Protocol Chief Jailed on US$8 Million Bail, Sends 15 Jurors to Prison Over Misconduct
Women Renew Call for War and Economic Crimes Court at Liberia’s Historic Peace Prayer Site
Finance Minister Ngafuan Urges Transparency, Accountability as Liberia Advances ARREST Agenda at UN Retreat
PPCC Donates ICT Equipment to 50 Government Institutions to Expand Electronic Procurement System
Liberia Commissions €100,000 Elemental Analyzer to Strengthen Environmental Research and Food Security
EPA Ends 16 Years of Renting with Purchase of Permanent Headquarters
West African Tax Bodies Deepen Partnership to Boost Revenue Mobilization, Launch Carbon Tax Study
Liberia Hosts Sierra Leone Procurement Delegation for E-GP Reform Study Tour
World Bank Praises Liberia’s Central Bank for Economic Stability and Private Sector Progress
Liberians See Slight Improvement in Corruption Fight, But Graft Still Viewed as Widespread, CENTAL Report Finds
Canada Afrique Care Foundation Set for Official Launch, Expanding Free Mental Health Access Across Canada and Africa
Weah Claims Liberia Has Become a “Narco State” as Opposition Rallies Behind Calls for Independent Probe into US$19 Million Cocaine Bust
EPA Boss Calls for Stronger Student Engagement, Unveils Push for Academic Partnership at UL Climate Symposium
Education Minister Urges Students to Embrace Tax Responsibility at National Student Tax Day
CDC Secretary General Urges U.S. Government to Review Support to Liberia National Police
Liberia Partners with CACFO to Expand Mental Health Services Ahead of Global Launch
Wreh-Toe Appointed Board Chair of CACFO as Foundation Strengthens Mental Health Push
GIABA Opens New Information Center Headquarters in Abidjan
Liberia Wins Fresh Backing as World Bank Group Executive Praises Progress, Pushes Faster Project Delivery
LRA Honors Liberia’s Top Taxpayers as Revenue Collections Hit Historic High
Root Cause in Question as Border Tensions Persist After Conakry Peace Deal
From Enforcement to Innovation: EPA Marks 2025 as a Defining Year for Liberia’s Environment
Weah Declares ‘Road to 2029 Begins Today’ as CDC Marks 22nd Anniversary in Zwedru
500 Documented Governance Failures: Activist Publishes Sweeping End-of-Year Indictment of Boakai Administration
CDC Calls for Probe into Border Crisis, Cites Alleged Mining Activities
Liberia Moves to Strengthen Small Businesses with $672,000 Packaging Solution Initiative
Former Public Works Minister Ruth Coker Collins Defends Zwedru Corridor Strategy, Calls for “Facts Over Rhetoric” in Infrastructure Debate
Power Shake-Up in CDC Diaspora: NEC Dissolves CDC-USA Interim Leadership, Appoints Rev. Muin to Lead U.S. Chapter
Tweah Reemerges, Sparks Fierce National Debate Over Governance and Liberia’s Future
Koijee Slams Tribal Politics and Political Manipulation in Lofa, Accuses Boakai Government
Mali and Burkina Faso Impose Reciprocal Travel Ban on U.S. Citizens
Guinea Election: A Turn Toward Continuity Amid Questions of Democratic Credibility
Liberia’s Revenue Grows Stronger as LRA Exceeds National Target for Second Year
Liberia’s Gender Legal Landscape: Laws in Place, Systems Lag Far Behind
Liberia’s Economy Gains Momentum as CBL Governor Highlights Progress at ECOWAS Meeting
Liberia Positions Itself for Eco Currency Entry as Economy Expands by 5.1%
From Overcrowded Classrooms to Renewal: NPA Mobilizes $1 Million to Transform UL
Ex-Public Works Minister Ruth Coker Collins Slams Ministry’s “Lack of Capacity,” Defends Her Infrastructure Record
CDC Expels Three Senior Members, Citing Alleged Alignment With Government and Undermining Party Ideology
UL to Celebrate 75 Years of Excellence
Saudi Fund Advances Liberia’s Push for Major Infrastructure Development
West African Financial Leaders Convene in Monrovia for ECOWAS Statutory Meetings
Unlocking Liberia’s Potential: Government Launches Major Revenue and Transparency Reforms
Incremental Gains, Enduring Impunity: Liberia’s CPI Improvement Fails the Test of Reform
Boakai’s Call for Unity Faces Scrutiny as Opposition, Citizens Question Actions Behind the Words
REMAPSEN Liberia Set to Strengthen Health and Environmental Reporting
Energy Sector Women Step Into the Spotlight at Liberia’s International Women’s Day Celebration
FeJAL Concludes Three-Day Retreat, Honors Outstanding Women Journalists
Dr. Rasha Kelej Named Among Africa’s 100 Most Influential Leaders
LAVA Honored for Strengthening Liberia–U.S. Ties at 2025 Military Ball