Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Jaki wzorzec ? :/
Seth
post 29.12.2003, 17:49:37
Post #1





Grupa: Przyjaciele php.pl
Postów: 2 335
Pomógł: 6
Dołączył: 7.03.2002

Ostrzeżenie: (0%)
-----


Chce nieco przysypieszyc dzialanie skryptu, wiec mysle o przefiltrowaniu jednego ciagu przez preg_matche.
Tekst wygladac moze tak:

test1.test2.test3
lub
test1.test2.test3.*

Oczywiscie mozna dopsiac jeszcze test4.test5 itd.

Natomiast pozostale mozliwosci takie jak:

.test.test
lub
test.test.
lub
test.*.test
lub
test.test..test
lub
test.test.**
lub
*.test.test
itp.

nie wchodza w gre.

Ogolnie mowiac potrzebne mi jest to do funkcji includujacej inne pliki - cos w stylu import z Javy czy using z c#, wiec musze przefiltorawac podany string.

Jakies pomysly na wyrazenie regularne ? smile.gif
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 13)
nobody
post 29.12.2003, 18:26:22
Post #2





Grupa: Zarejestrowani
Postów: 150
Pomógł: 0
Dołączył: 9.07.2003
Skąd: Lublin city

Ostrzeżenie: (0%)
-----


Moze troche prowizorycznie ale dziala:
[php:1:9f82fed7a3]<?php
$str="test1.test2.test34";
if(ereg("^test[0-9]+(.test[0-9]+){1,}$", $str)){
print "OK";
}else{
print "Blad";
}
?>[/php:1:9f82fed7a3]


--------------------
(none)
Go to the top of the page
+Quote Post
Seth
post 29.12.2003, 18:41:37
Post #3





Grupa: Przyjaciele php.pl
Postów: 2 335
Pomógł: 6
Dołączył: 7.03.2002

Ostrzeżenie: (0%)
-----


Co prawda ten napsi test1.test2 itd jest przykladowy, wiec i moze to byc jaki kolwiek inny napis winksmiley.jpg ale zaraz dostosuje to co podales i sprawdze czy dziala. Dzieki smile.gif
Go to the top of the page
+Quote Post
Seth
post 29.12.2003, 21:46:41
Post #4





Grupa: Przyjaciele php.pl
Postów: 2 335
Pomógł: 6
Dołączył: 7.03.2002

Ostrzeżenie: (0%)
-----


Gdyby ktos mial z tym problem to podaje wyrzenie nobody po przerobkach:
Cytat
^[a-zA-Z0-9_]+(.[a-zA-Z0-9_]+){0,}(.*)?$
Go to the top of the page
+Quote Post
nobody
post 29.12.2003, 21:54:35
Post #5





Grupa: Zarejestrowani
Postów: 150
Pomógł: 0
Dołączył: 9.07.2003
Skąd: Lublin city

Ostrzeżenie: (0%)
-----


heh a ja to zrobilem dla slowa test i za * uznalem ze tych testow moze byc wiele... rolleyes.gif


--------------------
(none)
Go to the top of the page
+Quote Post
cagrET
post 30.12.2003, 00:40:31
Post #6





Grupa: Zarejestrowani
Postów: 90
Pomógł: 0
Dołączył: 3.04.2003
Skąd: Opole

Ostrzeżenie: (0%)
-----


Nie wiem dokladnie jak w Javie wyrazenie import dziala, ale u mnie wykombinowalem cos takiego (moze komus sie przyda):

[php:1:8aa77e4482]
<?php
/**
* Import system class to global namespace
* @param string $s
* @return void
* @access public
* @package import
*/
function import($s) {
static $root;
if (!isset($root)) {
$root = realpath(dirname(__FILE__) . '/../') . '/';
}

static $imported = array();
if (isset($imported[$s])) {
return;
}

$arr = explode('.', $s);
if (is_dir($root . implode('/', $arr))) {
$arr[] = $arr[count($arr) - 1];
}
$file = $root . implode('/', $arr) . '.php';
if (!file_exists($file) || !is_file($file)) {
return trigger_error("import() failed, could not import `$s`", E_USER_ERROR);
}
require_once $file;
$imported[$s] = true;
}

?>
[/php:1:8aa77e4482]

Jest kilka katalogow z bibliotekami, ponizej listing, jak sa rozlozone libsy systemowe (czyli takie ktore nie sa w zaden sposob powiazane z dana aplikacja - ogolne, przydatne w wielu aplikacjach)
Kod
system/



