File Search Paths: Difference between revisions

From IHRIS Wiki
No edit summary
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
En este artículo describimos la utilidad de la Búsqueda de Archivos que es parte de iHRIS. Dicha utilidad le permite categorizar y agrupar facilmente archivos diferentes y ponerlos a disposición de iHRIS. También le permite copiar un archive de la core iHRIS Suite en la personalización de su sitio para hacer cambios ahí, sin tener que modificar el software central de iHRIS.
This article describes the File Search utility that is part of iHRIS. The file search utility lets you easily categorize different files and make them available to iHRIS. It also allows you to copy a file from the core iHRIS Suite into your site customization to make changes there, without having to modify the core iHRIS software.




El I2CE (Intrahealth Informatics Core Engine) utiliza una utilidad de búsqueda de Archivos para organizar los archivos en categorías y definir prioridades para la búsqueda en los directorios. Desde la versión 3.2 también porporciona [[#Localizing Paths|localization]] de archivos.
The I2CE (Intrahealth Informatics Core Engine) uses a File Search utility to organize the files into categories and define priorties for searching the directories. As of version 3.2, it also provides [[#Localizing Paths|localization]] of files.


Todos los archivos, con muy pocas excepciones, se encuentran utilizando la clase  ''I2CE_FileSearch'' definida en ''I2CE/lib/I2CE_FileSearch.php.''  Las excepciones son aquellos archivos bajo ''I2CE/lib.''   
All files, with very few exceptions, are found using the ''I2CE_FileSearch'' class defined in ''I2CE/lib/I2CE_FileSearch.php.''  The exceptions are those files under ''I2CE/lib.''   


=Categorías de Rutas=
=Path Categories=
Las categorías de rutas utilizadas comunmente son:
Commonly used pathed categories are:
*plantillas Estos son los directorios para buscar archivos de plantillas html  
*templates These are the directories to search for html template files
*imágenes Estos son los directorios para buscar archivos de imágenes
*images These are the directories to search for image files
*css Estos son los directorios para buscar archivos CSS  
*css These are the directories to search for CSS files
*scripts Estos son los directorios para buscar archivos javascript  
*scripts These are the directories to search for javascript files
*clases Estos son los directorios para buscar archivos que contienen clases php.  La convención aquí es que MyClass está localizado en el archivo MyClass.php
*classes These are the directories to search for files containing php classesThe convention here is that MyClass is located in the file MyClass.php
*módulos Estos son los directorios para buscar módulos
*modules These are the directories to look for modules in
Usted puede crear sus propias categorías de rutas.
You are free to create your own path categories.


=Prioridades=
=Priorties=
Los directorios en una categoría dada se buscan por un archive en orden de la prioridad màs baja a la màs alta. Si dos directorios tienen la misma prioridad y el mismo archive, no hay garantía de cúal archivo regresará.  
Directories in a given category are searched for a file in order of lowest priority to highest priority. If two directories have the same priority and the same file, there is no guarantee which file will be returned.  


Las rutas agregadas por un módulo tienen la prioridad negativa de ese módulo. Por ejemplo, un archive de plantilla en I2CE tiene una prioridad de 0, mientras que un archivo de plantilla encontrado en ihris-manage tiene una prioridad de -200  para que el archivo de plantilla en ihris-manage se encuentre primeroHay dos excepciones: las rutas agregadas por un módulo en las 'clases' o 'módulos' se agregan con la prioridad del modulo para que una clase php encontrada en I2CE tome precedencia sobre una en ihris-manage que tienen una prioridad de 200.
The paths added by a module have the negative priority of that module. For example an template file in I2CE has priority 0, while a template file found in ihris-manage has priority -200  so that the template file in ihris-manage is found firstThere are two exceptions: the paths added by a module in the 'classes' or 'modules' are added with the priority of the module so that a php class found in I2CE takes precedence over one in ihris-manage which has priority 200.


=Agregar Rutas=
=Adding Paths=
La forma más común de agregar un directorio a una ruta de búsqueda es hacerlo a través de una estructura de módulos [[Module Structure#Module Configuration File|configuration file]].  por ejemplo:
The most common way to add a directory to a search path is to do so through a modules [[Module Structure#Module Configuration File|configuration file]].  For example:
  <path name='classes'>  
  <path name='classes'>  
   <value>./lib</value>
   <value>./lib</value>
  </path>
  </path>
Las etiquetas de <value> pueden ser rutas absolutas o relativas. Si son relativas, es con respecto al directorio que contiene este archivo de configuración.   
The <value> tags can be either absolute paths or relative paths. If they are relative paths, they are relative to the directory which contains this configuration file.   
Algunas Salvedades:
Some Caveats:
*Si agrega un '*' al final de una ruta que termina en '/' (o '\' para windows), esto dice que todos los sub-directorios de este directorio deben añadirse a la ruta. Por ejemplo, <value>./my_path/*</value>  agrega todos los sub-directorios bajo ./my_path/
*If you add a '*' to the end of a path which ends in '/' (or '\' for windows), this says that all sub-directories of this directory should be added to path. For example, <value>./my_path/*</value>  adds in all sub-directories under ./my_path/
*Si agrega un  '*' al final de una ruta que no termina en  '/' (o '\' para windows) esto dice que agregamos todos los directorios que concuerdan con el archivo glob.  Por ejemplo, <value>./my_paths/go*</value> agrega todos los sub-directorios de my_paths que empiezan con go.
*If you add a '*' to the end of a path which does not end in a '/' (or '\' for windows) this says that we add all directories that match the file glob.  For example, <value>./my_paths/go*</value> adds in all sub-directories of my_paths which start with go.
*Si agrega un '**' al final de una ruta que termina en  '/' (o '\' para windows) agregará todos los sub-directorios, sub-sub-directorios, sub-sub-sub-directorios etc de la ruta dada.
*If you add a '**' to the end of a path which ends in '/' (or '\' for windows) it will add in all sub-directories, sub-sub-directories, sub-sub-sub-directories etc of the given path.
*Si un directorio que usted agrega tiene un sub-directorio llamado 'local'`primero buscará lo relativo a este subdirectorio para este archivoEsto es útil para propósitos de desarrollo para prevenir que las cosas se comprometan a bazaar.   
*If a directory that you add has a sub-directory named 'local' it will first check realtive to this subdirectory for this fileThis is useful for development purposes to prevent things from getting committed to bazaar.   
*Ver [[#Localization|localization]]
*See [[#Localization|localization]]


=Localización=
=Localization=
Dese la version 3.2, hemos agregado la habilidad de localizar una ruta. Cuando se agrega una ruta a la utilidad de búsqueda de archivos, primero revisa si el subirectorio està ''en_US.''  Si no existe, entonces este directorio no se considera localizado. Si existe, la ruta se considera localizada. En este caso, consideramos que cada sub-directorio corresponde a un local.
Beginning with version 3.2, we have added in the ability to localize a path. When a path is added to the file search utility, it first checks to see if there is the sub-directory ''en_US.''  If it does not exist, the this directory is not considered to be localized. If it does exist, the path is considered to be localized. In this case, we consider each sub-directory to correspond to a locale.


Los locales preferidos se esablecen por usuario. Por ejemplo, si mis locales preferidos fueran  ''fr_RW'' y luego  ''fr_FR'' y luego  ''en_US'' y estoy buscando el archivo ''main.html'' en ''./templates'' que tiene ''en_US'' como in sub-directorio, buscaría  ''main.html'' en este orden:
The preferred locales are set per user. For example, if my preferred locales were ''fr_RW'' and then ''fr_FR'' and then ''en_US'' and I was looking for the file ''main.html'' in ''./templates'' which has ''en_US'' as a sub-directory I would look for ''main.html'' in this order:
*./templates/fr_RW/main.html
*./templates/fr_RW/main.html
*./templates/fr_FR/main.html
*./templates/fr_FR/main.html
*./templates/en_US/main.html
*./templates/en_US/main.html
hasta encontrar el archivo que quería. Si no estuviese ahí, buscaría ''main.html'' en un directorio prioridad más alta.
until I found the file I wanted. If it wasn't there, I would then check for ''main.html'' in a directory of higher priority.


=Caché=
=Caching=
Debido a la alta frecuencia con que se buscan archivos, una busqueda exitosa tendría sus resultados en el cache via [http://pecl.php.net/package/APC apc].  En la versión 3.1, estos resultados se guardan globalmente. A partir de la versión 3.2, dado que la preferencia de localización es definida por usuario, estos resultados se guardan en el caché por usuario.   
Because of the high overhead of looking for files all the time,  a successful file search will have its results cached in memory via [http://pecl.php.net/package/APC apc].  In version 3.1, these results are stored globally. Starting in version 3.2, because the localization preference is defined per user, these results are cached per user.   


Por defecto, un archivo se considera obsoleto después de 60 segundos. El caché se puede desactivar al modificar los datos magic en /I2CE/fileSearch/stale_time (vea ''I2CE/I2CE_Configuration.xml'').
By default, a file is considered to be stale after 60 seconds. The cache can be turned off by modifying the magic data at /I2CE/fileSearch/stale_time (see ''I2CE/I2CE_Configuration.xml'').


'''<span style='color:red'>Precaución:</span>'''Si está desarrollando un módulo nuevo y agrega un archivo de plantilla, el sistema no lo archivará inmediatamente porque los resultados de la búsqueda de archivos se guardan en el caché. Usted puede esperar los 60 segundos o limpiar los resultados guardados en la memoria cache [http://pecl.php.net/package/APC apc].
'''<span style='color:red'>Caution:</span>'''If you are developing a new module and add in a template file, the system won't file that file immediately because the file search results are cached. You can either wait the 60 seconds or clear the results stored in the [http://pecl.php.net/package/APC apc] memory cache.
[[Category:Technical Overview]][[Category:Modules]][[Category:Search]][[Category:Review2013]][[Category:Needs Intro]]
 
[[Category:Developer Resources]]

Latest revision as of 19:23, 1 March 2019

This article describes the File Search utility that is part of iHRIS. The file search utility lets you easily categorize different files and make them available to iHRIS. It also allows you to copy a file from the core iHRIS Suite into your site customization to make changes there, without having to modify the core iHRIS software.


The I2CE (Intrahealth Informatics Core Engine) uses a File Search utility to organize the files into categories and define priorties for searching the directories. As of version 3.2, it also provides localization of files.

All files, with very few exceptions, are found using the I2CE_FileSearch class defined in I2CE/lib/I2CE_FileSearch.php. The exceptions are those files under I2CE/lib.

Path Categories

Commonly used pathed categories are:

  • templates These are the directories to search for html template files
  • images These are the directories to search for image files
  • css These are the directories to search for CSS files
  • scripts These are the directories to search for javascript files
  • classes These are the directories to search for files containing php classes. The convention here is that MyClass is located in the file MyClass.php
  • modules These are the directories to look for modules in

You are free to create your own path categories.

Priorties

Directories in a given category are searched for a file in order of lowest priority to highest priority. If two directories have the same priority and the same file, there is no guarantee which file will be returned.

The paths added by a module have the negative priority of that module. For example an template file in I2CE has priority 0, while a template file found in ihris-manage has priority -200 so that the template file in ihris-manage is found first. There are two exceptions: the paths added by a module in the 'classes' or 'modules' are added with the priority of the module so that a php class found in I2CE takes precedence over one in ihris-manage which has priority 200.

Adding Paths

The most common way to add a directory to a search path is to do so through a modules configuration file. For example:

<path name='classes'> 
  <value>./lib</value>
</path>

The <value> tags can be either absolute paths or relative paths. If they are relative paths, they are relative to the directory which contains this configuration file. Some Caveats:

  • If you add a '*' to the end of a path which ends in '/' (or '\' for windows), this says that all sub-directories of this directory should be added to path. For example, <value>./my_path/*</value> adds in all sub-directories under ./my_path/
  • If you add a '*' to the end of a path which does not end in a '/' (or '\' for windows) this says that we add all directories that match the file glob. For example, <value>./my_paths/go*</value> adds in all sub-directories of my_paths which start with go.
  • If you add a '**' to the end of a path which ends in '/' (or '\' for windows) it will add in all sub-directories, sub-sub-directories, sub-sub-sub-directories etc of the given path.
  • If a directory that you add has a sub-directory named 'local' it will first check realtive to this subdirectory for this file. This is useful for development purposes to prevent things from getting committed to bazaar.
  • See localization

Localization

Beginning with version 3.2, we have added in the ability to localize a path. When a path is added to the file search utility, it first checks to see if there is the sub-directory en_US. If it does not exist, the this directory is not considered to be localized. If it does exist, the path is considered to be localized. In this case, we consider each sub-directory to correspond to a locale.

The preferred locales are set per user. For example, if my preferred locales were fr_RW and then fr_FR and then en_US and I was looking for the file main.html in ./templates which has en_US as a sub-directory I would look for main.html in this order:

  • ./templates/fr_RW/main.html
  • ./templates/fr_FR/main.html
  • ./templates/en_US/main.html

until I found the file I wanted. If it wasn't there, I would then check for main.html in a directory of higher priority.

Caching

Because of the high overhead of looking for files all the time, a successful file search will have its results cached in memory via apc. In version 3.1, these results are stored globally. Starting in version 3.2, because the localization preference is defined per user, these results are cached per user.

By default, a file is considered to be stale after 60 seconds. The cache can be turned off by modifying the magic data at /I2CE/fileSearch/stale_time (see I2CE/I2CE_Configuration.xml).

Caution:If you are developing a new module and add in a template file, the system won't file that file immediately because the file search results are cached. You can either wait the 60 seconds or clear the results stored in the apc memory cache.