Overview

Classes

  • xu
  • Xu\Foundation\Foundation
  • Xu\Foundation\Jsonable
  • Xu\Model\Collection
  • Xu\Model\Model

Functions

  • xu
  • xu_add_option
  • xu_attachment_url_to_postid
  • xu_cache_delete
  • xu_cache_delete_group
  • xu_cache_get
  • xu_cache_key
  • xu_camel_case
  • xu_clean_attachment_cache
  • xu_clean_nav_menu_cache
  • xu_clean_post_cache
  • xu_contains
  • xu_convert_to_string
  • xu_current_attachment_url_to_postid
  • xu_current_url
  • xu_current_url_to_postid
  • xu_dashify
  • xu_delete_option
  • xu_delete_site_transient
  • xu_delete_transient
  • xu_doing_ajax
  • xu_ends_with
  • xu_get_class_name
  • xu_get_model
  • xu_get_option
  • xu_get_option_name
  • xu_get_option_post_id
  • xu_get_posts
  • xu_get_site_transient
  • xu_get_top_parent_post
  • xu_get_top_parent_post_type
  • xu_get_top_parent_post_type_object
  • xu_get_transient
  • xu_is_empty
  • xu_is_http_method
  • xu_is_json
  • xu_is_post_type
  • xu_is_wp
  • xu_is_xml
  • xu_post_exists
  • xu_register_large_option_post_type
  • xu_snake_case
  • xu_starts_with
  • xu_strip_spaces
  • xu_studly_case
  • xu_update_option
  • xu_url_to_postid
  • xu_valid_personnummer
  • xu_wp_get_attachment_image
  • xu_wp_get_attachment_image_sizes
  • xu_wp_get_attachment_image_src
  • xu_wp_get_attachment_image_srcset
  • xu_wp_get_attachment_url
  • xu_wp_nav_menu
  • Overview
  • Class
 1: <?php
 2: 
 3: /**
 4:  * Get namespace name and/or class name from file.
 5:  *
 6:  * @param  string $file The file path.
 7:  *
 8:  * @throws InvalidArgumentException if an argument is not of the expected type.
 9:  * @throws Exception if file don't exists.
10:  *
11:  * @return string
12:  */
13: function xu_get_class_name( $file ) {
14:     if ( ! is_string( $file ) ) {
15:         throw new InvalidArgumentException( 'Invalid argument. Must be string.' );
16:     }
17: 
18:     if ( ! file_exists( $file ) ) {
19:         throw new Exception( sprintf( '`%s`does not exist.', $file ) );
20:     }
21: 
22:     $content         = file_get_contents( $file );
23:     $tokens          = token_get_all( $content );
24:     $class_name      = '';
25:     $namespace_name  = '';
26:     $i               = 0;
27:     $len             = count( $tokens );
28: 
29:     for ( ; $i < $len; $i++ ) {
30:         if ( $tokens[$i][0] === T_NAMESPACE ) {
31:             for ( $j = $i + 1; $j < $len; $j++ ) {
32:                 if ( $tokens[$j][0] === T_STRING ) {
33:                      $namespace_name .= '\\' . $tokens[$j][1];
34:                 } else if ( $tokens[$j] === '{' || $tokens[$j] === ';' ) {
35:                      break;
36:                 }
37:             }
38:         }
39: 
40:         if ( $tokens[$i][0] === T_CLASS ) {
41:             for ( $j = $i + 1; $j < $len; $j++ ) {
42:                 if ( $tokens[$j] === '{' ) {
43:                     $class_name = $tokens[$i + 2][1];
44:                 }
45:             }
46:         }
47:     }
48: 
49:     if ( empty( $class_name ) ) {
50:         return '';
51:     }
52: 
53:     if ( empty( $namespace_name ) ) {
54:         return $class_name;
55:     }
56: 
57:     return $namespace_name . '\\' . $class_name;
58: }
59: 
API documentation generated by ApiGen