system/.htaccess

system/Dataspace.php

system/Example.php

system/import.php

system/license.txt

system/printR.php

system/Random.php

system/Stack.php



system/Config/

system/Config/Ini.php



system/Date/

system/Date/Common.php

system/Date/const.php

system/Date/Date.php

system/Date/Gmt.php

system/Date/Local.php

system/Date/Utility.php



system/Db/

system/Db/Db.php

system/Db/Debug.php

system/Db/debug.tpl

system/Db/Pager.php



system/Db/Mysql/

system/Db/Mysql/Mysql.php

system/Db/Mysql/Result.php



system/Db/Oci8/

system/Db/Oci8/oci8.php

system/Db/Oci8/Result.php

system/Db/Oci8/utlxplan.sql



system/Db/Pgsql/

system/Db/Pgsql/Pgsql.php

system/Db/Pgsql/Result.php



system/Db/Sql/

system/Db/Sql/Result.php

system/Db/Sql/Sql.php



system/Error/

system/Error/Handler/

system/Error/Handler/error.tpl

system/Error/Handler/Handler.php

system/Error/Handler/showSource.php



system/Html/

system/Html/Tag.php



system/Http/

system/Http/Cookie.php

system/Http/Request.php

system/Http/Response.php

system/Http/Utility.php

system/Http/Var.php



system/Http/Session/Session.php

system/Http/Session/Handler/Db.php



system/Http/Upload/Upload.php

system/Http/Upload/File.php



system/Image/

system/Image/Image.php

system/Image/Utility.php



system/Io/

system/Io/Directory.php

system/Io/File.php

system/Io/Path.php



system/Mail/

system/Mail/Mail.php

system/Mail/Utility.php



system/String/

system/String/String.php

system/String/Utility.php



system/Template/

system/Template/Plugin.php

system/Template/Template.php



system/Template/plugins/

system/Template/plugins/cycle.php

system/Template/plugins/escape.php

system/Template/plugins/htmlcheckboxes.php

system/Template/plugins/htmloptions.php

system/Template/plugins/htmlselectdate.php

system/Template/plugins/truncate.php



system/Unique/

system/Unique/mysql.sql

system/Unique/oci8.sql

system/Unique/Unique.php


Przyklady:
[php:1:8aa77e4482]
import('system.Http.Var');
import('system.Db');
import('system.Http.Cookie');
[/php:1:8aa77e4482]
Funkcja import dziala w ten sposob, ze jak bede chcial rozbudowac dana klase to nie bede musial zmieniac kodu aplikacji
Czyli w aplikacji wpisujac
[php:1:8aa77e4482]
import('system.Dataspace');
[/php:1:8aa77e4482]
Klasa zostanie includnieta, niezaleznie czy struktura bedzie taka:
Kod
system/Dataspace.php

czy taka:
Kod
system/Dataspace/

system/Dataspace/Dataspace.php

system/Dataspace/Costam.php


Biblioteki ogolne powiazane w jakikolwiek sposob z dana aplikacja trzymam w katalogu "application/".
Tam struktura klas jest podobna. np.
[php:1:8aa77e4482]
import('application.Registry');
import('application.Test.Connection');
[/php:1:8aa77e4482]

Myslalem tez nad zaimplementowaniem gwiazdki * w funkcji import czyli cos w stylu:
[php:1:8aa77e4482]
import('system.Http.*');
[/php:1:8aa77e4482]
Ale na razie jest to niepotrzebne, pozatym powstalby niepotrzebny narzut, gdyz na razie nie spotkalem sie z sytuacja zebym potrzebowal wszystkich klas z danego katalogu.


--------------------
code.gosu.pl
Go to the top of the page
+Quote Post
Seth
post 30.12.2003, 00:50:40
Post #7





Grupa: Przyjaciele php.pl
Postów: 2 335
Pomógł: 6
Dołączył: 7.03.2002

Ostrzeżenie: (0%)
-----


A ja tak smile.gif:
[php:1:47a304b380]define( 'INCLUDE_PATH', 'include/' );

