D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
forge
/
josepharmacy.online
/
Filename :
check_blade.py
back
Copy
import re def check_blade_directives(filepath): with open(filepath, 'r') as f: content = f.read() # Directives that need closing pairs = { '@if': '@endif', '@foreach': '@endforeach', '@section': '@endsection', '@push': '@endpush', '@isset': '@endisset', '@empty': '@endempty', '@can': '@endcan', '@auth': '@endauth', '@guest': '@endguest', '@switch': '@endswitch', '@php': '@endphp' } stack = [] lines = content.split('\n') # Regex to find directives, but ignore those inside {{-- --}} # This is a bit complex for a simple script, let's just do a basic line-by-line check for i, line in enumerate(lines, 1): # Ignore comments if '{{--' in line and '--}}' in line: # Check if directive is outside comment? Skip for now. pass # Find all directives in line # Use regex to find @word but only if it matches our pairs or their ends matches = re.findall(r'@(if|endif|foreach|endforeach|section|endsection|push|endpush|isset|endisset|empty|endempty|can|endcan|auth|endauth|guest|endguest|switch|endswitch|php|endphp)', line) for m in matches: directive = '@' + m # Special case for @section('name', 'content') if directive == '@section' and re.search(r"@section\s*\(\s*['\"].*?['\"]\s*,\s*['\"].*?['\"]\s*\)", line): continue # Special case for @php( ... ) if directive == '@php' and re.search(r"@php\s*\(", line): continue if directive in pairs: stack.append((directive, i)) print(f"L{i}: Opened {directive}") else: # Find which opener this closes found = False for pair_start, pair_end in pairs.items(): if directive == pair_end: if stack and stack[-1][0] == pair_start: opened, line_no = stack.pop() print(f"L{i}: Closed {opened} from L{line_no}") found = True break else: print(f"ERROR L{i}: Found {directive} but expected end for {stack[-1][0] if stack else 'nothing'}") if stack: stack.pop() # Try to continue found = True break if not found: print(f"L{i}: Ignore {directive}") if stack: print("\nUNCLOSED BLOCKS:") for directive, line_no in stack: print(f"{directive} opened on line {line_no} is never closed.") else: print("\nAll blocks closed correctly.") check_blade_directives('/home/mohamad-ayman/Desktop/pharmacy/resources/themes/default/web-views/users-profile/account-order-details.blade.php')