/**
* Use this function to include classes in given namespace pattern
*
* @param $nsPattern string
* @return true if succed, false otherwise
*/
function Import( $nsPattern )
{
// Filter pattern namespace
if ( preg_match( '/^[a-z0-9_]+(.[a-z0-9_]+){0,}(.*)?$/i', $nsPattern ) )
{
$nsPattern = str_replace( '.', '/', $nsPattern );

if ( preg_match( '/^(.*)/*$/', $nsPattern, $match ) )
{
$patch = INCLUDE_PATH.$match[1];

if ( $handle = opendir( $patch ) )
{
while ( false !== ( $file = readdir( $handle ) ) )
{
$i = 0;

if ( $file != '.' && $file != '..' && preg_match( '/^(.*).class.php$/', $file, $match ) )
{
$filePath = $patch."/".$file;

if ( file_exists( $filePath ) && is_file( $filePath ) && !class_exists( $match[1] ) )
{
require_once( $filePath );

$i++;
}
}
}

closedir($handle);
}

return ( $i ? 1 : 0 );
}
else
{
$className = substr( strrchr( $nsPattern, '/'), 1 );
$filePath = INCLUDE_PATH.$nsPattern.".class.php";

if ( file_exists( $filePath ) && is_file( $filePath ) && !class_exists( $className ) )
{
require_once( $filePath );

return 1;
}

return 0;
}
}

// Wrong pattern
return 0;
}[/php:1:47a304b380]

Wywolania:
Import( 'db.*' );
includuje wszystkie klasy z katalogu include_path.'db/'
(zastanawiam sie czy nie includowac rekursywnie takze z podkatalogow :?)

Importt( 'db.jakas_klasa' );
includuje klasy o nazwie jakas_klasa z katalogu db
Go to the top of the page
+Quote Post
cagrET
post 30.12.2003, 01:16:35
Post #8





Grupa: Zarejestrowani
Postów: 90
Pomógł: 0
Dołączył: 3.04.2003
Skąd: Opole

Ostrzeżenie: (0%)
-----


INCLUDE_PATCH ? biggrin.gif


--------------------
code.gosu.pl
Go to the top of the page
+Quote Post
Seth
post 30.12.2003, 01:37:04
Post #9





Grupa: Przyjaciele php.pl
Postów: 2 335
Pomógł: 6
Dołączył: 7.03.2002

Ostrzeżenie: (0%)
-----


Cytat
INCLUDE_PATCH ? biggrin.gif

Tak, a co ? :9
Go to the top of the page
+Quote Post
Cudi
post 30.12.2003, 01:42:11
Post #10


Administrator planeta/IRC


Grupa: Przyjaciele php.pl
Postów: 385
Pomógł: 0
Dołączył: 19.04.2003
Skąd: Zabrze

Ostrzeżenie: (0%)
-----


łatka, ściezka... who cares ? smile.gif


--------------------
"Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning."
Cudi's devBlog
Go to the top of the page
+Quote Post
Seth
post 30.12.2003, 01:46:36
Post #11





Grupa: Przyjaciele php.pl
Postów: 2 335
Pomógł: 6
Dołączył: 7.03.2002

Ostrzeżenie: (0%)
-----


Cizes biggrin.gif za szybko to pisalem i nie zorientowalem sie winksmiley.jpg
Go to the top of the page
+Quote Post
menic
post 30.12.2003, 02:03:15
Post #12





Grupa: Zarejestrowani
Postów: 493
Pomógł: 0
Dołączył: 14.06.2003
Skąd: Tomaszów Lubelski/Rzeszów

Ostrzeżenie: (0%)
-----


Cytat
łatka, ściezka... who cares ? smile.gif
nie rozumiem :?


--------------------
Jak masz cos zrobic dobrze...
...To musisz zrobić to sam.

Uchwycić moment...
Go to the top of the page
+Quote Post
Cudi
post 30.12.2003, 02:06:31
Post #13


Administrator planeta/IRC


Grupa: Przyjaciele php.pl
Postów: 385
Pomógł: 0
Dołączył: 19.04.2003
Skąd: Zabrze

Ostrzeżenie: (0%)
-----


łatka, ściezka, who cares ? smile.gif
Teraz lepiej ? smile.gif (straszny OT o tej porze nocy panuje)


--------------------
"Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning."
Cudi's devBlog
Go to the top of the page
+Quote Post
uboottd
post 30.12.2003, 20:52:31
Post #14





Grupa: Zarejestrowani
Postów: 384
Pomógł: 0
Dołączył: 3.04.2003
Skąd: Chorzow

Ostrzeżenie: (0%)
-----


Nie moglem sie powstrzymac:
Cytat za takimi dwoma ktorych pewny user ma w avatarze:
-The question is: What is "Ma-na-ma-na"?
-The question is: Who cares!
smile.gif
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 09:47